FFmpeg xfade: How to Configure Duration and Offset

This article provides a straightforward guide on how to configure the transition duration and start offset using the xfade filter in FFmpeg. You will learn the exact syntax, how the timing parameters interact, and see practical command-line examples to seamlessly transition between two video inputs.

The xfade (crossfade) filter in FFmpeg merges two video streams using a specified transition effect. To control when the transition starts and how long it lasts, you must configure two key parameters: offset and duration.

Understanding the Parameters

The Timing Formula

To calculate the correct offset, you must know the duration of your first video. Because the transition overlaps both videos, the transition should begin before the first video ends.

Use this formula to calculate the offset: Offset = (Duration of Video 1) - (Transition Duration)

For example, if your first video is 10 seconds long and you want a 2-second fade transition, the transition must start at 8 seconds: 10 - 2 = 8 seconds

Command Syntax and Example

Here is the basic FFmpeg command to apply a fade transition between two videos using the calculated timing:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "[0:v][1:v]xfade=transition=fade:duration=2:offset=8[outv]" -map "[outv]" output.mp4

Command Breakdown