Skip to content

Commit 401d378

Browse files
author
Clement Champetier
committed
FormatContext: add info when ffmpeg/libav error occurs
1 parent b94aa23 commit 401d378

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/AvTranscoder/file/FormatContext.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void FormatContext::findStreamInfo( AVDictionary** options )
5151
int err = avformat_find_stream_info( _avFormatContext, options );
5252
if( err < 0 )
5353
{
54-
throw std::ios_base::failure( "unable to find stream informations" );
54+
throw std::ios_base::failure( "unable to find stream informations: " + getDescriptionFromErrorCode( err ) );
5555
}
5656
}
5757

@@ -63,7 +63,7 @@ void FormatContext::openRessource( const std::string& url, int flags )
6363
int err = avio_open2( &_avFormatContext->pb, url.c_str(), flags, NULL, NULL );
6464
if( err < 0 )
6565
{
66-
throw std::ios_base::failure( "error when opening output format" );
66+
throw std::ios_base::failure( "error when opening output format: " + getDescriptionFromErrorCode( err ) );
6767
}
6868
}
6969

@@ -75,7 +75,7 @@ void FormatContext::closeRessource()
7575
int err = avio_close( _avFormatContext->pb );
7676
if( err < 0 )
7777
{
78-
throw std::ios_base::failure( "error when close output format" );
78+
throw std::ios_base::failure( "error when close output format: " + getDescriptionFromErrorCode( err ) );
7979
}
8080
}
8181

@@ -84,9 +84,7 @@ void FormatContext::writeHeader( AVDictionary** options )
8484
int ret = avformat_write_header( _avFormatContext, options );
8585
if( ret != 0 )
8686
{
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 ) );
9088
}
9189
}
9290

@@ -96,21 +94,23 @@ void FormatContext::writeFrame( AVPacket& packet, bool interleaved )
9694
if( interleaved )
9795
ret = av_interleaved_write_frame( _avFormatContext, &packet );
9896
else
97+
{
98+
// returns 1 if flushed and there is no more data to flush
9999
ret = av_write_frame( _avFormatContext, &packet );
100+
}
100101

101-
if( ret != 0 )
102+
if( ret < 0 )
102103
{
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 ) );
106105
}
107106
}
108107

109108
void FormatContext::writeTrailer()
110109
{
111-
if( av_write_trailer( _avFormatContext ) != 0)
110+
int ret = av_write_trailer( _avFormatContext );
111+
if( ret != 0 )
112112
{
113-
throw std::runtime_error( "could not write trailer" );
113+
throw std::runtime_error( "could not write trailer: " + getDescriptionFromErrorCode( ret ) );
114114
}
115115
}
116116

0 commit comments

Comments
 (0)