SebSob
SebSob

Reputation: 582

FFmpeg zoom not smooth-centered (but zigzag)

I try to perform a basic zoompan with FFmpeg. I have an input image (.png 1280x720) and i create an 8 seconds video (.mp4 320x180) from it, with a zoom. This is my command:

ffmpeg -loop 1 -i in_img.png -c:v libx264 -pix_fmt yuv420p -strict experimental -framerate 25 -vf zoompan=z='min(zoom+0.011835363,2.1835363)':d=375:x=400:y=247 -s 320x180 -t 00:00:08.882 out_vid.mp4

Everything works...but the zoom is not looking okay. It is going zig-zag.

Does anyone know how to make it zoom smooth, like centered? (And not first left then right)

Thanks

EDIT


I've come a small step closer to a solution by slightly modifying the 'x' and 'y' in the -vf filter (rest of the command is the same as above):

-vf zoompan=z='min(zoom+0.022,3.25)':d=375:x='if(gte(zoom,3.25),x,x+8.24)':y='if(gte(zoom,3.25),y,y+4.72)':s=1280x720

I incement x and y every frame (for x +8.24, for y +4.72, i know those values because i know how many frames it takes get to the end-zoom state) so that it will move to its end zoom state coordinate (1011,582), see image:

Zoom Visualization This is the video of the result, as you can see it does not do the zig-zag effect, but now it looks like its going first to the center and then to the zoomed result. Or is that only an illusion?? Any idea's?

Upvotes: 4

Views: 2935

Answers (1)

Gyan
Gyan

Reputation: 93068

To zoom from zoom level 1 (1280x720) to zoom level 5 (256x144) and pan to bottom right, with final position (1011,568) in 125 frames, and output video as 320x180, use

-vf zoompan=z='min(zoom+0.0320,5)':d=125:x='(iw-(iw/zoom))*(1011/1024)': \
                                         y='(ih-(ih/zoom))*(568/576)',scale=320x180

where 0.0320 is division of (final zoom - initial zoom) / frames to zoom in, 1024 is input width - final width and 576 is input height - final height

FFmpeg doesn't seem to smooth out the interpolation, so fine zoom and pans will be jittery.

Upvotes: 1

Related Questions