[FFmpeg-cvslog] avfilter/vf_blend: add support for commands

Paul B Mahol git at videolan.org
Thu Feb 4 22:45:22 EET 2021


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Thu Feb  4 21:42:38 2021 +0100| [3d7ee5c91aa3517dd10aad00e2bfe2536be5adb8] | committer: Paul B Mahol

avfilter/vf_blend: add support for commands

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3d7ee5c91aa3517dd10aad00e2bfe2536be5adb8
---

 doc/filters.texi       |  3 ++
 libavfilter/vf_blend.c | 76 +++++++++++++++++++++++++++++++++-----------------
 2 files changed, 54 insertions(+), 25 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 52bced3143..6c27ec420a 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -7455,6 +7455,9 @@ tblend=all_mode=grainextract
 @end example
 @end itemize
 
+ at subsection Commands
+This filter supports same @ref{commands} as options.
+
 @section bm3d
 
 Denoise frames using Block-Matching 3D algorithm.
diff --git a/libavfilter/vf_blend.c b/libavfilter/vf_blend.c
index ffcc0e9997..d12bfffbed 100644
--- a/libavfilter/vf_blend.c
+++ b/libavfilter/vf_blend.c
@@ -61,7 +61,7 @@ typedef struct ThreadData {
 } ThreadData;
 
 #define OFFSET(x) offsetof(BlendContext, x)
-#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
 
 static const AVOption blend_options[] = {
     { "c0_mode", "set component #0 blend mode", OFFSET(params[0].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode" },
@@ -780,13 +780,45 @@ void ff_blend_init(FilterParams *param, int depth)
         ff_blend_init_x86(param, depth);
 }
 
+static int config_params(AVFilterContext *ctx)
+{
+    BlendContext *s = ctx->priv;
+    int ret;
+
+    for (int plane = 0; plane < FF_ARRAY_ELEMS(s->params); plane++) {
+        FilterParams *param = &s->params[plane];
+
+        if (s->all_mode >= 0)
+            param->mode = s->all_mode;
+        if (s->all_opacity < 1)
+            param->opacity = s->all_opacity;
+
+        ff_blend_init(param, s->depth);
+
+        if (s->all_expr && !param->expr_str) {
+            param->expr_str = av_strdup(s->all_expr);
+            if (!param->expr_str)
+                return AVERROR(ENOMEM);
+        }
+        if (param->expr_str) {
+            ret = av_expr_parse(&param->e, param->expr_str, var_names,
+                                NULL, NULL, NULL, NULL, 0, ctx);
+            if (ret < 0)
+                return ret;
+            param->blend = s->depth > 8 ? s->depth > 16 ? blend_expr_32bit : blend_expr_16bit : blend_expr_8bit;
+        }
+    }
+
+    return 0;
+}
+
 static int config_output(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
     AVFilterLink *toplink = ctx->inputs[TOP];
     BlendContext *s = ctx->priv;
     const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(toplink->format);
-    int ret, plane;
+    int ret;
 
     if (!s->tblend) {
         AVFilterLink *bottomlink = ctx->inputs[BOTTOM];
@@ -821,29 +853,9 @@ static int config_output(AVFilterLink *outlink)
         if ((ret = ff_framesync_init_dualinput(&s->fs, ctx)) < 0)
             return ret;
 
-    for (plane = 0; plane < FF_ARRAY_ELEMS(s->params); plane++) {
-        FilterParams *param = &s->params[plane];
-
-        if (s->all_mode >= 0)
-            param->mode = s->all_mode;
-        if (s->all_opacity < 1)
-            param->opacity = s->all_opacity;
-
-        ff_blend_init(param, s->depth);
-
-        if (s->all_expr && !param->expr_str) {
-            param->expr_str = av_strdup(s->all_expr);
-            if (!param->expr_str)
-                return AVERROR(ENOMEM);
-        }
-        if (param->expr_str) {
-            ret = av_expr_parse(&param->e, param->expr_str, var_names,
-                                NULL, NULL, NULL, NULL, 0, ctx);
-            if (ret < 0)
-                return ret;
-            param->blend = s->depth > 8 ? s->depth > 16 ? blend_expr_32bit : blend_expr_16bit : blend_expr_8bit;
-        }
-    }
+    ret = config_params(ctx);
+    if (ret < 0)
+        return ret;
 
     if (s->tblend)
         return 0;
@@ -854,6 +866,18 @@ static int config_output(AVFilterLink *outlink)
     return ret;
 }
 
+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
+                           char *res, int res_len, int flags)
+{
+    int ret;
+
+    ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
+    if (ret < 0)
+        return ret;
+
+    return config_params(ctx);
+}
+
 #if CONFIG_BLEND_FILTER
 
 static int activate(AVFilterContext *ctx)
@@ -895,6 +919,7 @@ AVFilter ff_vf_blend = {
     .outputs       = blend_outputs,
     .priv_class    = &blend_class,
     .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
+    .process_command = process_command,
 };
 
 #endif
@@ -954,6 +979,7 @@ AVFilter ff_vf_tblend = {
     .inputs        = tblend_inputs,
     .outputs       = tblend_outputs,
     .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
+    .process_command = process_command,
 };
 
 #endif



More information about the ffmpeg-cvslog mailing list