@@ -51,7 +51,7 @@ void FormatContext::findStreamInfo( AVDictionary** options )
51
51
int err = avformat_find_stream_info ( _avFormatContext, options );
52
52
if ( err < 0 )
53
53
{
54
- throw std::ios_base::failure ( " unable to find stream informations" );
54
+ throw std::ios_base::failure ( " unable to find stream informations: " + getDescriptionFromErrorCode ( err ) );
55
55
}
56
56
}
57
57
@@ -63,7 +63,7 @@ void FormatContext::openRessource( const std::string& url, int flags )
63
63
int err = avio_open2 ( &_avFormatContext->pb , url.c_str (), flags, NULL , NULL );
64
64
if ( err < 0 )
65
65
{
66
- throw std::ios_base::failure ( " error when opening output format" );
66
+ throw std::ios_base::failure ( " error when opening output format: " + getDescriptionFromErrorCode ( err ) );
67
67
}
68
68
}
69
69
@@ -75,7 +75,7 @@ void FormatContext::closeRessource()
75
75
int err = avio_close ( _avFormatContext->pb );
76
76
if ( err < 0 )
77
77
{
78
- throw std::ios_base::failure ( " error when close output format" );
78
+ throw std::ios_base::failure ( " error when close output format: " + getDescriptionFromErrorCode ( err ) );
79
79
}
80
80
}
81
81
@@ -84,9 +84,7 @@ void FormatContext::writeHeader( AVDictionary** options )
84
84
int ret = avformat_write_header ( _avFormatContext, options );
85
85
if ( ret != 0 )
86
86
{
87
- std::string msg = " could not write header: " ;
88
- msg += getDescriptionFromErrorCode ( ret );
89
- throw std::runtime_error ( msg );
87
+ throw std::runtime_error ( " could not write header: " + getDescriptionFromErrorCode ( ret ) );
90
88
}
91
89
}
92
90
@@ -96,21 +94,23 @@ void FormatContext::writeFrame( AVPacket& packet, bool interleaved )
96
94
if ( interleaved )
97
95
ret = av_interleaved_write_frame ( _avFormatContext, &packet );
98
96
else
97
+ {
98
+ // returns 1 if flushed and there is no more data to flush
99
99
ret = av_write_frame ( _avFormatContext, &packet );
100
+ }
100
101
101
- if ( ret != 0 )
102
+ if ( ret < 0 )
102
103
{
103
- std::string msg = " error when writting packet in stream: " ;
104
- msg += getDescriptionFromErrorCode ( ret );
105
- throw std::runtime_error ( msg );
104
+ throw std::runtime_error ( " error when writting packet in stream: " + getDescriptionFromErrorCode ( ret ) );
106
105
}
107
106
}
108
107
109
108
void FormatContext::writeTrailer ()
110
109
{
111
- if ( av_write_trailer ( _avFormatContext ) != 0 )
110
+ int ret = av_write_trailer ( _avFormatContext );
111
+ if ( ret != 0 )
112
112
{
113
- throw std::runtime_error ( " could not write trailer" );
113
+ throw std::runtime_error ( " could not write trailer: " + getDescriptionFromErrorCode ( ret ) );
114
114
}
115
115
}
116
116
0 commit comments