Skip to content

Commit 9c23c8d

Browse files
committed
Simplify get_frame_played_at
1 parent 374d950 commit 9c23c8d

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -698,24 +698,9 @@ VideoDecoder::FrameOutput VideoDecoder::getFramePlayedAt(double seconds) {
698698
}
699699

700700
setCursorPtsInSeconds(seconds);
701-
AVFrameStream avFrameStream =
702-
decodeAVFrame([seconds, this](AVFrame* avFrame) {
703-
StreamInfo& streamInfo = streamInfos_[activeStreamIndex_];
704-
double frameStartTime = ptsToSeconds(avFrame->pts, streamInfo.timeBase);
705-
double frameEndTime = ptsToSeconds(
706-
avFrame->pts + getDuration(avFrame), streamInfo.timeBase);
707-
if (frameStartTime > seconds) {
708-
// FFMPEG seeked past the frame we are looking for even though we
709-
// set max_ts to be our needed timestamp in avformat_seek_file()
710-
// in maybeSeekToBeforeDesiredPts().
711-
// This could be a bug in FFMPEG: https://trac.ffmpeg.org/ticket/11137
712-
// In this case we return the very next frame instead of throwing an
713-
// exception.
714-
// TODO: Maybe log to stderr for Debug builds?
715-
return true;
716-
}
717-
return seconds >= frameStartTime && seconds < frameEndTime;
718-
});
701+
AVFrameStream avFrameStream = decodeAVFrame([this](AVFrame* avFrame) {
702+
return cursor_ < avFrame->pts + getDuration(avFrame);
703+
});
719704

720705
// Convert the frame to tensor.
721706
FrameOutput frameOutput = convertAVFrameToFrameOutput(avFrameStream);

0 commit comments

Comments
 (0)