[FFmpeg-user] Zoom out/scale down dynamically

astian astian at e-nautia.com
Mon Sep 17 17:37:00 EEST 2018


Gyan:
> On Fri, Sep 14, 2018 at 9:29 AM astian <astian at e-nautia.com> wrote:
>
>> Well, I'm not sure what you mean. Pad doesn't seem very dynamic to
>> me, I know that it has an eval=frame option, but according to the
>> manual there is no frame-number variable that I could exploit.
>
> Pad the video beforehand, usually with a transparent colour, then use
> zoompan. Since your new frame is much larger, you can simulate a
> zoom-out of the image, since with the padding, your zoom value doesn't
> need to drop below 1.
>
> However, you can't output these frames of differing sizes, as ffmpeg
> will resize them to a fixed size prior to encoding. However, you can
> use them in overlay, where the transparent padding gets hidden and you
> get the effective result.

After RTFM carefully, noticing the size parameter on zoompan, and
experimenting a bit, I think I understand you (except for the part about
'differing sizes').  I can zoom out of a video of dimensions D_i up to a
ratio R < 1 by first padding each dimension to D_i/R and then choosing a
zoom value of 1 and setting the size to D_i, zoompan will crop/scale the
video appropriately.

For example, this should progressively zoom out the test video to 20% of
the original size.

s=800x600
r=25
t=10
minz=0.2
padr=$(bc <<<"scale=4; 1/$minz")
ffmpeg -f lavfi -i "testsrc=r=$r:s=$s" -filter_complex  \
       "[0:v] pad= w=$padr*iw : h=$padr*ih : x=(ow-iw)/2 : y=(oh-ih)/2,
              zoompan= z=$padr-($padr-1)*(on-2)/($r*$t-1) :
                       x=(iw-iw/zoom)/2 :
                       y=(ih-ih/zoom)/2 :
                       d=1 : s=$s : fps=$r [vo]"  \
       -map '[vo]' -t 10 -c:v libx264 -crf 22 -y foo.mkv

One issue I discovered with this method is that the more I need to zoom
out, the more I need to increase the size of the original video, which
makes ffmpeg slower.

Still, my original 'why' question remains.  Why not directly allowing
zoom ratios < 1?  Do I have to ask in ffmpeg-devel?

Thanks.


More information about the ffmpeg-user mailing list