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

Stefano Sabatini stefasab at gmail.com
Mon Oct 15 09:46:52 CEST 2012


On date Saturday 2012-10-06 17:21:39 +0200, Michael Niedermayer encoded:
> 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

Fixed.

Patch updated.
-- 
FFmpeg = Freak and Fostering MultiPurpose Exciting Guru
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-lavfi-scale-accept-named-option-make-parsing-more-ro.patch
Type: text/x-diff
Size: 7899 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121015/461ec29b/attachment.bin>


More information about the ffmpeg-devel mailing list