How to Use Wipe Transitions in FFmpeg xfade

This guide explains how to apply wipe transitions between two video clips using FFmpeg's built-in xfade filter. You will learn the correct command syntax, how to calculate the transition timing offset, explore the different directional wipe options available, and handle corresponding audio transitions cleanly.

Understanding the xfade Wipe Syntax

The xfade (crossfade) filter accepts two video inputs and merges them using a chosen transition effect. To make a transition work properly, you must define three core parameters:

  • transition: The visual effect to apply (e.g., wipeleft, wiperight).
  • duration: The length of the transition in seconds.
  • offset: The exact timestamp (in seconds) in the first video where the transition begins.

The offset is calculated using the formula:
offset = duration_of_first_video - transition_duration

For example, if your first video is 5 seconds long and you want a 1-second wipe transition, your offset is 4 (5 - 1 = 4).

Basic Command Example

To perform a left-to-right wipe between input1.mp4 (5 seconds long) and input2.mp4 with a 1-second duration, run:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "[0:v][1:v]xfade=transition=wiperight:duration=1:offset=4[v]" -map "[v]" output.mp4

Available Wipe Directions

FFmpeg supports several wipe variations in the xfade filter depending on the direction you want the incoming video to travel:

  • wipeleft: Wipes from right to left.
  • wiperight: Wipes from left to right.
  • wipeup: Wipes from bottom to top.
  • wipedown: Wipes from top to bottom.
  • wipetl: Diagonal wipe towards the top-left corner.
  • wipetr: Diagonal wipe towards the top-right corner.
  • wipebl: Diagonal wipe towards the bottom-left corner.
  • wipebr: Diagonal wipe towards the bottom-right corner.

To change the direction, simply replace the value in transition=. For instance, use transition=wipedown for a downward vertical wipe.

Synchronizing Video and Audio

The xfade filter only processes video streams. To prevent the audio from abruptly cutting or getting out of sync, combine xfade with the acrossfade filter for audio:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex \
"[0:v][1:v]xfade=transition=wipeleft:duration=1:offset=4[v]; \
 [0:a][1:a]acrossfade=d=1[a]" \
-map "[v]" -map "[a]" output.mp4

In this command, acrossfade=d=1 crossfades the audio streams for 1 second at the same point the video wipe occurs, creating a seamless transition for both video and audio. Ensure both inputs share the same resolution, frame rate, and time base before applying the filter to prevent rendering artifacts.