Fix T47806: Blender animation player stop working correctly with XVID codec
authorSergey Sharybin <sergey.vfx@gmail.com>
Fri, 18 Mar 2016 06:50:06 +0000 (11:50 +0500)
committerSergey Sharybin <sergey.vfx@gmail.com>
Fri, 18 Mar 2016 06:50:06 +0000 (11:50 +0500)
Something weird, seems some buffers _might_ be shared between codec context
and frame, which is quite weird. Could be a bug in FFmpeg or could be wrong
API usage somewhere else..

source/blender/imbuf/intern/anim_movie.c

index 763ec121688452eb70c391be0915a1cd1eb14e97..d378ca9a78c826260ff5b0ede484dbf04c9baa1a 100644 (file)
@@ -1168,6 +1168,15 @@ static void free_anim_ffmpeg(struct anim *anim)
        if (anim->pCodecCtx) {
                avcodec_close(anim->pCodecCtx);
                avformat_close_input(&anim->pFormatCtx);
+
+               /* Special case here: pFrame could share pointers with codec,
+                * so in order to avoid double-free we don't use av_frame_free()
+                * to free the frame.
+                *
+                * Could it be a bug in FFmpeg?
+                */
+               av_free(anim->pFrame);
+
                if (!need_aligned_ffmpeg_buffer(anim)) {
                        /* If there's no need for own aligned buffer it means that FFmpeg's
                         * frame shares the same buffer as temporary ImBuf. In this case we
@@ -1179,8 +1188,8 @@ static void free_anim_ffmpeg(struct anim *anim)
                                       anim->x, anim->y);
                }
                av_frame_free(&anim->pFrameRGB);
-               av_frame_free(&anim->pFrame);
                av_frame_free(&anim->pFrameDeinterlaced);
+
                sws_freeContext(anim->img_convert_ctx);
                IMB_freeImBuf(anim->last_frame);
                if (anim->next_packet.stream_index != -1) {