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

Paul B Mahol git at videolan.org
Fri Dec 11 19:34:14 EET 2020


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Fri Dec 11 18:28:12 2020 +0100| [d76469378d44e17e974499f67248017b750f28bf] | committer: Paul B Mahol

avfilter/vf_convolution: add support for commands

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

 doc/filters.texi             | 16 +++++++++++
 libavfilter/vf_convolution.c | 66 +++++++++++++++++++++++++++++++-------------
 2 files changed, 63 insertions(+), 19 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index bd8bb85de3..c02a30ce8f 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -8544,6 +8544,10 @@ Set matrix mode for each plane. Can be @var{square}, @var{row} or @var{column}.
 Default is @var{square}.
 @end table
 
+ at subsection Commands
+
+This filter supports the all above options as @ref{commands}.
+
 @subsection Examples
 
 @itemize
@@ -15947,6 +15951,10 @@ Set value which will be multiplied with filtered result.
 Set value which will be added to filtered result.
 @end table
 
+ at subsection Commands
+
+This filter supports the all above options as @ref{commands}.
+
 @section pseudocolor
 
 Alter frame colors in video with pseudocolors.
@@ -16539,6 +16547,10 @@ Set value which will be multiplied with filtered result.
 Set value which will be added to filtered result.
 @end table
 
+ at subsection Commands
+
+This filter supports the all above options as @ref{commands}.
+
 @section rotate
 
 Rotate video by an arbitrary angle expressed in radians.
@@ -18125,6 +18137,10 @@ Set value which will be multiplied with filtered result.
 Set value which will be added to filtered result.
 @end table
 
+ at subsection Commands
+
+This filter supports the all above options as @ref{commands}.
+
 @anchor{spp}
 @section spp
 
diff --git a/libavfilter/vf_convolution.c b/libavfilter/vf_convolution.c
index 5909feaad1..3674f5b590 100644
--- a/libavfilter/vf_convolution.c
+++ b/libavfilter/vf_convolution.c
@@ -31,7 +31,7 @@
 #include "video.h"
 
 #define OFFSET(x) offsetof(ConvolutionContext, x)
-#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
 
 static const AVOption convolution_options[] = {
     { "0m", "set matrix for 1st plane", OFFSET(matrix_str[0]), AV_OPT_TYPE_STRING, {.str="0 0 0 0 1 0 0 0 0"}, 0, 0, FLAGS },
@@ -644,20 +644,25 @@ static av_cold int init(AVFilterContext *ctx)
             float sum = 0;
 
             p = s->matrix_str[i];
-            while (s->matrix_length[i] < 49) {
-                if (!(arg = av_strtok(p, " ", &saveptr)))
-                    break;
-
-                p = NULL;
-                sscanf(arg, "%d", &matrix[s->matrix_length[i]]);
-                sum += matrix[s->matrix_length[i]];
-                s->matrix_length[i]++;
+            if (p) {
+                s->matrix_length[i] = 0;
+
+                while (s->matrix_length[i] < 49) {
+                    if (!(arg = av_strtok(p, " |", &saveptr)))
+                        break;
+
+                    p = NULL;
+                    sscanf(arg, "%d", &matrix[s->matrix_length[i]]);
+                    sum += matrix[s->matrix_length[i]];
+                    s->matrix_length[i]++;
+                }
+
+                if (!(s->matrix_length[i] & 1)) {
+                    av_log(ctx, AV_LOG_ERROR, "number of matrix elements must be odd\n");
+                    return AVERROR(EINVAL);
+                }
             }
 
-            if (!(s->matrix_length[i] & 1)) {
-                av_log(ctx, AV_LOG_ERROR, "number of matrix elements must be odd\n");
-                return AVERROR(EINVAL);
-            }
             if (s->mode[i] == MATRIX_ROW) {
                 s->filter[i] = filter_row;
                 s->setup[i] = setup_row;
@@ -668,24 +673,31 @@ static av_cold int init(AVFilterContext *ctx)
                 s->size[i] = s->matrix_length[i];
             } else if (s->matrix_length[i] == 9) {
                 s->size[i] = 3;
-                if (!memcmp(matrix, same3x3, sizeof(same3x3)))
+
+                if (!memcmp(matrix, same3x3, sizeof(same3x3))) {
                     s->copy[i] = 1;
-                else
+                } else {
                     s->filter[i] = filter_3x3;
+                    s->copy[i] = 0;
+                }
                 s->setup[i] = setup_3x3;
             } else if (s->matrix_length[i] == 25) {
                 s->size[i] = 5;
-                if (!memcmp(matrix, same5x5, sizeof(same5x5)))
+                if (!memcmp(matrix, same5x5, sizeof(same5x5))) {
                     s->copy[i] = 1;
-                else
+                } else {
                     s->filter[i] = filter_5x5;
+                    s->copy[i] = 0;
+                }
                 s->setup[i] = setup_5x5;
             } else if (s->matrix_length[i] == 49) {
                 s->size[i] = 7;
-                if (!memcmp(matrix, same7x7, sizeof(same7x7)))
+                if (!memcmp(matrix, same7x7, sizeof(same7x7))) {
                     s->copy[i] = 1;
-                else
+                } else {
                     s->filter[i] = filter_7x7;
+                    s->copy[i] = 0;
+                }
                 s->setup[i] = setup_7x7;
             } else {
                 return AVERROR(EINVAL);
@@ -737,6 +749,18 @@ static av_cold int init(AVFilterContext *ctx)
     return 0;
 }
 
+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 init(ctx);
+}
+
 static const AVFilterPad convolution_inputs[] = {
     {
         .name         = "default",
@@ -767,6 +791,7 @@ AVFilter ff_vf_convolution = {
     .inputs        = convolution_inputs,
     .outputs       = convolution_outputs,
     .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
+    .process_command = process_command,
 };
 
 #endif /* CONFIG_CONVOLUTION_FILTER */
@@ -792,6 +817,7 @@ AVFilter ff_vf_prewitt = {
     .inputs        = convolution_inputs,
     .outputs       = convolution_outputs,
     .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
+    .process_command = process_command,
 };
 
 #endif /* CONFIG_PREWITT_FILTER */
@@ -817,6 +843,7 @@ AVFilter ff_vf_sobel = {
     .inputs        = convolution_inputs,
     .outputs       = convolution_outputs,
     .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
+    .process_command = process_command,
 };
 
 #endif /* CONFIG_SOBEL_FILTER */
@@ -842,6 +869,7 @@ AVFilter ff_vf_roberts = {
     .inputs        = convolution_inputs,
     .outputs       = convolution_outputs,
     .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
+    .process_command = process_command,
 };
 
 #endif /* CONFIG_ROBERTS_FILTER */



More information about the ffmpeg-cvslog mailing list