diff mbox series

[FFmpeg-devel,11/24] fftools/ffmpeg_filter: try to configure filtergraphs earlier

Message ID 20230528091416.17927-11-anton@khirnov.net
State Accepted
Commit ad4efb91586dc4918121d96030d247be6af630c1
Headers show
Series [FFmpeg-devel,01/24] fftools/ffmpeg_mux_init: merge ost_add_from_filter() to ost_add() | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov May 28, 2023, 9:14 a.m. UTC
When the filtergraph has no inputs, it can be configured immediately
when all its outputs are bound to output streams. This will simplify
treating some corner cases.
---
 fftools/ffmpeg_filter.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 3f6b906468..3bf1862ab6 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -504,6 +504,7 @@  static void set_channel_layout(OutputFilter *f, OutputStream *ost)
 
 void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
 {
+    FilterGraph  *fg = ofilter->graph;
     const AVCodec *c = ost->enc_ctx->codec;
 
     ofilter->ost = ost;
@@ -538,6 +539,23 @@  void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
         }
         break;
     }
+
+    // if we have all input parameters and all outputs are bound,
+    // the graph can now be configured
+    if (ifilter_has_all_input_formats(fg)) {
+        int ret;
+
+        for (int i = 0; i < fg->nb_outputs; i++)
+            if (!fg->outputs[i]->ost)
+                return;
+
+        ret = configure_filtergraph(fg);
+        if (ret < 0) {
+            av_log(NULL, AV_LOG_ERROR, "Error configuring filter graph: %s\n",
+                   av_err2str(ret));
+            exit_program(1);
+        }
+    }
 }
 
 static InputFilter *ifilter_alloc(FilterGraph *fg)