[FFmpeg-devel] [PATCH v4 2/2] lavf/mpegenc: fix termination following a fifo overrun

Nicolas Gaullier nicolas.gaullier at cji.paris
Tue Mar 22 19:23:37 EET 2022


Avoid an infinite 'retry' loop in output_packet when flushing.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier at cji.paris>
---
 libavformat/mpegenc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index e0955a7d33..91574ca95a 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c
@@ -85,6 +85,7 @@ typedef struct MpegMuxContext {
 
     int preload;
     int fifo_size_limit;
+    int fifo_size_exceeded;
 } MpegMuxContext;
 
 extern const AVOutputFormat ff_mpeg1vcd_muxer;
@@ -1221,9 +1222,11 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt)
     }
 
     ret = av_fifo_write(stream->fifo, buf, size);
-    if (ret == AVERROR(ENOSPC))
+    if (ret == AVERROR(ENOSPC)) {
+        s->fifo_size_exceeded = 1;
         av_log(s, AV_LOG_FATAL, "Input stream buffer overrun. "
                 "To avoid, increase fifo_size_limit option.\n");
+    }
     if (ret < 0)
         return ret;
 
@@ -1236,9 +1239,13 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt)
 
 static int mpeg_mux_end(AVFormatContext *ctx)
 {
+    MpegMuxContext *s = ctx->priv_data;
     StreamInfo *stream;
     int i;
 
+    if (s->fifo_size_exceeded)
+        return 0;
+
     for (;;) {
         int ret = output_packet(ctx, 1);
         if (ret < 0)
-- 
2.34.0



More information about the ffmpeg-devel mailing list