From 0c0dbb36e770ca34a87702c3c6e0fc39e39d1a67 Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Fri, 29 Aug 2025 12:34:14 +0200 Subject: [PATCH 1/2] Remove workaround for h264 decoder bug FFMS2 requires ffmpeg 7.1 now, which fixes this bug. --- src/core/videosource.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/core/videosource.cpp b/src/core/videosource.cpp index 75a91f820a..3d4edd603d 100644 --- a/src/core/videosource.cpp +++ b/src/core/videosource.cpp @@ -921,11 +921,6 @@ 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) From a33cd4a14cdfc1e161d3c34f1120f289d75f5031 Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Tue, 23 Dec 2025 18:13:52 +0100 Subject: [PATCH 2/2] Fix EndOfStreamDist when seeking We want to make sure to reach the full decoder delay if possible, so we need to apply both reorder delay and thread delay. This logic can add more distance than necessary when hidden frames or PAFF are involved, but tightening the distance would require a lot more logic. --- src/core/videosource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/videosource.cpp b/src/core/videosource.cpp index 3d4edd603d..af57140652 100644 --- a/src/core/videosource.cpp +++ b/src/core/videosource.cpp @@ -919,7 +919,7 @@ bool FFMS_VideoSource::SeekTo(int n, int SeekOffset) { // Seeking too close to the end of the stream can result in a different decoder delay since // frames are returned as soon as draining starts, so avoid this to keep the delay predictable. // Is the +1 necessary here? Not sure, but let's keep it to be safe. - int EndOfStreamDist = CodecContext->has_b_frames + 1; + int EndOfStreamDist = Delay.ReorderDelay + Delay.ThreadDelay + 1; TargetFrame = std::min(TargetFrame, Frames.RealFrameNumber(std::max(0, VP.NumFrames - 1 - EndOfStreamDist)));