Search code examples
videoffmpegconcatenation

Adding cross fade between concatenated videos


I'm using the following command to concat multiple videos together:

ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mp4 -f lavfi -t 0.1 -i anullsrc -filter_complex "[0:v]scale=3840:2160:force_original_aspect_ratio=decrease,pad=3840:2160:-1:-1,setsar=1,fps=30,format=yuv420p[v0]; [1:v]scale=3840:2160:force_original_aspect_ratio=decrease,pad=3840:2160:-1:-1,setsar=1,fps=30,format=yuv420p[v1]; [2:v]scale=3840:2160:force_original_aspect_ratio=decrease,pad=3840:2160:-1:-1,setsar=1,fps=30,format=yuv420p[v2]; [v0][3:a][v1][3:a][v2][3:a]concat=n=3:v=1:a=1[v][a]" -map "[v]" -map "[a]" -c:v libx264 -c:a aac -movflags +faststart output3.mp4

How can I modify my command so that I can include cross fade transition between each video? Notice I need a constant duration of fade between all the videos, no need special effect between two videos. Also I don't care about audio, only care about the transitions between videos.

Is there a generic way that I don't need to specify the exact time when to start the next transition? Like saying between each video do cross fade transition.


Solution

  • Try this

    ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mp4 -filter_complex 
      "[0:v]scale=3840:2160:force_original_aspect_ratio=decrease,pad=3840:2160:-1:-1,setsar=1,fps=30,format=yuv420p[v0]; 
       [1:v]scale=3840:2160:force_original_aspect_ratio=decrease,pad=3840:2160:-1:-1,setsar=1,fps=30,format=yuv420p[v1]; 
       [2:v]scale=3840:2160:force_original_aspect_ratio=decrease,pad=3840:2160:-1:-1,setsar=1,fps=30,format=yuv420p[v2]; 
       [v0][v1]xfade[v01];
       [v01][v2]xfade[v]" 
       -map "[v]" -c:v libx264 -movflags +faststart output3.mp4