From 0e01a74fb51c52f7a5f29dbb20ef9e783fa81cbc Mon Sep 17 00:00:00 2001 From: Fredrik Mellbin Date: Sun, 30 Mar 2008 15:39:02 +0000 Subject: [PATCH] fix for h264 with b-frame pyramid stuff Originally committed to SVN as r2161. --- FFmpegSource/ffmatroskasource.cpp | 13 ++++++++++--- FFmpegSource/ffmpegsource.cpp | 16 ++++++++++++---- FFmpegSource/ffmpegsource.html | 2 ++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/FFmpegSource/ffmatroskasource.cpp b/FFmpegSource/ffmatroskasource.cpp index 2b3a497fa..223a2ee18 100644 --- a/FFmpegSource/ffmatroskasource.cpp +++ b/FFmpegSource/ffmatroskasource.cpp @@ -357,19 +357,26 @@ int FFMatroskaSource::DecodeNextFrame(AVFrame *AFrame, int64_t *AFirstStartTime, unsigned int Track, FrameFlags, FrameSize; while (mkv_ReadFrame(MF, 0, &Track, &StartTime, &EndTime, &FilePos, &FrameSize, &FrameFlags) == 0) { - FrameSize = ReadFrame(FilePos, FrameSize, VideoCS, Env); if (*AFirstStartTime < 0) *AFirstStartTime = StartTime; + FrameSize = ReadFrame(FilePos, FrameSize, VideoCS, Env); Ret = avcodec_decode_video(VideoCodecContext, AFrame, &FrameFinished, Buffer, FrameSize); + if (Ret < 0) + goto Error; + if (FrameFinished) goto Done; } - // Flush the last frame - if (CurrentFrame == VI.num_frames - 1 && VideoCodecContext->has_b_frames) + // Flush the last frames + if (VideoCodecContext->has_b_frames) Ret = avcodec_decode_video(VideoCodecContext, AFrame, &FrameFinished, NULL, 0); + if (!FrameFinished || Ret < 0) + goto Error; + +Error: Done: return Ret; } diff --git a/FFmpegSource/ffmpegsource.cpp b/FFmpegSource/ffmpegsource.cpp index fee4359ce..a3ef7915c 100644 --- a/FFmpegSource/ffmpegsource.cpp +++ b/FFmpegSource/ffmpegsource.cpp @@ -237,10 +237,13 @@ int FFmpegSource::DecodeNextFrame(AVFrame *AFrame, int64_t *AStartTime) { while (av_read_frame(FormatContext, &Packet) >= 0) { if (Packet.stream_index == VideoTrack) { - Ret = avcodec_decode_video(VideoCodecContext, AFrame, &FrameFinished, Packet.data, Packet.size); - if (*AStartTime < 0) *AStartTime = Packet.dts; + + Ret = avcodec_decode_video(VideoCodecContext, AFrame, &FrameFinished, Packet.data, Packet.size); + + if (Ret < 0) + goto Error; } av_free_packet(&Packet); @@ -249,10 +252,15 @@ int FFmpegSource::DecodeNextFrame(AVFrame *AFrame, int64_t *AStartTime) { goto Done; } - // Flush the last frame - if (CurrentFrame == VI.num_frames - 1 && VideoCodecContext->has_b_frames) + // Flush the last frames + if (VideoCodecContext->has_b_frames) Ret = avcodec_decode_video(VideoCodecContext, AFrame, &FrameFinished, NULL, 0); + if (!FrameFinished || Ret < 0) + goto Error; + +// Ignore errors for now +Error: Done: return Ret; } diff --git a/FFmpegSource/ffmpegsource.html b/FFmpegSource/ffmpegsource.html index e32379c32..78134c523 100644 --- a/FFmpegSource/ffmpegsource.html +++ b/FFmpegSource/ffmpegsource.html @@ -166,6 +166,8 @@ Note that --enable-w32threads is required for multithreaded decoding to work.

Changes