Skip to content

Commit

Permalink
Avoid seeking too close to the end of the stream
Browse files Browse the repository at this point in the history
This can throw off delay predictions.

Hidden frames don't make it into the delayed picture buffer,
so the distance needs to be computed in terms of real frames.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
  • Loading branch information
arch1t3cht authored and dwbuiten committed Apr 9, 2024
1 parent 7363ff3 commit 82d21ba
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/videosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,13 @@ bool FFMS_VideoSource::SeekTo(int n, int SeekOffset) {
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.
int EndOfStreamDist = CodecContext->has_b_frames + 1;

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

if (SeekMode < 3)
TargetFrame = Frames.FindClosestVideoKeyFrame(TargetFrame);

Expand Down

0 comments on commit 82d21ba

Please sign in to comment.