FOLLOW US
4dots Software CODE HELP BLOG

How to make a zoom in, zoom out crossfade video transition with ffmpeg

To make a zoom in - zoom out video transition with ffmpeg, use the following code.

First, we make the zoom out video for the first image.

	
ffmpeg.exe -loop 1 -t effectDurationInSeconds  -r 25 -i firstImage -filter_complex
"[0:v]pad=w=1/0.1*iw:h=1/0.1*ih:x=(ow-iw/2):y=(oh-ih)/2,zoompan=z='(effectDurationInSeconds*25-on)*(1/0.1)
/(effectDurationInSeconds*25)':d=effectDurationInSeconds*25:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'
:s=imageWidthximageHeight[vo]" -map "[vo]" -y zoomout.mp4

effectDurationInSeconds : duration of the effect in seconds

imageWidth, imageHeight : image width and height.

Afterwards, we make the zoom in video for the second image.

	
ffmpeg.exe -r 25 -i secondImage -filter_complex
"[0:v]pad=w=1/0.1*iw:h=1/0.1*ih:x=(ow-iw/2):y=(oh-ih)/2,zoompan=z='on*(1/0.1)/(25*effectDurationInSeconds)'
:d=(25*effectDurationInSeconds):x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':s=imageWidthximageHeight[vo]"
-map "[vo]" -y zoomin.mp4

effectDurationInSeconds : duration of the effect in seconds

imageWidth, imageHeight : image width and height.

Lastly, we make use crossfade to make a crossfade zoom in, zoom out video transition.

	
ffmpeg.exe -i zoomout.mp4 -i zoomin.mp4
-filter_complex
"[0:v]fade=t=out:d=effectDurationInSeconds:alpha=1[v1];[1:v]fade=t=in:d=effectDurationInSeconds:alpha=1[v2];
[v1][v2]overlay,setsar=1[v];[2:v]setsar=1[v3];[v][v3]concat=n=2:v=1:a=0,setsar=1[out]" -map "[out]" -y outvideo.mp4

effectDurationInSeconds : duration of the effect in seconds