Skip to content

Commit 9dbf49f

Browse files
committed
Fix stopPts logic
1 parent bd7c6ae commit 9dbf49f

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -890,16 +890,15 @@ VideoDecoder::AudioFramesOutput VideoDecoder::getFramesPlayedInRangeAudio(
890890
std::optional<double> stopSecondsOptional) {
891891
validateActiveStream(AVMEDIA_TYPE_AUDIO);
892892

893-
double stopSeconds =
894-
stopSecondsOptional.value_or(std::numeric_limits<double>::max());
895-
896-
TORCH_CHECK(
897-
startSeconds <= stopSeconds,
898-
"Start seconds (" + std::to_string(startSeconds) +
899-
") must be less than or equal to stop seconds (" +
900-
std::to_string(stopSeconds) + ").");
893+
if (stopSecondsOptional.has_value()) {
894+
TORCH_CHECK(
895+
startSeconds <= *stopSecondsOptional,
896+
"Start seconds (" + std::to_string(startSeconds) +
897+
") must be less than or equal to stop seconds (" +
898+
std::to_string(*stopSecondsOptional) + ").");
899+
}
901900

902-
if (startSeconds == stopSeconds) {
901+
if (stopSecondsOptional.has_value() && startSeconds == *stopSecondsOptional) {
903902
// For consistency with video
904903
return AudioFramesOutput{torch::empty({0, 0}), 0.0};
905904
}
@@ -921,7 +920,9 @@ VideoDecoder::AudioFramesOutput VideoDecoder::getFramesPlayedInRangeAudio(
921920
std::vector<torch::Tensor> frames;
922921

923922
std::optional<double> firstFramePtsSeconds = std::nullopt;
924-
auto stopPts = secondsToClosestPts(stopSeconds, streamInfo.timeBase);
923+
auto stopPts = stopSecondsOptional.has_value()
924+
? secondsToClosestPts(*stopSecondsOptional, streamInfo.timeBase)
925+
: INT64_MAX;
925926
auto finished = false;
926927
while (!finished) {
927928
try {

0 commit comments

Comments
 (0)