[FFmpeg-devel] [PATCH] lavfi: Add support to process_command in vf_eq.c

arwa arif arwaarif1994 at gmail.com
Wed Feb 18 22:03:43 CET 2015


On Sat, Jan 31, 2015 at 3:55 PM, Stefano Sabatini <stefasab at gmail.com>
wrote:

> On date Friday 2015-01-30 23:17:33 +0530, Arwa Arif encoded:
> > I have tried to add process_command in vf_eq.c. I have attached the
> patch.
>
> > From 1d65e493a8eb247d86b0db324cb740579662706d Mon Sep 17 00:00:00 2001
> > From: Arwa Arif <arwaarif1994 at gmail.com>
> > Date: Fri, 30 Jan 2015 23:06:50 +0530
> > Subject: [PATCH] Add support to process_command in vf_eq.c
> >
> > ---
> >  libavfilter/vf_eq.c |   53
> ++++++++++++++++++++++++++++++++++++++-------------
> >  1 file changed, 40 insertions(+), 13 deletions(-)
>
> Missing doc updates.
>
> >
> > diff --git a/libavfilter/vf_eq.c b/libavfilter/vf_eq.c
> > index ad2a37e..5899abb 100644
> > --- a/libavfilter/vf_eq.c
> > +++ b/libavfilter/vf_eq.c
> > @@ -27,11 +27,6 @@
> >   * very simple video equalizer
> >   */
> >
> > -/**
> > - * TODO:
> > - * - Add support to process_command
> > - */
> > -
> >  #include "libavfilter/internal.h"
> >  #include "libavutil/common.h"
> >  #include "libavutil/imgutils.h"
> > @@ -217,6 +212,37 @@ static int filter_frame(AVFilterLink *inlink,
> AVFrame *in)
> >      av_frame_free(&in);
> >      return ff_filter_frame(outlink, out);
> >  }
> > +
> > +static int process_command(AVFilterContext *ctx, const char *cmd, const
> char *args,
> > +                           char *res, int res_len, int flags)
> > +{
> > +    EQContext *eq = ctx->priv;
> > +
> > +    if (!strcmp(cmd, "contrast"))
>
> > +        eq->contrast     = av_clipf(strtod(args, NULL), -2.0,  2.0);
>
> All this parameters are set through the av_opt_ interface. Try to use
> it, since otherwise range checks and parsing is inconsistent. In
> particular, the parsing performed by av_opt_ may be different from
> strtod(). Also you want to want the user in case of out-of-range values.
>
> > +    if (!strcmp(cmd, "brightness"))
> > +        eq->brightness   = av_clipf(strtod(args, NULL), -1.0,  1.0);
> > +    if (!strcmp(cmd, "saturation"))
> > +        eq->saturation   = av_clipf(strtod(args, NULL),  0.0,  3.0);
> > +    if (!strcmp(cmd, "gamma"))
> > +        eq->gamma        = av_clipf(strtod(args, NULL),  0.1, 10.0);
> > +    if (!strcmp(cmd, "gamma_r"))
> > +        eq->gamma_r      = av_clipf(strtod(args, NULL),  0.1, 10.0);
> > +    if (!strcmp(cmd, "gamma_g"))
> > +        eq->gamma_g      = av_clipf(strtod(args, NULL),  0.1, 10.0);
> > +    if (!strcmp(cmd, "gamma_b"))
> > +        eq->gamma_b      = av_clipf(strtod(args, NULL),  0.1, 10.0);
> > +    if (!strcmp(cmd, "gamma_weight"))
> > +        eq->gamma_weight = av_clipf(strtod(args, NULL),  0.0,  1.0);
> > +
> > +    set_gamma(eq);
> > +    set_contrast(eq);
> > +    set_brightness(eq);
> > +    set_saturation(eq);
> > +
> > +    return 0;
> > +}
>
> if (!strcmp(cmd, "contrast) {
>    set contrast
>    set_contrast(eq);
> } else if (...)
>
> } else...
>
> This wauy you don't need to set the other parameters if they are not
> changed.
>
>
> Also it should return AVERROR(ENOSYS) in case of unrecognized command.
>
> > +
> >  static const AVFilterPad eq_inputs[] = {
> >      {
> >          .name = "default",
> > @@ -260,12 +286,13 @@ static const AVOption eq_options[] = {
> >  AVFILTER_DEFINE_CLASS(eq);
> >
> >  AVFilter ff_vf_eq = {
> > -    .name          = "eq",
> > -    .description   = NULL_IF_CONFIG_SMALL("Adjust brightness, contrast,
> gamma, and saturation."),
> > -    .priv_size     = sizeof(EQContext),
> > -    .priv_class    = &eq_class,
> > -    .inputs        = eq_inputs,
> > -    .outputs       = eq_outputs,
> > -    .query_formats = query_formats,
> > -    .init          = initialize,
>
> > +    .name            = "eq",
> > +    .description     = NULL_IF_CONFIG_SMALL("Adjust brightness,
> contrast, gamma, and saturation."),
> > +    .priv_size       = sizeof(EQContext),
> > +    .priv_class      = &eq_class,
> > +    .inputs          = eq_inputs,
> > +    .outputs         = eq_outputs,
> > +    .process_command = process_command,
> > +    .query_formats   = query_formats,
> > +    .init            = initialize,
>
> avoid cosmetic changes, you can vertically realign in a separate
> (cosmetical) commit.
> --
> FFmpeg = Fostering Faithless Mournful Puristic Ecletic Generator
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


I have looked at various codes which use process_command and tried to
update the patch accordingly.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-process_command-to-eq.patch
Type: text/x-patch
Size: 12811 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150219/7589013c/attachment.bin>


More information about the ffmpeg-devel mailing list