[FFmpeg-devel] [PATCH] lavfi: Add support to process_command in vf_eq.c
Michael Niedermayer
michaelni at gmx.at
Thu Feb 19 00:51:40 CET 2015
On Thu, Feb 19, 2015 at 02:33:43AM +0530, arwa arif wrote:
> 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.
[...]
> Extract color channel components from input video stream into
> diff --git a/libavfilter/vf_eq.c b/libavfilter/vf_eq.c
> index 5899abb..2b957d3 100644
> --- a/libavfilter/vf_eq.c
> +++ b/libavfilter/vf_eq.c
> @@ -106,14 +106,16 @@ static void check_values(EQParameters *param, EQContext *eq)
>
> static void set_contrast(EQContext *eq)
> {
> - eq->param[0].contrast = eq->contrast;
> + eq->var_values[VAR_CONTRAST] = av_clipf(av_strtod(eq->contrast_expr, NULL), -2.0, 2.0);
if you want to use AVExpr then all the av_strtod() should be
replaced by av_expr_eval()
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The real ebay dictionary, page 3
"Rare item" - "Common item with rare defect or maybe just a lie"
"Professional" - "'Toy' made in china, not functional except as doorstop"
"Experts will know" - "The seller hopes you are not an expert"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150219/54364e66/attachment.asc>
More information about the ffmpeg-devel
mailing list