diff mbox series

[FFmpeg-devel,3/5] fftools/ffmpeg: close output files before cleanup

Message ID 20211130004950.30697-3-cus@passwd.hu
State Accepted
Commit 8d66a07d657ba7ed8c5e95345d4eec770b55e438
Headers show
Series [FFmpeg-devel,1/5] avformat/file: use proper return value in file_close | 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

Commit Message

Marton Balint Nov. 30, 2021, 12:49 a.m. UTC
This allows us to check the return value of avio_closep().

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 fftools/ffmpeg.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 25360423b5..ea75fad637 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -4716,7 +4716,7 @@  static int transcode(void)
 
     term_exit();
 
-    /* write the trailer if needed and close file */
+    /* write the trailer if needed */
     for (i = 0; i < nb_output_files; i++) {
         os = output_files[i]->ctx;
         if (!output_files[i]->header_written) {
@@ -4736,6 +4736,18 @@  static int transcode(void)
     /* dump report by using the first video and audio streams */
     print_report(1, timer_start, av_gettime_relative());
 
+    /* close the output files */
+    for (i = 0; i < nb_output_files; i++) {
+        os = output_files[i]->ctx;
+        if (os && os->oformat && !(os->oformat->flags & AVFMT_NOFILE)) {
+            if ((ret = avio_closep(&os->pb)) < 0) {
+                av_log(NULL, AV_LOG_ERROR, "Error closing file %s: %s\n", os->url, av_err2str(ret));
+                if (exit_on_error)
+                    exit_program(1);
+            }
+        }
+    }
+
     /* close each encoder */
     for (i = 0; i < nb_output_streams; i++) {
         ost = output_streams[i];