Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/torchcodec/decoders/_core/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,10 +859,10 @@ bool VideoDecoder::canWeAvoidSeeking(int64_t targetPts) const {
// We are seeking forwards.
// We can only skip a seek if both lastDecodedAvFramePts and targetPts share
// the same keyframe.
int currentKeyFrameIndex = getKeyFrameIndexForPts(lastDecodedAvFramePts);
int lastDecodedAvFrameIndex = getKeyFrameIndexForPts(lastDecodedAvFramePts);
int targetKeyFrameIndex = getKeyFrameIndexForPts(targetPts);
return currentKeyFrameIndex >= 0 && targetKeyFrameIndex >= 0 &&
currentKeyFrameIndex == targetKeyFrameIndex;
return lastDecodedAvFrameIndex >= 0 && targetKeyFrameIndex >= 0 &&
lastDecodedAvFrameIndex == targetKeyFrameIndex;
Comment on lines +862 to +865
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by

}

// This method looks at currentPts and desiredPts and seeks in the
Expand All @@ -871,18 +871,16 @@ bool VideoDecoder::canWeAvoidSeeking(int64_t targetPts) const {
void VideoDecoder::maybeSeekToBeforeDesiredPts() {
validateActiveStream();
StreamInfo& streamInfo = streamInfos_[activeStreamIndex_];
streamInfo.discardFramesBeforePts =

int64_t desiredPts =
secondsToClosestPts(*desiredPtsSeconds_, streamInfo.timeBase);
streamInfo.discardFramesBeforePts = desiredPts;

decodeStats_.numSeeksAttempted++;

int64_t desiredPtsForStream = *desiredPtsSeconds_ * streamInfo.timeBase.den;
if (canWeAvoidSeeking(desiredPtsForStream)) {
if (canWeAvoidSeeking(desiredPts)) {
decodeStats_.numSeeksSkipped++;
return;
}
int64_t desiredPts =
secondsToClosestPts(*desiredPtsSeconds_, streamInfo.timeBase);

// For some encodings like H265, FFMPEG sometimes seeks past the point we
// set as the max_ts. So we use our own index to give it the exact pts of
Expand Down
Loading