[FFmpeg-devel] [PATCH] lavfi/hue: add process_command callback

Jérémy Tran tran.jeremy.av at gmail.com
Sun Aug 26 18:51:46 CEST 2012


This allows dynamic reconfiguration of the filter
---
 libavfilter/vf_hue.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/libavfilter/vf_hue.c b/libavfilter/vf_hue.c
index cf1fe5f..03a8dd8 100644
--- a/libavfilter/vf_hue.c
+++ b/libavfilter/vf_hue.c
@@ -26,6 +26,7 @@
  */
 
 #include <float.h>
+#include "libavutil/eval.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
@@ -223,6 +224,39 @@ static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
     return ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
 }
 
+static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
+{
+    HueContext *hue = ctx->priv;
+    double new_val;
+    const double var_values[] = { 0 };
+    const char *var_names[] = { NULL };
+
+    if (av_expr_parse_and_eval(&new_val, arg,
+                               var_names, var_values,
+                               NULL, NULL, NULL, NULL, NULL, 0, hue) < 0)
+        return AVERROR(EINVAL);
+
+    if (!strcmp(cmd, "s")) {
+        if (new_val < -10 || new_val > -10) {
+            av_log(ctx, AV_LOG_ERROR,
+                   "Invalid value for saturation %0.1f: "
+                   "must be included between range -10 and +10\n", new_val);
+            return AVERROR(EINVAL);
+        }
+        hue->saturation = new_val;
+    } else if (!strcmp(cmd, "h")) {
+        hue->hue = new_val * M_PI / 180;
+    } else if (!strcmp(cmd, "H")) {
+        hue->hue = new_val;
+    } else
+        return AVERROR(ENOSYS);
+
+    hue->hue_sin = rint(sin(hue->hue) * (1 << 16) * hue->saturation);
+    hue->hue_cos = rint(cos(hue->hue) * (1 << 16) * hue->saturation);
+
+    return 0;
+}
+
 AVFilter avfilter_vf_hue = {
     .name        = "hue",
     .description = NULL_IF_CONFIG_SMALL("Adjust the hue and saturation of the input video."),
@@ -232,6 +266,7 @@ AVFilter avfilter_vf_hue = {
     .init          = init,
     .uninit        = uninit,
     .query_formats = query_formats,
+    .process_command = command,
 
     .inputs = (const AVFilterPad[]) {
         {
-- 
1.7.11.3



More information about the ffmpeg-devel mailing list