File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -626,9 +626,17 @@ FrameOutput SingleStreamDecoder::getFrameAtIndexInternal(
626626 }
627627 validateFrameIndex (streamMetadata, frameIndex);
628628
629- int64_t pts = getPts (frameIndex);
630- setCursorPtsInSeconds (ptsToSeconds (pts, streamInfo.timeBase ));
631- return getNextFrameInternal (preAllocatedOutputTensor);
629+ // Only set cursor if we're not decoding sequentially: when decoding
630+ // sequentially, we don't need to seek anywhere, so by *not* setting the
631+ // cursor we allow canWeAvoidSeeking() to return true early.
632+ if (frameIndex != lastDecodedFrameIndex_ + 1 ) {
633+ int64_t pts = getPts (frameIndex);
634+ setCursorPtsInSeconds (ptsToSeconds (pts, streamInfo.timeBase ));
635+ }
636+
637+ auto result = getNextFrameInternal (preAllocatedOutputTensor);
638+ lastDecodedFrameIndex_ = frameIndex;
639+ return result;
632640}
633641
634642FrameBatchOutput SingleStreamDecoder::getFramesAtIndices (
Original file line number Diff line number Diff line change @@ -346,6 +346,7 @@ class SingleStreamDecoder {
346346 bool cursorWasJustSet_ = false ;
347347 int64_t lastDecodedAvFramePts_ = 0 ;
348348 int64_t lastDecodedAvFrameDuration_ = 0 ;
349+ int64_t lastDecodedFrameIndex_ = INT64_MIN;
349350
350351 // Stores various internal decoding stats.
351352 DecodeStats decodeStats_;
You can’t perform that action at this time.
0 commit comments