Log in

View Full Version : Resize + Pad to keep image centered


groucho86
25th September 2020, 23:34
I have a 1998x998 source that I need to "fit all" within a 1920x1080 container.

That means resizing 1998x998 to ~1920x959.04 and padding top and bottom to fill the height to 1080.

I'm currently scaling first to 1920x960 then padding top and bottom but then I'm not getting a perfect 1:1 compared to other softwares.

Ideally I'd like to preserve subpixel accuracy but I'm struggling with using src_top, src_height, etc.

Anyone know of a convenience function to resize & pad while keeping the image perfectly centered?

Selur
26th September 2020, 07:43
Anyone know of a convenience function to resize & pad while keeping the image perfectly centered?
No.
but then I'm not getting a perfect 1:1 compared to other softwares.
Does it look better to you if you first pad and then resize?
1998x998->1998x1124 (pad) -> 1920x1080 (resize)
that's the only different way that jumps to mind,..

Sharc
26th September 2020, 14:15
You could try the ffmpeg filter
-filter:v "scale=1920:-2, pad=1920:1080:(ow-iw)/2:(oh-ih)/2, setdar=16/9"
It keeps the AR within mod 2 and centers the picture.