[FFmpeg-devel] [PATCH 06/24] ffmpeg: move writing the trailer to ffmpeg_mux.c

Anton Khirnov anton at khirnov.net
Mon Dec 13 17:20:24 EET 2021


---
 fftools/ffmpeg.c     | 16 +++-------------
 fftools/ffmpeg.h     |  1 +
 fftools/ffmpeg_mux.c | 21 +++++++++++++++++++++
 3 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index a00fe58063..1fb10869b4 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -4436,19 +4436,9 @@ static int transcode(void)
 
     /* write the trailer if needed */
     for (i = 0; i < nb_output_files; i++) {
-        os = output_files[i]->ctx;
-        if (!output_files[i]->header_written) {
-            av_log(NULL, AV_LOG_ERROR,
-                   "Nothing was written into output file %d (%s), because "
-                   "at least one of its streams received no packets.\n",
-                   i, os->url);
-            continue;
-        }
-        if ((ret = av_write_trailer(os)) < 0) {
-            av_log(NULL, AV_LOG_ERROR, "Error writing trailer of %s: %s\n", os->url, av_err2str(ret));
-            if (exit_on_error)
-                exit_program(1);
-        }
+        ret = of_write_trailer(output_files[i]);
+        if (exit_on_error)
+            exit_program(1);
     }
 
     /* dump report by using the first video and audio streams */
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index fed34b06f8..91c313d8ef 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -686,6 +686,7 @@ int hwaccel_decode_init(AVCodecContext *avctx);
 
 /* open the muxer when all the streams are initialized */
 int of_check_init(OutputFile *of);
+int of_write_trailer(OutputFile *of);
 
 void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost,
                      int unqueue);
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index e7c6ddd8f8..fec8537506 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -291,3 +291,24 @@ int of_check_init(OutputFile *of)
 
     return 0;
 }
+
+int of_write_trailer(OutputFile *of)
+{
+    int ret;
+
+    if (!of->header_written) {
+        av_log(NULL, AV_LOG_ERROR,
+               "Nothing was written into output file %d (%s), because "
+               "at least one of its streams received no packets.\n",
+               of->index, of->ctx->url);
+        return AVERROR(EINVAL);
+    }
+
+    ret = av_write_trailer(of->ctx);
+    if (ret < 0) {
+        av_log(NULL, AV_LOG_ERROR, "Error writing trailer of %s: %s\n", of->ctx->url, av_err2str(ret));
+        return ret;
+    }
+
+    return 0;
+}
-- 
2.33.0



More information about the ffmpeg-devel mailing list