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

Paul B Mahol git at videolan.org
Fri Dec 25 17:43:54 EET 2020


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Fri Dec 25 16:41:44 2020 +0100| [5b48d2af43861d7cd84f52ed6f949449c652076d] | committer: Paul B Mahol

avfilter/vf_xmedian: add support for commands

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

 doc/filters.texi         |  8 ++++++++
 libavfilter/vf_xmedian.c | 29 +++++++++++++++++++++++++----
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index d6a53624ee..f71d33c602 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -19315,6 +19315,10 @@ Default value of @code{0.5} will pick always median values, while @code{0} will
 minimum values, and @code{1} maximum values.
 @end table
 
+ at subsection Commands
+
+This filter supports all above options as @ref{commands}, excluding option @code{radius}.
+
 @section tmix
 
 Mix successive video frames.
@@ -21259,6 +21263,10 @@ Default value of @code{0.5} will pick always median values, while @code{0} will
 minimum values, and @code{1} maximum values.
 @end table
 
+ at subsection Commands
+
+This filter supports all above options as @ref{commands}, excluding option @code{inputs}.
+
 @section xstack
 Stack video inputs into custom layout.
 
diff --git a/libavfilter/vf_xmedian.c b/libavfilter/vf_xmedian.c
index 15857d6f14..0c4d4ab047 100644
--- a/libavfilter/vf_xmedian.c
+++ b/libavfilter/vf_xmedian.c
@@ -344,13 +344,32 @@ static int activate(AVFilterContext *ctx)
     return ff_framesync_activate(&s->fs);
 }
 
+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
+                           char *res, int res_len, int flags)
+{
+    XMedianContext *s = ctx->priv;
+    int ret;
+
+    ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
+    if (ret < 0)
+        return ret;
+
+    if (s->nb_inputs & 1)
+        s->index = s->radius * 2.f * s->percentile;
+    else
+        s->index = av_clip(s->radius * 2.f * s->percentile, 1, s->nb_inputs - 1);
+
+    return 0;
+}
+
 #define OFFSET(x) offsetof(XMedianContext, x)
 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
+#define TFLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
 
 static const AVOption xmedian_options[] = {
     { "inputs", "set number of inputs", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64=3},  3, 255, .flags = FLAGS },
-    { "planes", "set planes to filter", OFFSET(planes),    AV_OPT_TYPE_INT, {.i64=15}, 0,  15, .flags = FLAGS },
-    { "percentile", "set percentile",   OFFSET(percentile),AV_OPT_TYPE_FLOAT,{.dbl=0.5}, 0, 1, .flags = FLAGS },
+    { "planes", "set planes to filter", OFFSET(planes),    AV_OPT_TYPE_INT, {.i64=15}, 0,  15, .flags =TFLAGS },
+    { "percentile", "set percentile",   OFFSET(percentile),AV_OPT_TYPE_FLOAT,{.dbl=0.5}, 0, 1, .flags =TFLAGS },
     { NULL },
 };
 
@@ -377,6 +396,7 @@ AVFilter ff_vf_xmedian = {
     .uninit        = uninit,
     .activate      = activate,
     .flags         = AVFILTER_FLAG_DYNAMIC_INPUTS | AVFILTER_FLAG_SLICE_THREADS,
+    .process_command = process_command,
 };
 
 #endif /* CONFIG_XMEDIAN_FILTER */
@@ -422,8 +442,8 @@ static int tmedian_filter_frame(AVFilterLink *inlink, AVFrame *in)
 
 static const AVOption tmedian_options[] = {
     { "radius",     "set median filter radius", OFFSET(radius),     AV_OPT_TYPE_INT,   {.i64=1},   1, 127, .flags = FLAGS },
-    { "planes",     "set planes to filter",     OFFSET(planes),     AV_OPT_TYPE_INT,   {.i64=15},  0,  15, .flags = FLAGS },
-    { "percentile", "set percentile",           OFFSET(percentile), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0,   1, .flags = FLAGS },
+    { "planes",     "set planes to filter",     OFFSET(planes),     AV_OPT_TYPE_INT,   {.i64=15},  0,  15, .flags =TFLAGS },
+    { "percentile", "set percentile",           OFFSET(percentile), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0,   1, .flags =TFLAGS },
     { NULL },
 };
 
@@ -458,6 +478,7 @@ AVFilter ff_vf_tmedian = {
     .init          = init,
     .uninit        = uninit,
     .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
+    .process_command = process_command,
 };
 
 #endif /* CONFIG_TMEDIAN_FILTER */



More information about the ffmpeg-cvslog mailing list