@@ -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