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

Stefano Sabatini stefasab at gmail.com
Mon Aug 27 11:05:04 CEST 2012


On date Sunday 2012-08-26 18:51:46 +0200, Jérémy Tran encoded:
> 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;
> +}

This is duplicating code in init. Best thing would be to implement
"reinit=..." which takes the same arguments as init(), and reuses the
same code.

[...]
-- 
FFmpeg = Fierce Fantastic Miracolous Patchable Enhancing God


More information about the ffmpeg-devel mailing list