[FFmpeg-devel] [PATCH 16/47] fftools/ffmpeg_filter: return error codes from ofilter_bind_ost() instead of aborting

Anton Khirnov anton at khirnov.net
Sat Jul 15 13:45:40 EEST 2023


---
 fftools/ffmpeg.h          |  2 +-
 fftools/ffmpeg_filter.c   | 12 ++++++++----
 fftools/ffmpeg_mux_init.c |  4 +++-
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 62b56a8cd8..d7e16d034f 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -744,7 +744,7 @@ void ifilter_sub2video_heartbeat(InputFilter *ifilter, int64_t pts, AVRational t
  */
 int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec);
 
-void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost);
+int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost);
 
 /**
  * Create a new filtergraph in the global filtergraph list.
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index d373d8c002..cdf5610620 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -624,7 +624,7 @@ static void set_channel_layout(OutputFilterPriv *f, OutputStream *ost)
     av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels);
 }
 
-void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
+int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
 {
     OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
     FilterGraph  *fg = ofilter->graph;
@@ -699,15 +699,17 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
 
         for (int i = 0; i < fg->nb_outputs; i++)
             if (!fg->outputs[i]->ost)
-                return;
+                return 0;
 
         ret = configure_filtergraph(fg);
         if (ret < 0) {
             av_log(fg, AV_LOG_ERROR, "Error configuring filter graph: %s\n",
                    av_err2str(ret));
-            exit_program(1);
+            return ret;
         }
     }
+
+    return 0;
 }
 
 static InputFilter *ifilter_alloc(FilterGraph *fg)
@@ -899,7 +901,9 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
     if (ret < 0)
         return ret;
 
-    ofilter_bind_ost(fg->outputs[0], ost);
+    ret = ofilter_bind_ost(fg->outputs[0], ost);
+    if (ret < 0)
+        return ret;
 
     return 0;
 }
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index cc5ec68040..359a5149d4 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1393,7 +1393,9 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
         (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
         if (ofilter) {
             ost->filter       = ofilter;
-            ofilter_bind_ost(ofilter, ost);
+            ret = ofilter_bind_ost(ofilter, ost);
+            if (ret < 0)
+                return ret;
         } else {
             ret = init_simple_filtergraph(ost->ist, ost, filters);
             if (ret < 0) {
-- 
2.40.1



More information about the ffmpeg-devel mailing list