@@ -10,7 +10,7 @@ namespace avtranscoder
10
10
FormatContext::FormatContext ( const std::string& filename, int req_flags )
11
11
: _avFormatContext( NULL )
12
12
, _options()
13
- , _isOpen( true )
13
+ , _isOpen( false )
14
14
{
15
15
int ret = avformat_open_input ( &_avFormatContext, filename.c_str (), NULL , NULL );
16
16
if ( ret < 0 )
@@ -23,6 +23,7 @@ FormatContext::FormatContext( const std::string& filename, int req_flags )
23
23
msg += err;
24
24
throw std::ios_base::failure ( msg );
25
25
}
26
+ _isOpen = true ;
26
27
loadOptions ( _options, _avFormatContext, req_flags );
27
28
}
28
29
@@ -39,7 +40,7 @@ FormatContext::~FormatContext()
39
40
{
40
41
if ( ! _avFormatContext )
41
42
return ;
42
-
43
+
43
44
if ( _isOpen )
44
45
avformat_close_input ( &_avFormatContext );
45
46
else
@@ -52,7 +53,6 @@ void FormatContext::findStreamInfo( AVDictionary** options )
52
53
int err = avformat_find_stream_info ( _avFormatContext, options );
53
54
if ( err < 0 )
54
55
{
55
- avformat_close_input ( &_avFormatContext );
56
56
throw std::ios_base::failure ( " unable to find stream informations" );
57
57
}
58
58
}
@@ -65,7 +65,6 @@ void FormatContext::openRessource( const std::string& url, int flags )
65
65
int err = avio_open2 ( &_avFormatContext->pb , url.c_str (), flags, NULL , NULL );
66
66
if ( err < 0 )
67
67
{
68
- avformat_close_input ( &_avFormatContext );
69
68
throw std::ios_base::failure ( " error when opening output format" );
70
69
}
71
70
}
@@ -78,7 +77,6 @@ void FormatContext::closeRessource()
78
77
int err = avio_close ( _avFormatContext->pb );
79
78
if ( err < 0 )
80
79
{
81
- avformat_close_input ( &_avFormatContext );
82
80
throw std::ios_base::failure ( " error when close output format" );
83
81
}
84
82
}
0 commit comments