@@ -827,7 +827,7 @@ VideoDecoder::AVFrameStream VideoDecoder::filteredDecode(
827827 frameStreamIndex = -1 ;
828828 bool gotPermanentErrorOnAnyActiveStream = false ;
829829
830- // Get a frame on an active stream
830+ // Get a frame on an active stream.
831831 for (int streamIndex : activeStreamIndices_) {
832832 StreamInfo& streamInfo = streamInfos_[streamIndex];
833833 ffmpegStatus =
@@ -839,7 +839,7 @@ VideoDecoder::AVFrameStream VideoDecoder::filteredDecode(
839839 break ;
840840 }
841841
842- // Found one.
842+ // Found one!
843843 if (ffmpegStatus == AVSUCCESS) {
844844 frameStreamIndex = streamIndex;
845845 break ;
@@ -854,14 +854,14 @@ VideoDecoder::AVFrameStream VideoDecoder::filteredDecode(
854854
855855 // Is this the kind of frame we're looking for?
856856 if (ffmpegStatus == AVSUCCESS && filter (frameStreamIndex, avFrame.get ())) {
857- // Yes, this is the frame we'll return.
857+ // Yes, this is the frame we'll return; break out of the decoding loop .
858858 break ;
859859 } else if (ffmpegStatus == AVSUCCESS) {
860860 // No, but we received a valid frame - just not the kind we're looking
861861 // for. The logic below will read packets and send them to the decoder.
862862 // But since we did just receive a frame, we should skip reading more
863- // packets and sending them to the decoder and just try to get more frames
864- // from the decoder
863+ // packets and sending them to the decoder and just try to receive more
864+ // frames from the decoder.
865865 continue ;
866866 }
867867
@@ -876,6 +876,7 @@ VideoDecoder::AVFrameStream VideoDecoder::filteredDecode(
876876 ReferenceAVPacket packet (autoAVPacket);
877877 ffmpegStatus = av_read_frame (formatContext_.get (), packet.get ());
878878 decodeStats_.numPacketsRead ++;
879+
879880 if (ffmpegStatus == AVERROR_EOF) {
880881 // End of file reached. We must drain all codecs by sending a nullptr
881882 // packet.
@@ -890,6 +891,10 @@ VideoDecoder::AVFrameStream VideoDecoder::filteredDecode(
890891 getFFMPEGErrorStringFromErrorCode (ffmpegStatus));
891892 }
892893 }
894+
895+ // We've reached the end of file so we can't read any more packets from
896+ // it, but the decoder may still have frames to read in its buffer.
897+ // Continue iterating to try reading frames.
893898 reachedEOF = true ;
894899 continue ;
895900 }
0 commit comments