Skip to content

Commit b80757e

Browse files
committed
More single-stream stuff
1 parent 6f01650 commit b80757e

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,6 @@ VideoDecoder::FrameBatchOutput VideoDecoder::getFramesPlayedAt(
703703

704704
const auto& streamMetadata =
705705
containerMetadata_.allStreamMetadata[activeStreamIndex_];
706-
const auto& streamInfo = streamInfos_[activeStreamIndex_];
707706

708707
double minSeconds = getMinSeconds(streamMetadata);
709708
double maxSeconds = getMaxSeconds(streamMetadata);
@@ -723,7 +722,7 @@ VideoDecoder::FrameBatchOutput VideoDecoder::getFramesPlayedAt(
723722
std::to_string(maxSeconds) + ").");
724723

725724
frameIndices[i] =
726-
secondsToIndexLowerBound(frameSeconds, streamInfo, streamMetadata);
725+
secondsToIndexLowerBound(frameSeconds);
727726
}
728727

729728
return getFramesAtIndices(frameIndices);
@@ -795,7 +794,7 @@ VideoDecoder::FrameBatchOutput VideoDecoder::getFramesPlayedInRange(
795794
// frame's pts, but before the next frames's pts.
796795

797796
int64_t startFrameIndex =
798-
secondsToIndexLowerBound(startSeconds, streamInfo, streamMetadata);
797+
secondsToIndexLowerBound(startSeconds);
799798
int64_t stopFrameIndex =
800799
secondsToIndexUpperBound(stopSeconds, streamInfo, streamMetadata);
801800
int64_t numFrames = stopFrameIndex - startFrameIndex;
@@ -1499,10 +1498,8 @@ int VideoDecoder::getKeyFrameIndexForPtsUsingScannedIndex(
14991498
return upperBound - 1 - keyFrames.begin();
15001499
}
15011500

1502-
int64_t VideoDecoder::secondsToIndexLowerBound(
1503-
double seconds,
1504-
const StreamInfo& streamInfo,
1505-
const StreamMetadata& streamMetadata) {
1501+
int64_t VideoDecoder::secondsToIndexLowerBound(double seconds) {
1502+
auto& streamInfo = streamInfos_[activeStreamIndex_];
15061503
switch (seekMode_) {
15071504
case SeekMode::exact: {
15081505
auto frame = std::lower_bound(
@@ -1515,8 +1512,10 @@ int64_t VideoDecoder::secondsToIndexLowerBound(
15151512

15161513
return frame - streamInfo.allFrames.begin();
15171514
}
1518-
case SeekMode::approximate:
1515+
case SeekMode::approximate: {
1516+
auto& streamMetadata = containerMetadata_.allStreamMetadata[activeStreamIndex_];
15191517
return std::floor(seconds * streamMetadata.averageFps.value());
1518+
}
15201519
default:
15211520
throw std::runtime_error("Unknown SeekMode");
15221521
}

src/torchcodec/decoders/_core/VideoDecoder.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,7 @@ class VideoDecoder {
414414
const std::vector<VideoDecoder::FrameInfo>& keyFrames,
415415
int64_t pts) const;
416416

417-
int64_t secondsToIndexLowerBound(
418-
double seconds,
419-
const StreamInfo& streamInfo,
420-
const StreamMetadata& streamMetadata);
417+
int64_t secondsToIndexLowerBound(double seconds);
421418

422419
int64_t secondsToIndexUpperBound(
423420
double seconds,

0 commit comments

Comments
 (0)