From 96f4267b6cc203fd78604101569bc6818974975b Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Sat, 6 Apr 2024 22:26:38 +0200 Subject: [PATCH] Fix CurrentFrame guessing when second fields have Pos=-1 For (non-MBAFF) interlaced h264 in mpegts containers, the second fields all have FilePos equal to -1 or to the previous packet's FilePos. Previously, the fields with FilePos=-1 would abort the loop to find CurrentFrame prematurely. --- src/core/videosource.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core/videosource.cpp b/src/core/videosource.cpp index 7497afeaed..f148a944e8 100644 --- a/src/core/videosource.cpp +++ b/src/core/videosource.cpp @@ -931,10 +931,16 @@ FFMS_Frame *FFMS_VideoSource::GetFrame(int n) { // aggressive (non-keyframe) seeking. int64_t Pos = Frames[CurrentFrame].FilePos; if (CurrentFrame > 0 && Pos != -1) { - int Prev = CurrentFrame - 1; - while (Prev >= 0 && Frames[Prev].FilePos != -1 && Frames[Prev].FilePos > Pos) - --Prev; - CurrentFrame = Prev + 1; + while (true) { + int Prev = CurrentFrame - 1; + if (Prev >= 0 && Frames[Prev].SecondField) + --Prev; + + if (Prev >= 0 && (Frames[Prev].FilePos != -1 && Frames[Prev].FilePos > Pos)) + CurrentFrame = Prev; + else + break; + } } if (Frames[CurrentFrame].Skipped()) {