@@ -584,7 +584,7 @@ VideoDecoder::FrameOutput VideoDecoder::getNextFrameInternal(
584584 std::optional<torch::Tensor> preAllocatedOutputTensor) {
585585 validateActiveStream ();
586586 UniqueAVFrame avFrame = decodeAVFrame (
587- [this ](AVFrame* avFrame) { return avFrame->pts >= cursor_; });
587+ [this ](const UniqueAVFrame& avFrame) { return avFrame->pts >= cursor_; });
588588 return convertAVFrameToFrameOutput (avFrame, preAllocatedOutputTensor);
589589}
590590
@@ -715,23 +715,24 @@ VideoDecoder::FrameOutput VideoDecoder::getFramePlayedAt(double seconds) {
715715 }
716716
717717 setCursorPtsInSeconds (seconds);
718- UniqueAVFrame avFrame = decodeAVFrame ([seconds, this ](AVFrame* avFrame) {
719- StreamInfo& streamInfo = streamInfos_[activeStreamIndex_];
720- double frameStartTime = ptsToSeconds (avFrame->pts , streamInfo.timeBase );
721- double frameEndTime =
722- ptsToSeconds (avFrame->pts + getDuration (avFrame), streamInfo.timeBase );
723- if (frameStartTime > seconds) {
724- // FFMPEG seeked past the frame we are looking for even though we
725- // set max_ts to be our needed timestamp in avformat_seek_file()
726- // in maybeSeekToBeforeDesiredPts().
727- // This could be a bug in FFMPEG: https://trac.ffmpeg.org/ticket/11137
728- // In this case we return the very next frame instead of throwing an
729- // exception.
730- // TODO: Maybe log to stderr for Debug builds?
731- return true ;
732- }
733- return seconds >= frameStartTime && seconds < frameEndTime;
734- });
718+ UniqueAVFrame avFrame =
719+ decodeAVFrame ([seconds, this ](const UniqueAVFrame& avFrame) {
720+ StreamInfo& streamInfo = streamInfos_[activeStreamIndex_];
721+ double frameStartTime = ptsToSeconds (avFrame->pts , streamInfo.timeBase );
722+ double frameEndTime = ptsToSeconds (
723+ avFrame->pts + getDuration (avFrame), streamInfo.timeBase );
724+ if (frameStartTime > seconds) {
725+ // FFMPEG seeked past the frame we are looking for even though we
726+ // set max_ts to be our needed timestamp in avformat_seek_file()
727+ // in maybeSeekToBeforeDesiredPts().
728+ // This could be a bug in FFMPEG: https://trac.ffmpeg.org/ticket/11137
729+ // In this case we return the very next frame instead of throwing an
730+ // exception.
731+ // TODO: Maybe log to stderr for Debug builds?
732+ return true ;
733+ }
734+ return seconds >= frameStartTime && seconds < frameEndTime;
735+ });
735736
736737 // Convert the frame to tensor.
737738 FrameOutput frameOutput = convertAVFrameToFrameOutput (avFrame);
@@ -890,9 +891,10 @@ VideoDecoder::AudioFramesOutput VideoDecoder::getFramesPlayedInRangeAudio(
890891 auto finished = false ;
891892 while (!finished) {
892893 try {
893- UniqueAVFrame avFrame = decodeAVFrame ([startPts](AVFrame* avFrame) {
894- return startPts < avFrame->pts + getDuration (avFrame);
895- });
894+ UniqueAVFrame avFrame =
895+ decodeAVFrame ([startPts](const UniqueAVFrame& avFrame) {
896+ return startPts < avFrame->pts + getDuration (avFrame);
897+ });
896898 // TODO: it's not great that we are getting a FrameOutput, which is
897899 // intended for videos. We should consider bypassing
898900 // convertAVFrameToFrameOutput and directly call
@@ -1035,7 +1037,7 @@ void VideoDecoder::maybeSeekToBeforeDesiredPts() {
10351037// --------------------------------------------------------------------------
10361038
10371039UniqueAVFrame VideoDecoder::decodeAVFrame (
1038- std::function<bool (AVFrame* )> filterFunction) {
1040+ std::function<bool (const UniqueAVFrame& )> filterFunction) {
10391041 validateActiveStream ();
10401042
10411043 resetDecodeStats ();
@@ -1063,7 +1065,7 @@ UniqueAVFrame VideoDecoder::decodeAVFrame(
10631065
10641066 decodeStats_.numFramesReceivedByDecoder ++;
10651067 // Is this the kind of frame we're looking for?
1066- if (status == AVSUCCESS && filterFunction (avFrame. get () )) {
1068+ if (status == AVSUCCESS && filterFunction (avFrame)) {
10671069 // Yes, this is the frame we'll return; break out of the decoding loop.
10681070 break ;
10691071 } else if (status == AVSUCCESS) {
0 commit comments