@@ -653,7 +653,10 @@ VideoDecoder::getFramesInRange(int64_t start, int64_t stop, int64_t step) {
653653 getFrameAtIndexInternal (i, frameBatchOutput.data [f]);
654654 frameBatchOutput.ptsSeconds [f] = frameOutput.ptsSeconds ;
655655 frameBatchOutput.durationSeconds [f] = frameOutput.durationSeconds ;
656+ // We know the frames are consecutive, there's no need to seek
657+ mustSkipSeeking_ = (step == 1 );
656658 }
659+ mustSkipSeeking_ = false ; // reset to original value
657660 frameBatchOutput.data = maybePermuteHWC2CHW (frameBatchOutput.data );
658661 return frameBatchOutput;
659662}
@@ -807,7 +810,10 @@ VideoDecoder::FrameBatchOutput VideoDecoder::getFramesPlayedInRange(
807810 getFrameAtIndexInternal (i, frameBatchOutput.data [f]);
808811 frameBatchOutput.ptsSeconds [f] = frameOutput.ptsSeconds ;
809812 frameBatchOutput.durationSeconds [f] = frameOutput.durationSeconds ;
813+ // We know the frames are consecutive, there's no need to seek
814+ mustSkipSeeking_ = true ;
810815 }
816+ mustSkipSeeking_ = false ; // reset to original value
811817 frameBatchOutput.data = maybePermuteHWC2CHW (frameBatchOutput.data );
812818
813819 return frameBatchOutput;
@@ -847,6 +853,9 @@ I P P P I P P P I P P I P P I P
847853(2) is more efficient than (1) if there is an I frame between x and y.
848854*/
849855bool VideoDecoder::canWeAvoidSeeking (int64_t targetPts) const {
856+ if (mustSkipSeeking_) {
857+ return true ;
858+ }
850859 int64_t lastDecodedAvFramePts =
851860 streamInfos_.at (activeStreamIndex_).lastDecodedAvFramePts ;
852861 if (targetPts < lastDecodedAvFramePts) {
0 commit comments