How to Use the FFmpeg xfade Wipe Transition
This guide provides a straightforward tutorial on how to use the
xfade (crossfade) filter in FFmpeg to apply a wipe
transition between two video files. You will learn the exact
command-line syntax, how to configure transition directions such as
left, right, up, or down, and how to calculate the correct timing
parameters for a seamless edit.
The Basic Command Syntax
The xfade filter requires two video inputs, a specified
transition type, the start time (offset), and the
transition length (duration).
In FFmpeg, the wipe transition is split into four directional
options: wipeleft, wiperight,
wipeup, and wipedown.
Here is the standard command to apply a horizontal left-to-right wipe transition:
ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "[0:v][1:v]xfade=transition=wiperight:duration=1:offset=9[outv]" -map "[outv]" output.mp4Key Parameters Explained
[0:v][1:v]: This tells FFmpeg to take the video streams of the first input (0) and the second input (1) and pass them to thexfadefilter.transition=wiperight: Specifies the type of transition. You can change this towipeleft,wipeup, orwipedown.duration=1: The duration of the transition effect in seconds. In this case, the wipe will take exactly 1 second to complete.offset=9: The timestamp (in seconds) in the first video where the transition starts.
Calculating the Offset
To prevent the video from freezing or clipping, you must calculate
the offset based on the duration of your first video. The
formula is:
\[\text{Offset} = \text{Duration of Input 1} - \text{Transition Duration}\]
For example, if your first video (input1.mp4) is exactly
10 seconds long, and you want a 1-second wipe transition, your offset
must be 9 seconds (\(10 - 1 =
9\)).
Handling Audio (Optional)
The xfade filter only processes video streams. If your
videos have audio and you want the audio to fade simultaneously, you
must use the acrossfade filter in combination with
xfade:
ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex \
"[0:v][1:v]xfade=transition=wiperight:duration=1:offset=9[outv]; \
[0:a][1:a]acrossfade=d=1[outa]" \
-map "[outv]" -map "[outa]" output.mp4In this command, acrossfade=d=1 creates a 1-second audio
crossfade at the end of the first clip.