[FFmpeg-devel] [PATCH] lavfi/scale: accept named option, make parsing more robust

Michael Niedermayer michaelni at gmx.at
Sat Oct 6 17:21:39 CEST 2012


On Sat, Oct 06, 2012 at 12:39:40PM +0200, Stefano Sabatini wrote:
> Also update documentation accordingly.
> 
[...]
> diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
> index 49988bf..b7c5272 100644
> --- a/libavfilter/vf_scale.c
> +++ b/libavfilter/vf_scale.c
> @@ -67,6 +67,7 @@ enum var_name {
>  };
>  
>  typedef struct {
> +    const AVClass *class;
>      struct SwsContext *sws;     ///< software scaler context
>      struct SwsContext *isws[2]; ///< software scaler context for interlaced material
>  
> @@ -76,7 +77,8 @@ typedef struct {
>       *  -1 = keep original aspect
>       */
>      int w, h;
> -    unsigned int flags;         ///sws flags
> +    const char *flags_str;      ///sws flags string
> +    int         flags;          ///sws flags
>  
>      int hsub, vsub;             ///< chroma subsampling
>      int slice_y;                ///< top of current output slice
> @@ -84,35 +86,47 @@ typedef struct {
>      int output_is_pal;          ///< set to 1 if the output format is paletted
>      int interlaced;
>  
> -    char w_expr[256];           ///< width  expression string
> -    char h_expr[256];           ///< height expression string
> +    char *w_expr;           ///< width  expression string
> +    char *h_expr;           ///< height expression string
>  } ScaleContext;

i think this would break changing resolution support, see start_frame()


>  
> +#define OFFSET(x) offsetof(ScaleContext, x)
> +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
> +
> +static const AVOption scale_options[] = {
> +    { "w",      "set width expression",    OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, 0, 0, FLAGS },
> +    { "width",  "set width expression",    OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, 0, 0, FLAGS },
> +    { "h",      "set height expression",   OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, 0, 0, FLAGS },
> +    { "height", "set height expression",   OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, 0, 0, FLAGS },
> +    { "flags",  "set libswscale flags",    OFFSET(flags_str), AV_OPT_TYPE_STRING, {.str = "bilinear"}, 0, INT_MAX, FLAGS },
> +    { "interl", "set interlacing", OFFSET(interlaced), AV_OPT_TYPE_INT, {.i64 = 0 }, -1, 1, FLAGS },
> +    { NULL },
> +};
> +
> +AVFILTER_DEFINE_CLASS(scale);
> +
>  static av_cold int init(AVFilterContext *ctx, const char *args)
>  {
>      ScaleContext *scale = ctx->priv;
> -    const char *p;
> -
> -    av_strlcpy(scale->w_expr, "iw", sizeof(scale->w_expr));
> -    av_strlcpy(scale->h_expr, "ih", sizeof(scale->h_expr));
> -
> -    scale->flags = SWS_BILINEAR;
> -    if (args) {
> -        sscanf(args, "%255[^:]:%255[^:]", scale->w_expr, scale->h_expr);
> -        p = strstr(args,"flags=");
> -        if (p) {
> -            const AVClass *class = sws_get_class();
> -            const AVOption    *o = av_opt_find(&class, "sws_flags", NULL, 0,
> -                                               AV_OPT_SEARCH_FAKE_OBJ);
> -            int ret = av_opt_eval_flags(&class, o, p + 6, &scale->flags);
> -
> -            if (ret < 0)
> -                return ret;
> -        }
> -        if(strstr(args,"interl=1")){
> -            scale->interlaced=1;
> -        }else if(strstr(args,"interl=-1"))
> -            scale->interlaced=-1;
> +    const char *shorthand[] = { "w", "h" };

missing static and missing null termination

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Old school: Use the lowest level language in which you can solve the problem
            conveniently.
New school: Use the highest level language in which the latest supercomputer
            can solve the problem without the user falling asleep waiting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121006/47cdb129/attachment.asc>


More information about the ffmpeg-devel mailing list