[FFmpeg-devel] [Patch] Scale filter should use multiples of 2

Stefano Sabatini stefano.sabatini-lala
Thu Jul 1 01:40:55 CEST 2010


On date Wednesday 2010-06-30 13:21:03 -0400, Daniel G. Taylor encoded:
> On 06/29/2010 08:16 PM, Michael Niedermayer wrote:
> >On Wed, Jun 30, 2010 at 01:04:36AM +0200, Stefano Sabatini wrote:
> >>On date Tuesday 2010-06-29 12:56:17 -0700, Baptiste Coudurier encoded:
> >>>On 6/29/10 12:02 PM, Daniel G. Taylor wrote:
> >>>>Hey,
> >>>>
> >>>>Attached is a small patch to make the vf_scale filter always produce
> >>>>multiples of 2 when the -1 option is used for either width or height to
> >>>>keep the aspect ratio. This lets you use it properly with some encoders,
> >>>>like libx264, that would otherwise fail, e.g:
> >>>
> >>>This depends on the output pixel format. For 420, indeed it would be useful.
> >>
> >>Odd-size rescaling was a feature explicitely requested by Michael. I'm
> >>not against adding an option to make it only issues even-sized image though.
> >
> >I insisted possibly on it being supported (that is important)
> >but doing it by default with 420 seems odd
> 
> What about attached patch? It changes the behavior so that a width
> or height of -1 remains the same as it is now while adding the
> ability to use other negative values to mean "scale proportionately
> but clip to the closest multiple of X," so e.g.
> 
>     scale=320:-1  =>  320x197
>     scale=320:-2  =>  320x198
>     scale=320:-8  =>  320x200
>     scale=320:-16 =>  320x192
> 
> This can be useful for other codecs that wish to have dimensions as
> multiples of 2, 8, 16, etc. In the future we could even auto-insert
> a scaler to do this when needed by the chosen vcodec.
> 
> Thoughts? I tried to use FFALIGN but it seems to always round up.

> 
> Take care,
> -- 
> Daniel G. Taylor
> http://programmer-art.org/

> Index: libavfilter/vf_scale.c
> ===================================================================
> --- libavfilter/vf_scale.c	(revision 23891)
> +++ libavfilter/vf_scale.c	(working copy)
> @@ -33,7 +33,7 @@
>      /**
>       * New dimensions. Special values are:
>       *   0 = original width/height
> -     *  -1 = keep original aspect
> +     *  -x = keep original aspect and make mod-x, e.g. -16 for multiples of 16

Just a question, couldn't this be achieved using parametric values for
w:h?

I don't want to add code and complexity when all this may be
accomplished by a more general mechanism.

For example we may have a = w / h
w'/h' = a = w/h
h' = w' / a

scale=OUT_W:mod(OUT_W/a, 2)

Regards.
-- 
FFmpeg = Fiendish and Fostering Mean Purposeless Elastic Glue



More information about the ffmpeg-devel mailing list