[FFmpeg-devel] [PATCH] lavfi/decimate: use named options

Clément Bœsch ubitux at gmail.com
Wed Feb 20 15:16:50 CET 2013


On Wed, Feb 20, 2013 at 03:03:12PM +0100, Stefano Sabatini wrote:
> TODO: bump micro
> ---
>  doc/filters.texi          |   23 +++++++++++++---------
>  libavfilter/vf_decimate.c |   48 ++++++++++++++++++++++++---------------------
>  2 files changed, 40 insertions(+), 31 deletions(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 43bfd9c..3be8363 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -2069,11 +2069,14 @@ for very-low-bitrate encoding (e.g. streaming over dialup modem), but
>  it could in theory be used for fixing movies that were
>  inverse-telecined incorrectly.
>  
> -It accepts the following parameters:
> - at var{max}:@var{hi}:@var{lo}:@var{frac}.
> +The filter accepts parameters as a list of @var{key}=@var{value}
> +pairs, separated by ":".  If the key of the first options is omitted,
> +the arguments are interpreted according to the syntax:
> + at option{max}:@option{hi}:@option{lo}:@option{frac}.
>  

Isn't this "@option{max}[:@option{hi}[:@option{lo}[:@option{frac}]]]"?

Note: we definitely need a common documentation template for all of them.

> - at table @option
> +A description of the accepted options follows.
>  
> + at table @option
>  @item max
>  Set the maximum number of consecutive frames which can be dropped (if
>  positive), or the minimum interval between dropped frames (if
> @@ -2082,20 +2085,22 @@ number of previous sequentially dropped frames.
>  
>  Default value is 0.
>  
> - at item hi, lo, frac
> + at item hi
> + at item lo
> + at item frac
>  Set the dropping threshold values.
>  
> -Values for @var{hi} and @var{lo} are for 8x8 pixel blocks and
> +Values for @option{hi} and @option{lo} are for 8x8 pixel blocks and
>  represent actual pixel value differences, so a threshold of 64
>  corresponds to 1 unit of difference for each pixel, or the same spread
>  out differently over the block.
>  
>  A frame is a candidate for dropping if no 8x8 blocks differ by more
> -than a threshold of @var{hi}, and if no more than @var{frac} blocks (1
> -meaning the whole image) differ by more than a threshold of @var{lo}.
> +than a threshold of @option{hi}, and if no more than @option{frac} blocks (1
> +meaning the whole image) differ by more than a threshold of @option{lo}.
>  
> -Default value for @var{hi} is 64*12, default value for @var{lo} is
> -64*5, and default value for @var{frac} is 0.33.
> +Default value for @option{hi} is 64*12, default value for @option{lo} is
> +64*5, and default value for @option{frac} is 0.33.
>  @end table
>  
>  @section delogo
> diff --git a/libavfilter/vf_decimate.c b/libavfilter/vf_decimate.c
> index 0d89b81..4982f79 100644
> --- a/libavfilter/vf_decimate.c
> +++ b/libavfilter/vf_decimate.c
> @@ -24,6 +24,7 @@
>   * Rich Felker.
>   */
>  
> +#include "libavutil/opt.h"
>  #include "libavutil/pixdesc.h"
>  #include "libavutil/timestamp.h"
>  #include "libavcodec/dsputil.h"
> @@ -33,6 +34,7 @@
>  #include "video.h"
>  
>  typedef struct {
> +    const AVClass *class;
>      int lo, hi;                    ///< lower and higher threshold number of differences
>                                     ///< values for 8x8 blocks
>  
> @@ -50,6 +52,20 @@ typedef struct {
>      AVCodecContext *avctx;         ///< codec context required for the DSPContext
>  } DecimateContext;
>  
> +#define OFFSET(x) offsetof(DecimateContext, x)
> +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
> +
> +static const AVOption decimate_options[] = {
> +    { "max",  "set the maximum number of consecutive dropped frames (positive), or minimum interval between dropped frames (minimum)",
> +      OFFSET(max_drop_count), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS },
> +    { "hi",   "set high dropping threshold", OFFSET(hi), AV_OPT_TYPE_INT, {.i64=64*12}, INT_MIN, INT_MAX, FLAGS },
> +    { "lo",   "set low dropping threshold", OFFSET(lo), AV_OPT_TYPE_INT, {.i64=64*5}, INT_MIN, INT_MAX, FLAGS },
> +    { "frac", "set fraction dropping threshold",  OFFSET(frac), AV_OPT_TYPE_FLOAT, {.dbl=0.33}, 0, 1, FLAGS },
> +    { NULL },

nit+++: comma uneeded since nothing will be added after this one.

> +};
> +
> +AVFILTER_DEFINE_CLASS(decimate);
> +
>  /**
>   * Return 1 if the two planes are different, 0 otherwise.
>   */
> @@ -116,29 +132,14 @@ static int decimate_frame(AVFilterContext *ctx,
>  static av_cold int init(AVFilterContext *ctx, const char *args)
>  {
>      DecimateContext *decimate = ctx->priv;
> +    static const char *shorthand[] = { "max", "hi", "lo", "frac", NULL };
> +    int ret;
>  
> -    /* set default values */
> -    decimate->drop_count = decimate->max_drop_count = 0;
> -    decimate->lo = 64*5;
> -    decimate->hi = 64*12;
> -    decimate->frac = 0.33;
> -
> -    if (args) {
> -        char c1, c2, c3, c4;
> -        int n = sscanf(args, "%d%c%d%c%d%c%f%c",
> -                       &decimate->max_drop_count, &c1,
> -                       &decimate->hi, &c2, &decimate->lo, &c3,
> -                       &decimate->frac, &c4);
> -        if (n != 1 &&
> -            (n != 3 || c1 != ':') &&
> -            (n != 5 || c1 != ':' || c2 != ':') &&
> -            (n != 7 || c1 != ':' || c2 != ':' || c3 != ':')) {
> -            av_log(ctx, AV_LOG_ERROR,
> -                   "Invalid syntax for argument '%s': "
> -                   "must be in the form 'max:hi:lo:frac'\n", args);
> -            return AVERROR(EINVAL);
> -        }
> -    }
> +    decimate->class = &decimate_class;
> +    av_opt_set_defaults(decimate);
> +
> +    if ((ret = av_opt_set_from_string(decimate, args, shorthand, "=", ":")) < 0)
> +        return ret;
>  
>      av_log(ctx, AV_LOG_VERBOSE, "max_drop_count:%d hi:%d lo:%d frac:%f\n",
>             decimate->max_drop_count, decimate->hi, decimate->lo, decimate->frac);
> @@ -156,6 +157,7 @@ static av_cold void uninit(AVFilterContext *ctx)
>      DecimateContext *decimate = ctx->priv;
>      avfilter_unref_bufferp(&decimate->ref);
>      avcodec_close(decimate->avctx);
> +    av_opt_free(decimate);
>      av_freep(&decimate->avctx);
>  }
>  
> @@ -260,4 +262,6 @@ AVFilter avfilter_vf_decimate = {
>      .query_formats = query_formats,
>      .inputs        = decimate_inputs,
>      .outputs       = decimate_outputs,
> +

nit+++: not needed

> +    .priv_class    = &decimate_class,

LGTM anyway, thanks

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130220/f1900a79/attachment.asc>


More information about the ffmpeg-devel mailing list