[FFmpeg-devel] [PATCH] Fix odd width or height from scaling filter expression

Michael Niedermayer michaelni at gmx.at
Mon Aug 20 18:44:21 CEST 2012


On Mon, Aug 20, 2012 at 02:44:21PM +0200, Jeroen Ost wrote:
> Hi,
> 
> The attached patch fixes the issue that the scaling filter, when used
> with an expression like
> scale=iw*sar:ih (to correct non-square pixels), can lead to odd width or height.
> Example: 720x576 [SAR 12:11] and scale=iw*sar:ih
> before patch: 785x576
> after patch: 786x576
> 
> It causes a vf_pad filter further in the filter chain to abort because
> of the odd video size. I suspect codecs and players don't like odd
> dimensions either.
> 
> Jeroen Ost

>  vf_scale.c |    8 ++++++++
>  1 file changed, 8 insertions(+)
> d1c032ffe539d484c23f3104bbf6c943e1f1886c  0001-Fix-odd-width-or-height-after-scaling-causes-issues-.patch
> From b2254fdabaf673722cb4f5592c5f5a5be2ebe94d Mon Sep 17 00:00:00 2001
> From: Jeroen Ost <jeroen.ost at gmail.com>
> Date: Mon, 20 Aug 2012 14:17:55 +0200
> Subject: [PATCH] Fix odd width or height after scaling causes issues in
>  filters like vf_pad
> 
> ---
>  libavfilter/vf_scale.c |    8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
> index eda1b1f..39454c6 100644
> --- a/libavfilter/vf_scale.c
> +++ b/libavfilter/vf_scale.c
> @@ -221,6 +221,14 @@ static int config_props(AVFilterLink *outlink)
>          (w * inlink->h) > INT_MAX)
>          av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
>  
> +    // SAR values like 16:11 or 12:11 can lead to odd width or height - avoid problems with filters like vf_pad
> +    if (w % 2 == 1) {
> +    	w++;
> +    }
> +    if (h % 2 == 1) {
> +    	h++;
> +    }
> +

the scaler works with more than 4:2:0, 2 is just correct for 4:2:0
saftey checks are done before and the ++ can make them fail
it also would break intentional rescaling to a odd dimension, like
scale=101:103
Given that, i think such rounding if done, should be optional

also tabs are forbidden in ffmpeg git

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Awnsering whenever a program halts or runs forever is
On a turing machine, in general impossible (turings halting problem).
On any real computer, always possible as a real computer has a finite number
of states N, and will either halt in less than N cycles or never halt.
-------------- 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/20120820/1ed647b2/attachment.asc>


More information about the ffmpeg-devel mailing list