[FFmpeg-devel] [PATCH] lavfi: port decimate libmpcodecs filter

Stefano Sabatini stefasab at gmail.com
Mon Aug 27 13:42:25 CEST 2012


On date Tuesday 2012-08-21 11:24:06 +0200, Nicolas George encoded:
> Le tridi 3 fructidor, an CCXX, Stefano Sabatini a écrit :
> > > Maybe store it as an integer? That would help making the filter bit-exact.
> > Please elaborate, also I'd like to keep compatibility with mp=decimate.
> 
> My suggestion would be to have "unsigned frac", with default value
> 1431655765 ((1<<32)/3) or 1417339208 ((1<<32)*0.33) and replace the
> following code 
> 
> > +    int t = (w/16)*(h/16)*decimate->frac;
> 
> by:
> 
> int t = av_rescale((w/16)*(h/16), decimate->frac, 0x100000000);
> 
> In other words: frac_as_a_float = frac_as_an_unsigned / (float)(1 << 32),
> but avoiding all floating-point arithmetic.

Are you suggesting to change the filter to accept an int rather than a
float? That would break compatibility with the previous filter.
 
> Since (w/16)*(h/16) should be way smaller than 1<<32 (if av_image_check_size
> did its work, (w/16)*(h/16) < 1<<20), it will be accurate enough. And
> without floating-point arithmetic, we can be sure the computation is
> bit-exact across architectures and add FATE tests.
> 
> The /16 look very strange, though, as x and y are incremented by steps of 4.
> 
> > +        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);
> 
> This test look very clumsy, but I guess it comes from the original code.

Alternatively, we add an option taking an int, as alternative to the
current option. Ideally we should also add named option support, once
we have support for shorthand so we don't need clumsy wrapper for
keeping backward compatibility.
[...]

Patch updated, now making use of dsputil.
-- 
FFmpeg = Furious & Faithful Multimedia Purposeless Extensive Game
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-lavfi-port-decimate-libmpcodecs-filter.patch
Type: text/x-diff
Size: 14644 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120827/103cca47/attachment.bin>


More information about the ffmpeg-devel mailing list