Skip to content

Commit 7d26623

Browse files
committed
Fix last frame request
1 parent 4dda5b7 commit 7d26623

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,7 @@ VideoDecoder::BatchDecodedOutput VideoDecoder::getFramesDisplayedByTimestamps(
11231123
return ptsToSeconds(info.nextPts, stream.timeBase) <= start;
11241124
});
11251125
int64_t frameIndex = it - stream.allFrames.begin();
1126+
frameIndex = std::min(frameIndex, (int64_t)stream.allFrames.size() - 1);
11261127
frameIndices[i] = frameIndex;
11271128
}
11281129

test/decoders/test_video_decoder_ops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ def test_get_frames_by_pts(self):
162162
scan_all_streams_to_update_metadata(decoder)
163163
stream_index = 3
164164

165-
frame_ptss = [2, 0, 1, 0 + 1e-3, 2 + 1e-3]
165+
# Note: 13.01 should give the last video frame for the NASA video
166+
frame_ptss = [2, 0, 1, 0 + 1e-3, 13.01, 2 + 1e-3]
166167

167168
expected_frames = [
168169
get_frame_at_pts(decoder, seconds=pts)[0] for pts in frame_ptss

0 commit comments

Comments
 (0)