From f1dd5e49c562a8a4a4c08cb122347a01e8ae652a Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 29 May 2020 19:52:26 +0000 Subject: [PATCH] videoio(ffmpeg): fix handling of AVERROR_EOF decoder should be properly flushed after that --- modules/videoio/src/cap_ffmpeg_impl.hpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/videoio/src/cap_ffmpeg_impl.hpp b/modules/videoio/src/cap_ffmpeg_impl.hpp index fae85425b0..d77382537b 100644 --- a/modules/videoio/src/cap_ffmpeg_impl.hpp +++ b/modules/videoio/src/cap_ffmpeg_impl.hpp @@ -1215,9 +1215,20 @@ bool CvCapture_FFMPEG::grabFrame() #endif int ret = av_read_frame(ic, &packet); - if (ret == AVERROR(EAGAIN)) continue; - /* else if (ret < 0) break; */ + if (ret == AVERROR(EAGAIN)) + continue; + + if (ret == AVERROR_EOF) + { + if (rawMode) + break; + + // flush cached frames from video decoder + packet.data = NULL; + packet.size = 0; + packet.stream_index = video_stream; + } if( packet.stream_index != video_stream ) {