Skip to content

Commit 448c4a6

Browse files
committed
More inline comment
1 parent fa374bc commit 448c4a6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,8 +1119,13 @@ VideoDecoder::BatchDecodedOutput VideoDecoder::getFramesDisplayedByTimestamps(
11191119

11201120
auto it = std::lower_bound(
11211121
stream.allFrames.begin(),
1122-
// See https://github.com/pytorch/torchcodec/pull/286 for why the `- 1`
1123-
// is needed.
1122+
// We have to end the search at end() - 1 to exclude the last frame from
1123+
// the search: the last frame's nextPts field is 0, which breaks the
1124+
// working assumption of std::lower_bound() that the search space must
1125+
// be sorted. The last frame can still be correctly returned: when the
1126+
// binary search ends without a match, `end() - 1` will be returned, and
1127+
// that corresponds to the last frame.
1128+
// See https://github.com/pytorch/torchcodec/pull/286 for more details.
11241129
stream.allFrames.end() - 1,
11251130
framePts,
11261131
[&stream](const FrameInfo& info, double framePts) {

0 commit comments

Comments
 (0)