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.mp4

Key Parameters Explained

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.mp4

In this command, acrossfade=d=1 creates a 1-second audio crossfade at the end of the first clip.