5

FFMPEG document for zoompan https://ffmpeg.org/ffmpeg-filters.html#Examples-89 says

Zoom-in up to 1.5 and pan at same time to some spot near center of picture:

zoompan=z='min(zoom+0.0015,1.5)':d=700:x='if(gte(zoom,1.5),x,x+1/a)':y='if(gte(zoom,1.5),y,y+1)':s=640x360

Zoom-in up to 1.5 and pan always at center of picture:

zoompan=z='min(zoom+0.0015,1.5)':d=700:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'

i tried both the option but still not happy with zoom effect. I can see some shaking issue when it zooming.

Wondering whether there is any better way to achieve this. I want to zoom an image (16:9 ratio) to it centered position for some XX seconds and below is my same code

ffmpeg -r 25 -i image.png -filter_complex "zoompan=z='min(zoom+0.0032,5)':d=125:x='iw/1.7777-(iw/zoom/1.7777)':y='ih/1.7777-(ih/zoom/1.7777)'"  -shortest  -pix_fmt yuv420p -c:v libx264 image_output.mp4

Video File: http://sendvid.com/zn6oftiu

2
  • Image File: i.sstatic.net/LVjYi.jpg
    – Balajee
    Commented Jun 10, 2016 at 14:05
  • ffmpeg -r 25 -i LVjYi.jpg -filter_complex "scale=-6:6*ih,zoompan=z='min(zoom+0.0099,1.5)':d=125:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)',scale=-2:720" -y -shortest -c:v libx264 image_output.mp4 is working for me Commented Jul 21, 2017 at 10:52

2 Answers 2

4

I was having the same issue and got an answer that worked really well. The key is to first upscale the image prior to applying the zoom filter. You can downscale afterwards to the desired resolution.

The following scales up 10x, zooms to center, and then downscales back to 720p (the -2 x value in the scale filters maintains the aspect ratio, ie. scale=-2:10*ih). This pretty much eliminates the jiggle:

ffmpeg -r 25 -i LVjYi.jpg -filter_complex "scale=-2:10*ih,zoompan=z='min(zoom+0.0015,1.5)':d=125:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)',scale=-2:720"  -y -shortest -c:v libx264 image_output.mp4

Note that it seems the higher the initial upscale, the smoother the resulting zoom. Compare the above to an upscale of only 2x:

ffmpeg -r 25 -i LVjYi.jpg -filter_complex "scale=-2:2*ih,zoompan=z='min(zoom+0.0015,1.5)':d=125:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)',scale=-2:720"  -y -shortest -c:v libx264 image_output.mp4

That one is still jiggly.

0
0

Based on the answer of @Timbo White:

Here is the way to zoom out. That I found here. Unfortunately I do not know how to stop the loop of the zoom in zoom out. This is due to the if but I did take the time to search, without this one I think the zoom start from 1 and not from %maxzoom%(cf below).

A lot info are present in the docs - (not for zoom out).

Here a simple example in batch language: This is creating with a duration of 100

The difference are not so clear but you can see it (I think I should have choose other values for an example ...)

  • Example 1 zoom in and out
    • speed 0.02
    • maxzoom 2
  • Example 2 zoom in and out
    • speed 0.02
    • maxzoom 4
  • Example 3 zoom in and out
    • speed 0.04
    • maxzoom 4
set speed=0.02
set maxzoom=2
set /a out=1

:: Zoom in
ffmpeg -r 24 -i ff.png -filter_complex "scale=-2:%maxzoom%*ih,zoompan=z='min(zoom+%speed%,%maxzoom%)':d=100:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'",scale=-2:ih -y -shortest -c:v libx264 Zoom_in_%out%.mp4
:: Zoom out
ffmpeg -r 24 -i ff.png -filter_complex "scale=-2:%maxzoom%*ih,zoompan=z='if(lte(zoom, 1),%maxzoom%,max(zoom-%speed%,1))':d=100:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'",scale=-2:ih -y -shortest -c:v libx264 Zoom_out_%out%.mp4

:: -------------------------------------
set speed=0.02
set maxzoom=4
set /a out+=1

:: Zoom in
ffmpeg -r 24 -i ff.png -filter_complex "scale=-2:%maxzoom%*ih,zoompan=z='min(zoom+%speed%,%maxzoom%)':d=100:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'",scale=-2:ih -y -shortest -c:v libx264 Zoom_in_%out%.mp4
:: Zoom out
ffmpeg -r 24 -i ff.png -filter_complex "scale=-2:%maxzoom%*ih,zoompan=z='if(lte(zoom,1),%maxzoom%,max(1,zoom-%speed%))':d=100:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'",scale=-2:ih -y -shortest -c:v libx264 Zoom_out_%out%.mp4

:: -------------------------------------
set speed=0.04
set maxzoom=4
set /a out+=1

:: Zoom in
ffmpeg -r 24 -i ff.png -filter_complex "scale=-2:%maxzoom%*ih,zoompan=z='min(zoom+%speed%,%maxzoom%)':d=100:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'",scale=-2:ih -y -shortest -c:v libx264 Zoom_in_%out%.mp4
:: Zoom out
ffmpeg -r 24 -i ff.png -filter_complex "scale=-2:%maxzoom%*ih,zoompan=z='if(lte(zoom,1),%maxzoom%,max(1,zoom-%speed%))':d=100:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'",scale=-2:ih -y -shortest -c:v libx264 Zoom_out_%out%.mp4
  • Example 1 speed 0.02 maxzoom 2
    • Zoom IN
      • enter image description here
    • Zoom OUT
      • enter image description here
  • Example 2 speed 0.02 maxzoom 4
    • Zoom IN
      • enter image description here
    • Zoom OUT
      • enter image description here
  • Example 3 speed 0.04 maxzoom 4
    • Zoom IN
      • enter image description here
    • Zoom OUT
      • enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .