@@ -1359,6 +1359,9 @@ void FFmpegReader::ProcessVideoPacket(int64_t requested_frame) {
13591359 // Check if the AVFrame is finished and set it
13601360 if (!frame_finished) {
13611361 // No AVFrame decoded yet, bail out
1362+ if (pFrame) {
1363+ RemoveAVFrame (pFrame);
1364+ }
13621365 return ;
13631366 }
13641367
@@ -1383,8 +1386,6 @@ void FFmpegReader::ProcessVideoPacket(int64_t requested_frame) {
13831386 int height = info.height ;
13841387 int width = info.width ;
13851388 int64_t video_length = info.video_length ;
1386- AVFrame *my_frame = pFrame;
1387- pFrame = NULL ;
13881389
13891390 // Create variables for a RGB Frame (since most videos are not in RGB, we must convert it)
13901391 AVFrame *pFrameRGB = nullptr ;
@@ -1485,7 +1486,7 @@ void FFmpegReader::ProcessVideoPacket(int64_t requested_frame) {
14851486 height, PIX_FMT_RGBA, scale_mode, NULL , NULL , NULL );
14861487
14871488 // Resize / Convert to RGB
1488- sws_scale (img_convert_ctx, my_frame ->data , my_frame ->linesize , 0 ,
1489+ sws_scale (img_convert_ctx, pFrame ->data , pFrame ->linesize , 0 ,
14891490 original_height, pFrameRGB->data , pFrameRGB->linesize );
14901491
14911492 // Create or get the existing frame object
@@ -1510,7 +1511,7 @@ void FFmpegReader::ProcessVideoPacket(int64_t requested_frame) {
15101511 AV_FREE_FRAME (&pFrameRGB);
15111512
15121513 // Remove frame and packet
1513- RemoveAVFrame (my_frame );
1514+ RemoveAVFrame (pFrame );
15141515 sws_freeContext (img_convert_ctx);
15151516
15161517 // Get video PTS in seconds
@@ -1599,6 +1600,11 @@ void FFmpegReader::ProcessAudioPacket(int64_t requested_frame) {
15991600
16001601 // Calculate total number of samples
16011602 packet_samples = audio_frame->nb_samples * AV_GET_CODEC_ATTRIBUTES (aStream, aCodecCtx)->channels ;
1603+ } else {
1604+ if (audio_frame) {
1605+ // Free audio frame
1606+ AV_FREE_FRAME (&audio_frame);
1607+ }
16021608 }
16031609
16041610 // Estimate the # of samples and the end of this packet's location (to prevent GAPS for the next timestamp)
0 commit comments