diff mbox series

[FFmpeg-devel,05/28] ffmpeg: move freeing the output file to ffmpeg_mux.c

Message ID 20220111095830.31542-5-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/28] ffmpeg: pass the muxer context explicitly to some functions | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Anton Khirnov Jan. 11, 2022, 9:58 a.m. UTC
---
 fftools/ffmpeg.c     | 14 ++------------
 fftools/ffmpeg.h     |  1 +
 fftools/ffmpeg_mux.c | 17 +++++++++++++++++
 3 files changed, 20 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 87e8b0be59..320ab8e0ca 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -567,19 +567,9 @@  static void ffmpeg_cleanup(int ret)
     av_freep(&subtitle_out);
 
     /* close files */
-    for (i = 0; i < nb_output_files; i++) {
-        OutputFile *of = output_files[i];
-        AVFormatContext *s;
-        if (!of)
-            continue;
-        s = of->ctx;
-        if (s && s->oformat && !(s->oformat->flags & AVFMT_NOFILE))
-            avio_closep(&s->pb);
-        avformat_free_context(s);
-        av_dict_free(&of->opts);
+    for (i = 0; i < nb_output_files; i++)
+        of_close(&output_files[i]);
 
-        av_freep(&output_files[i]);
-    }
     for (i = 0; i < nb_output_streams; i++) {
         OutputStream *ost = output_streams[i];
 
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 91c313d8ef..288e0f2981 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -687,6 +687,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_close(OutputFile **pof);
 
 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 c65ed3631a..12ee3c2357 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -312,3 +312,20 @@  int of_write_trailer(OutputFile *of)
 
     return 0;
 }
+
+void of_close(OutputFile **pof)
+{
+    OutputFile *of = *pof;
+    AVFormatContext *s;
+
+    if (!of)
+        return;
+
+    s = of->ctx;
+    if (s && s->oformat && !(s->oformat->flags & AVFMT_NOFILE))
+        avio_closep(&s->pb);
+    avformat_free_context(s);
+    av_dict_free(&of->opts);
+
+    av_freep(pof);
+}