Skip to content

Commit

Permalink
this should work
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasHug committed Jan 23, 2025
1 parent bc024eb commit a17027c
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions src/torchcodec/decoders/_core/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,27 +1080,7 @@ VideoDecoder::FrameOutput VideoDecoder::getFramePlayedAtTimestampNoDemux(
}

setCursorPtsInSeconds(seconds);
AVFrameWithStreamIndex avFrameWithStreamIndex = getAVFrameUsingFilterFunction(
[seconds, this](int frameStreamIndex, AVFrame* avFrame) {
StreamInfo& streamInfo = streamInfos_[frameStreamIndex];
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;
});

// Convert the frame to tensor.
FrameOutput frameOutput = convertAVFrameToFrameOutput(avFrameWithStreamIndex);
FrameOutput frameOutput = getNextFrameNoDemuxInternal();
frameOutput.data =
maybePermuteHWC2CHW(frameOutput.streamIndex, frameOutput.data);
return frameOutput;
Expand Down

0 comments on commit a17027c

Please sign in to comment.