[FFmpeg-devel] [PATCH 3/3] ffmpeg: properly close down muxers on av_interleaved_write_frame() failure

Michael Niedermayer michaelni at gmx.at
Tue Jan 14 04:40:41 CET 2014


Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 ffmpeg.c |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 5831a78..228849f 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -313,6 +313,7 @@ void term_exit(void)
 
 static volatile int received_sigterm = 0;
 static volatile int received_nb_signals = 0;
+static int main_return_code = 0;
 
 static void
 sigterm_handler(int sig)
@@ -547,6 +548,15 @@ static void update_benchmark(const char *fmt, ...)
     }
 }
 
+static void close_all_output_streams(void)
+{
+    int i;
+    for (i = 0; i < nb_output_streams; i++) {
+        OutputStream *ost = output_streams[i];
+        ost->finished = 1;
+    }
+}
+
 static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
 {
     AVBitStreamFilterContext *bsfc = ost->bitstream_filters;
@@ -647,7 +657,8 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
     ret = av_interleaved_write_frame(s, pkt);
     if (ret < 0) {
         print_error("av_interleaved_write_frame()", ret);
-        exit_program(1);
+        main_return_code = 1;
+        close_all_output_streams();
     }
 }
 
@@ -3559,6 +3570,6 @@ int main(int argc, char **argv)
     if ((decode_error_stat[0] + decode_error_stat[1]) * max_error_rate < decode_error_stat[1])
         exit_program(69);
 
-    exit_program(received_nb_signals ? 255 : 0);
-    return 0;
+    exit_program(received_nb_signals ? 255 : main_return_code);
+    return main_return_code;
 }
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list