FFmpeg Concatenate Two Videos with Fade Transition

This article provides a straightforward guide on how to merge two video files with a seamless crossfade transition using FFmpeg. You will learn the exact command-line syntax, how the xfade filter works, and how to calculate the transition timing based on your video length.

To concatenate two videos with a fade transition, you must use FFmpeg’s xfade filter for the video stream and the acrossfade filter for the audio stream.

The FFmpeg Command

Here is the standard command template:

ffmpeg -i video1.mp4 -i video2.mp4 -filter_complex \
"[0:v][1:v]xfade=transition=fade:duration=1:offset=9[v]; \
 [0:a][1:a]acrossfade=d=1[a]" \
-map "[v]" -map "[a]" output.mp4

How to Calculate the Offset

The offset parameter determines exactly when the transition begins. To calculate the correct offset, use this formula:

\[\text{Offset} = \text{Duration of Video 1} - \text{Duration of Transition}\]

For example, if your first video is 10 seconds long and you want a 1-second fade transition: * Duration (\(D\)) = 10 * Transition Duration (\(T\)) = 1 * Offset (\(O\)) = \(10 - 1 = 9\) seconds.

Parameter Breakdown