FOLLOW US
4dots Software CODE HELP BLOG

How to make crossfade video transition effect with ffmpeg

To make a crossfade video transition effect with ffmpeg use the following code :

	
ffmpeg.exe -loop 1 -t effectDurationInSeconds -i firstImage.jpg -loop 1 -t effectDurationInSeconds -i secondImage.jpg 
-filter_complex "color=c=black:r=60:size=imageWidthximageHeight:d=effectDurationInSeconds[black];[0:v]format=pix_fmts=yuva420p
,fade=t=out:st=effectDurationInSeconds:d=3:alpha=1,scale=imageWidthximageHeight,setpts=PTS-STARTPTS[v0];
[1:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=effectDurationInSeconds:alpha=1,scale=imageWidthximageHeight
,setpts=PTS-STARTPTS+4/TB[v1];[black][v0]overlay[over1];[over1][v1]overlay=format=yuv420[outv]" -map "[outv]" outvideo.mp4

effectDurationInSeconds : how long the fade in and fade out should last in seconds.

imageWidth, imageHeight : image width and height.