Skip to content

Commit

Permalink
Work around ffmpeg skipping frames near end for h264
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
  • Loading branch information
arch1t3cht authored and dwbuiten committed Apr 9, 2024
1 parent 82d21ba commit 73b0f36
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/videosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,11 @@ bool FFMS_VideoSource::SeekTo(int n, int SeekOffset) {
// Is the +1 necessary here? Not sure, but let's keep it to be safe.
int EndOfStreamDist = CodecContext->has_b_frames + 1;

if (CodecContext->codec_id == AV_CODEC_ID_H264)
// Work around a bug in ffmpeg's h264 decoder where frames are skipped when seeking too
// close to the end in open-gop files: https://trac.ffmpeg.org/ticket/10936
EndOfStreamDist *= 2;

TargetFrame = std::min(TargetFrame, Frames.RealFrameNumber(std::max(0, VP.NumFrames - 1 - EndOfStreamDist)));

if (SeekMode < 3)
Expand Down

0 comments on commit 73b0f36

Please sign in to comment.