Skip to content

Commit

Permalink
Fix CurrentFrame guessing when second fields have Pos=-1
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arch1t3cht committed Apr 8, 2024
1 parent 3d50c09 commit 96f4267
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/core/videosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 96f4267

Please sign in to comment.