From 136426283b6271a8396f900682027c2980b981a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Zumer?= Date: Wed, 27 Aug 2025 14:15:25 -0400 Subject: [PATCH] videosource: Prevent SeekTo() from targeting negative frame numbers This prevents an exception from being thrown if -SeekOffset > n, which can occur if the first frame is skipped by FrameFromPTS. --- src/core/videosource.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/core/videosource.cpp b/src/core/videosource.cpp index c27b5d6f98..b267f200ad 100644 --- a/src/core/videosource.cpp +++ b/src/core/videosource.cpp @@ -908,11 +908,6 @@ bool FFMS_VideoSource::SeekTo(int n, int SeekOffset) { // The semantics here are basically "return true if we don't know exactly where our seek ended up (destination isn't frame 0)" if (SeekMode >= 0) { - int TargetFrame = n + SeekOffset; - if (TargetFrame < 0) - throw FFMS_Exception(FFMS_ERROR_SEEKING, FFMS_ERROR_UNKNOWN, - "Frame accurate seeking is not possible in this file"); - // 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. @@ -923,7 +918,7 @@ bool FFMS_VideoSource::SeekTo(int n, int SeekOffset) { // 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))); + int TargetFrame = std::min(std::max(0, n + SeekOffset), Frames.RealFrameNumber(std::max(0, VP.NumFrames - 1 - EndOfStreamDist))); if (SeekMode < 3) TargetFrame = Frames.FindClosestVideoKeyFrame(TargetFrame); @@ -997,7 +992,6 @@ FFMS_Frame *FFMS_VideoSource::GetFrame(int n) { // Is the seek destination time known? Does it belong to a frame? if (CurrentFrame < 0) { if (SeekMode == 1 || StartTime < 0) { - // No idea where we are so go back a bit further SeekOffset -= 10; Seek = true; continue;