Skip to content

Commit 969efbc

Browse files
author
Clement Champetier
committed
VideoEncoder: throw exception if buffer size < 0
1 parent 60f0c02 commit 969efbc

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/AvTranscoder/encoder/VideoEncoder.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ bool VideoEncoder::encodeFrame( const Frame& sourceFrame, Frame& codedFrame )
4646
frame->width = avCodecContext.width;
4747
frame->height = avCodecContext.height;
4848
frame->format = avCodecContext.pix_fmt;
49-
avpicture_fill( (AVPicture*)frame, const_cast< unsigned char * >( sourceImageFrame.getData() ), avCodecContext.pix_fmt, avCodecContext.width, avCodecContext.height );
49+
50+
int bufferSize = avpicture_fill( (AVPicture*)frame, const_cast< unsigned char * >( sourceImageFrame.getData() ), avCodecContext.pix_fmt, avCodecContext.width, avCodecContext.height );
51+
if( bufferSize < 0 )
52+
{
53+
char err[AV_ERROR_MAX_STRING_SIZE];
54+
av_strerror( bufferSize, err, sizeof(err) );
55+
throw std::runtime_error( "Encode video frame error: buffer size < 0 - " + std::string(err) );
56+
}
5057

5158
AVPacket& packet = codedFrame.getAVPacket();
5259
packet.stream_index = 0;

0 commit comments

Comments
 (0)