Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 4 additions & 10 deletions src/torchcodec/decoders/_core/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,6 @@ torch::Tensor VideoDecoder::getKeyFrameIndices(int streamIndex) {
return keyFrameIndices;
}

int VideoDecoder::getKeyFrameIndexForPtsUsingEncoderIndex(
AVStream* stream,
int64_t pts) const {
int currentKeyFrameIndex =
av_index_search_timestamp(stream, pts, AVSEEK_FLAG_BACKWARD);
return currentKeyFrameIndex;
}

int VideoDecoder::getKeyFrameIndexForPtsUsingScannedIndex(
const std::vector<VideoDecoder::FrameInfo>& keyFrames,
int64_t pts) const {
Expand Down Expand Up @@ -694,9 +686,11 @@ int VideoDecoder::getKeyFrameIndexForPts(
const StreamInfo& streamInfo,
int64_t pts) const {
if (streamInfo.keyFrames.empty()) {
return getKeyFrameIndexForPtsUsingEncoderIndex(streamInfo.stream, pts);
return av_index_search_timestamp(
streamInfo.stream, pts, AVSEEK_FLAG_BACKWARD);
} else {
return getKeyFrameIndexForPtsUsingScannedIndex(streamInfo.keyFrames, pts);
}
return getKeyFrameIndexForPtsUsingScannedIndex(streamInfo.keyFrames, pts);
}

/*
Expand Down
3 changes: 0 additions & 3 deletions src/torchcodec/decoders/_core/VideoDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,6 @@ class VideoDecoder {
int getKeyFrameIndexForPtsUsingScannedIndex(
const std::vector<VideoDecoder::FrameInfo>& keyFrames,
int64_t pts) const;
// Return key frame index, from FFmpeg. Potentially less accurate
int getKeyFrameIndexForPtsUsingEncoderIndex(AVStream* stream, int64_t pts)
const;

int64_t secondsToIndexLowerBound(
double seconds,
Expand Down
Loading