diff mbox series

[FFmpeg-devel,09/11] fftools/ffmpeg: move unconfigured graph handling to ffmpeg_filter

Message ID 20230505090723.24872-9-anton@khirnov.net
State Accepted
Commit dd1c67d5393303ad23ba8cb494ddb17a2c1a002b
Headers show
Series [FFmpeg-devel,01/11] fftools/ffmpeg: merge choose_output() and got_eagain() | 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 5, 2023, 9:07 a.m. UTC
This code more properly belongs there.
---
 fftools/ffmpeg.c        | 25 +------------------------
 fftools/ffmpeg_filter.c | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 24 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 38569c60a4..1ae9445b5d 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2018,34 +2018,11 @@  static int transcode_step(OutputStream *ost)
     InputStream  *ist = NULL;
     int ret;
 
-    if (ost->filter && !ost->filter->graph->graph) {
-        if (ifilter_has_all_input_formats(ost->filter->graph)) {
-            ret = configure_filtergraph(ost->filter->graph);
-            if (ret < 0) {
-                av_log(NULL, AV_LOG_ERROR, "Error reinitializing filters!\n");
-                return ret;
-            }
-        }
-    }
-
-    if (ost->filter && ost->filter->graph->graph) {
+    if (ost->filter) {
         if ((ret = fg_transcode_step(ost->filter->graph, &ist)) < 0)
             return ret;
         if (!ist)
             return 0;
-    } else if (ost->filter) {
-        int i;
-        for (i = 0; i < ost->filter->graph->nb_inputs; i++) {
-            InputFilter *ifilter = ost->filter->graph->inputs[i];
-            if (!ifilter->ist->got_output && !input_files[ifilter->ist->file_index]->eof_reached) {
-                ist = ifilter->ist;
-                break;
-            }
-        }
-        if (!ist) {
-            ost->inputs_done = 1;
-            return 0;
-        }
     } else {
         ist = ost->ist;
         av_assert0(ist);
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 0165be8f77..634315fa34 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1623,6 +1623,33 @@  int fg_transcode_step(FilterGraph *graph, InputStream **best_ist)
     InputFilter *ifilter;
     InputStream *ist;
 
+    if (!graph->graph && ifilter_has_all_input_formats(graph)) {
+        // graph has not been configured yet, but everything is ready;
+        // this can happen for graphs with no inputs, or when some input
+        // EOF'ed with zero frames and fallback parameters were used
+        ret = configure_filtergraph(graph);
+        if (ret < 0) {
+            av_log(NULL, AV_LOG_ERROR, "Error reinitializing filters!\n");
+            return ret;
+        }
+    }
+
+    if (!graph->graph) {
+        for (int i = 0; i < graph->nb_inputs; i++) {
+            InputFilter *ifilter = graph->inputs[i];
+            if (!ifilter->ist->got_output && !input_files[ifilter->ist->file_index]->eof_reached) {
+                *best_ist = ifilter->ist;
+                return 0;
+            }
+        }
+
+        // graph not configured, but all inputs are either initialized or EOF
+        for (int i = 0; i < graph->nb_outputs; i++)
+            graph->outputs[i]->ost->inputs_done = 1;
+
+        return 0;
+    }
+
     *best_ist = NULL;
     ret = avfilter_graph_request_oldest(graph->graph);
     if (ret >= 0)