File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
src/torchcodec/decoders/_core Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -1119,12 +1119,18 @@ VideoDecoder::BatchDecodedOutput VideoDecoder::getFramesDisplayedByTimestamps(
11191119
11201120 auto it = std::lower_bound (
11211121 stream.allFrames .begin (),
1122- stream.allFrames .end () - 1 ,
1122+ stream.allFrames .end (),
11231123 framePts,
11241124 [&stream](const FrameInfo& info, double framePts) {
11251125 return ptsToSeconds (info.nextPts , stream.timeBase ) <= framePts;
11261126 });
11271127 int64_t frameIndex = it - stream.allFrames .begin ();
1128+ // If the frame index is larger than the size of allFrames, that means we
1129+ // couldn't match the pts value to the pts value of a NEXT FRAME. And
1130+ // that means that this timestamp falls during the time between when the
1131+ // last frame is displayed, and the video ends. Hence, it should map to the
1132+ // index of the last frame.
1133+ frameIndex = std::min (frameIndex, (int64_t )stream.allFrames .size () - 1 );
11281134 frameIndices[i] = frameIndex;
11291135 }
11301136
Original file line number Diff line number Diff line change @@ -177,10 +177,10 @@ def test_get_frames_by_pts(self):
177177 for frame , expected_frame in zip (frames , expected_frames ):
178178 assert_tensor_equal (frame , expected_frame )
179179
180- # # first and last frame should be equal, at pts=2 [+ eps]. We then
181- # modify the # first frame and assert that it's now different from the
182- # last frame. # This ensures a copy was properly made during the
183- # de-duplication logic.
180+ # first and last frame should be equal, at pts=2 [+ eps]. We then modify
181+ # the first frame and assert that it's now different from the last
182+ # frame. This ensures a copy was properly made during the de-duplication
183+ # logic.
184184 assert_tensor_equal (frames [0 ], frames [- 1 ])
185185 frames [0 ] += 20
186186 with pytest .raises (AssertionError ):
You can’t perform that action at this time.
0 commit comments