Skip to content

Commit 5ac1523

Browse files
committed
Clean up some logic
1 parent 10022ab commit 5ac1523

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -658,20 +658,16 @@ VideoDecoder::getFramesInRange(int64_t start, int64_t stop, int64_t step) {
658658
return frameBatchOutput;
659659
}
660660

661-
VideoDecoder::FrameOutput VideoDecoder::getFramePlayedAt(
662-
double seconds) {
663-
for (auto& [streamIndex, streamInfo] : streamInfos_) {
664-
double frameStartTime =
665-
ptsToSeconds(streamInfo.currentPts, streamInfo.timeBase);
666-
double frameEndTime = ptsToSeconds(
667-
streamInfo.currentPts + streamInfo.currentDuration,
668-
streamInfo.timeBase);
669-
if (seconds >= frameStartTime && seconds < frameEndTime) {
670-
// We are in the same frame as the one we just returned. However, since we
671-
// don't cache it locally, we have to rewind back.
672-
seconds = frameStartTime;
673-
break;
674-
}
661+
VideoDecoder::FrameOutput VideoDecoder::getFramePlayedAt(double seconds) {
662+
StreamInfo& streamInfo = streamInfos_[activeStreamIndex_];
663+
double frameStartTime =
664+
ptsToSeconds(streamInfo.currentPts, streamInfo.timeBase);
665+
double frameEndTime = ptsToSeconds(
666+
streamInfo.currentPts + streamInfo.currentDuration, streamInfo.timeBase);
667+
if (seconds >= frameStartTime && seconds < frameEndTime) {
668+
// We are in the same frame as the one we just returned. However, since we
669+
// don't cache it locally, we have to rewind back.
670+
seconds = frameStartTime;
675671
}
676672

677673
setCursorPtsInSeconds(seconds);

test/decoders/VideoDecoderTest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ TEST_P(VideoDecoderTest, GetsFramePlayedAtTimestamp) {
285285
kPtsOfLastFrameInVideoStream + kDurationOfLastFrameInVideoStream;
286286
// Sanity check: make sure duration is strictly positive.
287287
EXPECT_GT(kPtsPlusDurationOfLastFrame, kPtsOfLastFrameInVideoStream);
288-
output =
289-
ourDecoder->getFramePlayedAt(kPtsPlusDurationOfLastFrame - 1e-6);
288+
output = ourDecoder->getFramePlayedAt(kPtsPlusDurationOfLastFrame - 1e-6);
290289
EXPECT_EQ(output.ptsSeconds, kPtsOfLastFrameInVideoStream);
291290
}
292291

0 commit comments

Comments
 (0)