diff --git a/src/torchcodec/decoders/_core/VideoDecoder.cpp b/src/torchcodec/decoders/_core/VideoDecoder.cpp index 97214cec..7c52f877 100644 --- a/src/torchcodec/decoders/_core/VideoDecoder.cpp +++ b/src/torchcodec/decoders/_core/VideoDecoder.cpp @@ -698,24 +698,9 @@ VideoDecoder::FrameOutput VideoDecoder::getFramePlayedAt(double seconds) { } setCursorPtsInSeconds(seconds); - AVFrameStream avFrameStream = - decodeAVFrame([seconds, this](AVFrame* avFrame) { - StreamInfo& streamInfo = streamInfos_[activeStreamIndex_]; - double frameStartTime = ptsToSeconds(avFrame->pts, streamInfo.timeBase); - double frameEndTime = ptsToSeconds( - avFrame->pts + getDuration(avFrame), streamInfo.timeBase); - if (frameStartTime > seconds) { - // FFMPEG seeked past the frame we are looking for even though we - // set max_ts to be our needed timestamp in avformat_seek_file() - // in maybeSeekToBeforeDesiredPts(). - // This could be a bug in FFMPEG: https://trac.ffmpeg.org/ticket/11137 - // In this case we return the very next frame instead of throwing an - // exception. - // TODO: Maybe log to stderr for Debug builds? - return true; - } - return seconds >= frameStartTime && seconds < frameEndTime; - }); + AVFrameStream avFrameStream = decodeAVFrame([this](AVFrame* avFrame) { + return cursor_ < avFrame->pts + getDuration(avFrame); + }); // Convert the frame to tensor. FrameOutput frameOutput = convertAVFrameToFrameOutput(avFrameStream);