[FFmpeg-devel] [PATCH 7/9] fftools/ffmpeg_mux_init: move the check for filtering+streamcopy

Anton Khirnov anton at khirnov.net
Sat Sep 28 12:53:39 EEST 2024


To streamcopy_init().

This will allow to simplify the control flow in ost_add() by moving the
ost_get_filters() call (which previously had to handle both encoding and
streamcopy streams) to ost_bind_filter() (which is only called for
audio/video encoding).

Also, return EINVAL rather than ENOSYS, as trying to combine filtering
with streamcopy is a parameter error.
---
 fftools/ffmpeg_mux_init.c | 52 ++++++++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 23 deletions(-)

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 117b1a4338..1ddd1d7492 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -424,27 +424,6 @@ static int ost_get_filters(const OptionsContext *o, AVFormatContext *oc,
 #endif
     opt_match_per_stream_str(ost, &o->filters, oc, ost->st, &filters);
 
-    if (!ost->enc) {
-        if (
-#if FFMPEG_OPT_FILTER_SCRIPT
-            filters_script ||
-#endif
-            filters) {
-            av_log(ost, AV_LOG_ERROR,
-                   "%s '%s' was specified, but codec copy was selected. "
-                   "Filtering and streamcopy cannot be used together.\n",
-#if FFMPEG_OPT_FILTER_SCRIPT
-                   filters ? "Filtergraph" : "Filtergraph script",
-                   filters ? filters : filters_script
-#else
-                   "Filtergraph", filters
-#endif
-                   );
-            return AVERROR(ENOSYS);
-        }
-        return 0;
-    }
-
     if (!ost->ist) {
         if (
 #if FFMPEG_OPT_FILTER_SCRIPT
@@ -1028,7 +1007,8 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter,
     return ret;
 }
 
-static int streamcopy_init(const Muxer *mux, OutputStream *ost, AVDictionary **encoder_opts)
+static int streamcopy_init(const OptionsContext *o, const Muxer *mux,
+                           OutputStream *ost, AVDictionary **encoder_opts)
 {
     MuxStream           *ms         = ms_from_ost(ost);
 
@@ -1044,6 +1024,32 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost, AVDictionary **e
 
     int ret = 0;
 
+    const char *filters = NULL;
+#if FFMPEG_OPT_FILTER_SCRIPT
+    const char *filters_script = NULL;
+
+    opt_match_per_stream_str(ost, &o->filter_scripts, mux->fc, ost->st, &filters_script);
+#endif
+    opt_match_per_stream_str(ost, &o->filters, mux->fc, ost->st, &filters);
+
+    if (
+#if FFMPEG_OPT_FILTER_SCRIPT
+        filters_script ||
+#endif
+        filters) {
+        av_log(ost, AV_LOG_ERROR,
+               "%s '%s' was specified, but codec copy was selected. "
+               "Filtering and streamcopy cannot be used together.\n",
+#if FFMPEG_OPT_FILTER_SCRIPT
+               filters ? "Filtergraph" : "Filtergraph script",
+               filters ? filters : filters_script
+#else
+               "Filtergraph", filters
+#endif
+               );
+        return AVERROR(EINVAL);
+    }
+
     codec_ctx = avcodec_alloc_context3(NULL);
     if (!codec_ctx)
         return AVERROR(ENOMEM);
@@ -1562,7 +1568,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
     }
 
     if (ost->ist && !ost->enc) {
-        ret = streamcopy_init(mux, ost, &encoder_opts);
+        ret = streamcopy_init(o, mux, ost, &encoder_opts);
         if (ret < 0)
             goto fail;
     }
-- 
2.43.0



More information about the ffmpeg-devel mailing list