[FFmpeg-devel] [PATCH] ffmpeg: Properly handle EOF return when flushing encoder

Andriy Gelman andriy.gelman at gmail.com
Wed Oct 23 15:11:41 EEST 2019


From: Andriy Gelman <andriy.gelman at gmail.com>

When flushing an encoder we send a NULL frame to avcodec_send_frame()
and then deque all compressed packets in avcodec_recieve_packet() until
AVERROR(EAGAIN) is returned (indicating that all compressed packets have
been removed). The second time that avcodec_send_frame() is called with a
NULL frame it returns AVERROR_EOF.

At the moment, avcoded_send_frame() treats all errors as fatal errors,
even when AVERROR_EOF is returned, meaning that an encoder is not
properly shutdown.
Since all other returns are handled after the while loop, it suffices to
break when AVERROR_EOF is encountered to fix this problem.
---
 fftools/ffmpeg.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 8e408c808a..9e9fc7a714 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1933,12 +1933,8 @@ static void flush_encoders(void)
 
             while ((ret = avcodec_receive_packet(enc, &pkt)) == AVERROR(EAGAIN)) {
                 ret = avcodec_send_frame(enc, NULL);
-                if (ret < 0) {
-                    av_log(NULL, AV_LOG_FATAL, "%s encoding failed: %s\n",
-                           desc,
-                           av_err2str(ret));
-                    exit_program(1);
-                }
+                if (ret == AVERROR_EOF)
+                    break;
             }
 
             update_benchmark("flush_%s %d.%d", desc, ost->file_index, ost->index);
-- 
2.23.0



More information about the ffmpeg-devel mailing list