[FFmpeg-devel] [PATCH 41/49] fftools/ffmpeg_mux: return errors from write_packet()

Anton Khirnov anton at khirnov.net
Mon Apr 4 14:30:29 EEST 2022


---
 fftools/ffmpeg_mux.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 69af2c8d46..37ae61fee8 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -166,7 +166,7 @@ static int queue_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
     return 0;
 }
 
-static void write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
+static int write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
 {
     MuxStream *ms = &of->mux->streams[ost->index];
     AVFormatContext *s = of->mux->fc;
@@ -211,10 +211,8 @@ static void write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
                 av_log(s, loglevel, "Non-monotonous DTS in output stream "
                        "%d:%d; previous: %"PRId64", current: %"PRId64"; ",
                        ost->file_index, ost->st->index, ms->last_mux_dts, pkt->dts);
-                if (exit_on_error) {
-                    av_log(NULL, AV_LOG_FATAL, "aborting.\n");
-                    exit_program(1);
-                }
+                if (exit_on_error)
+                    return AVERROR(EINVAL);
                 av_log(s, loglevel, "changing to %"PRId64". This may result "
                        "in incorrect timestamps in the output file.\n",
                        max);
@@ -250,7 +248,10 @@ static void write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
         print_error("av_interleaved_write_frame()", ret);
         main_return_code = 1;
         close_all_output_streams(ost, MUXER_FINISHED | ENCODER_FINISHED, ENCODER_FINISHED);
+        return ret;
     }
+
+    return 0;
 }
 
 static int submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
@@ -258,7 +259,7 @@ static int submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
     int ret;
 
     if (of->mux->header_written) {
-        write_packet(of, ost, pkt);
+        return write_packet(of, ost, pkt);
     } else {
         /* the muxer is not initialized yet, buffer the packet */
         ret = queue_packet(of, ost, pkt);
@@ -401,8 +402,10 @@ int of_check_init(OutputFile *of)
 
         while (av_fifo_read(ms->muxing_queue, &pkt, 1) >= 0) {
             ms->muxing_queue_data_size -= pkt->size;
-            write_packet(of, ost, pkt);
+            ret = write_packet(of, ost, pkt);
             av_packet_free(&pkt);
+            if (ret < 0)
+                return ret;
         }
     }
 
-- 
2.34.1



More information about the ffmpeg-devel mailing list