From 4adaedb3049340ac6a71d000db0340d873621eb7 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sun, 16 May 2021 18:31:03 +1000 Subject: [PATCH] ffmpegdecoder: fixed issue with interlaced footage in some situations --- app/codec/ffmpeg/ffmpegdecoder.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/codec/ffmpeg/ffmpegdecoder.cpp b/app/codec/ffmpeg/ffmpegdecoder.cpp index cb1152992..5c49a6ae1 100644 --- a/app/codec/ffmpeg/ffmpegdecoder.cpp +++ b/app/codec/ffmpeg/ffmpegdecoder.cpp @@ -649,15 +649,16 @@ FFmpegFramePool::ElementPtr FFmpegDecoder::RetrieveFrame(const rational& time, c { int64_t target_ts = GetTimeInTimebaseUnits(time, instance_.avstream()->time_base, instance_.avstream()->start_time); - if (params.dst_interlacing == VideoParams::kInterlaceNone && params.src_interlacing != VideoParams::kInterlaceNone) { + const int64_t min_seek = -instance_.avstream()->start_time; + int64_t seek_ts = target_ts; + bool still_seeking = false; + + if (params.src_interlacing != VideoParams::kInterlaceNone) { // If we are de-interlacing, the timebase is doubled because we get one frame per field, so we // double the target timestamp too target_ts *= 2; } - int64_t seek_ts = target_ts; - bool still_seeking = false; - if (time != kAnyTimecode) { // If the frame wasn't in the frame cache, see if this frame cache is too old to use if (cached_frames_.isEmpty() @@ -665,7 +666,7 @@ FFmpegFramePool::ElementPtr FFmpegDecoder::RetrieveFrame(const rational& time, c ClearFrameCache(); instance_.Seek(seek_ts); - if (seek_ts == 0) { + if (seek_ts == min_seek) { cache_at_zero_ = true; } @@ -703,9 +704,9 @@ FFmpegFramePool::ElementPtr FFmpegDecoder::RetrieveFrame(const rational& time, c // We'll only be here if the frame cache was emptied earlier if (!cache_at_zero_ && (ret == AVERROR_EOF || working_frame->pts > target_ts)) { - seek_ts = qMax(static_cast(0), seek_ts - second_ts_); + seek_ts = qMax(min_seek, seek_ts - second_ts_); instance_.Seek(seek_ts); - if (seek_ts == 0) { + if (seek_ts == min_seek) { cache_at_zero_ = true; } continue;