Skip to content

Commit 251a0af

Browse files
committed
Minor cleanup for firstFramePtsSeconds
1 parent 611421e commit 251a0af

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ VideoDecoder::AudioFramesOutput VideoDecoder::getFramesPlayedInRangeAudio(
924924
// sample rate, so in theory we know the number of output samples.
925925
std::vector<torch::Tensor> frames;
926926

927-
double firstFramePtsSeconds = std::numeric_limits<double>::max();
927+
std::optional<double> firstFramePtsSeconds = std::nullopt;
928928
auto stopPts = secondsToClosestPts(stopSeconds, streamInfo.timeBase);
929929
auto finished = false;
930930
while (!finished) {
@@ -934,8 +934,9 @@ VideoDecoder::AudioFramesOutput VideoDecoder::getFramesPlayedInRangeAudio(
934934
return startPts < avFrame->pts + getDuration(avFrame);
935935
});
936936
auto frameOutput = convertAVFrameToFrameOutput(avFrame);
937-
firstFramePtsSeconds =
938-
std::min(firstFramePtsSeconds, frameOutput.ptsSeconds);
937+
if (!firstFramePtsSeconds.has_value()) {
938+
firstFramePtsSeconds = frameOutput.ptsSeconds;
939+
}
939940
frames.push_back(frameOutput.data);
940941
} catch (const EndOfFileException& e) {
941942
finished = true;
@@ -956,7 +957,7 @@ VideoDecoder::AudioFramesOutput VideoDecoder::getFramesPlayedInRangeAudio(
956957
frames.push_back(*lastSamples);
957958
}
958959

959-
return AudioFramesOutput{torch::cat(frames, 1), firstFramePtsSeconds};
960+
return AudioFramesOutput{torch::cat(frames, 1), *firstFramePtsSeconds};
960961
}
961962

962963
// --------------------------------------------------------------------------

0 commit comments

Comments
 (0)