From 8ea0af59c60e77ce0ff260a134876ce511fa4c0c Mon Sep 17 00:00:00 2001 From: Chris Kirmse Date: Fri, 10 May 2019 11:39:26 -0700 Subject: [PATCH] fix allocations to be done the same for ffmpeg < 3.2 - fixes freeing an invalid pointer on old ffmpeg - now all tests pass --- src/FFmpegReader.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index 0b67da4e..38d59f83 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -1120,11 +1120,13 @@ bool FFmpegReader::GetAVFrame() { #else avcodec_decode_video2(pCodecCtx, next_frame, &frameFinished, packet); + // always allocate pFrame (because we do that in the ffmpeg >= 3.2 as well); it will always be freed later + pFrame = AV_ALLOCATE_FRAME(); + // is frame finished if (frameFinished) { // AVFrames are clobbered on the each call to avcodec_decode_video, so we // must make a copy of the image data before this method is called again. - pFrame = AV_ALLOCATE_FRAME(); avpicture_alloc((AVPicture *) pFrame, pCodecCtx->pix_fmt, info.width, info.height); av_picture_copy((AVPicture *) pFrame, (AVPicture *) next_frame, pCodecCtx->pix_fmt, info.width, info.height);