From 6515963a082ab1454a38aaa718fbc0a4180141d2 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Tue, 28 Jan 2025 10:21:17 +0000 Subject: [PATCH] Remove getKeyFrameIndexForPtsUsingEncoderIndex --- src/torchcodec/decoders/_core/VideoDecoder.cpp | 14 ++++---------- src/torchcodec/decoders/_core/VideoDecoder.h | 3 --- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/torchcodec/decoders/_core/VideoDecoder.cpp b/src/torchcodec/decoders/_core/VideoDecoder.cpp index bba8b4e4a..274b10757 100644 --- a/src/torchcodec/decoders/_core/VideoDecoder.cpp +++ b/src/torchcodec/decoders/_core/VideoDecoder.cpp @@ -553,14 +553,6 @@ VideoDecoder::ContainerMetadata VideoDecoder::getContainerMetadata() const { return containerMetadata_; } -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& keyFrames, int64_t pts) const { @@ -683,9 +675,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); } /* diff --git a/src/torchcodec/decoders/_core/VideoDecoder.h b/src/torchcodec/decoders/_core/VideoDecoder.h index 760b534df..aa2080a99 100644 --- a/src/torchcodec/decoders/_core/VideoDecoder.h +++ b/src/torchcodec/decoders/_core/VideoDecoder.h @@ -416,9 +416,6 @@ class VideoDecoder { int getKeyFrameIndexForPtsUsingScannedIndex( const std::vector& 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,