Configure FFmpeg acrossfade Transition Duration

Audio crossfading is a crucial technique for creating smooth transitions between two audio tracks. This guide explains how to use the FFmpeg acrossfade filter, specifically focusing on how to configure the transition duration and curve shapes to achieve professional-sounding audio transitions.

The Basic Syntax for Transition Duration

To set the transition duration in the acrossfade filter, you use the duration (or shorthand d) option. This value is specified in seconds.

The basic syntax for blending two audio inputs with a specific crossfade duration is:

ffmpeg -i input1.mp3 -i input2.mp3 -filter_complex "acrossfade=d=5" output.mp3

In this example, d=5 configures a 5-second transition duration where the end of the first file fades out while the beginning of the second file fades in simultaneously.

Key Parameters for Controlling the Transition

While duration is the primary setting, the acrossfade filter offers other parameters that directly affect how that duration behaves:

  • duration (or d): Sets the duration of the crossfade in seconds. The default value is 2 seconds.
  • overlap (or o): A boolean option (1 or 0) that determines if the files should overlap. By default, this is set to 1 (enabled). If set to 0, the tracks will play sequentially with a fade-out and fade-in, but without overlapping.
  • curve1 (or c1): Sets the fade curve for the first stream (fade-out).
  • curve2 (or c2): Sets the fade curve for the second stream (fade-in).

Adjusting the Transition Curves

The way the volume changes during the specified transition duration depends on the curves you select. Some common curve types include:

  • tri (double linear, default)
  • qsin (quarter of sine wave)
  • esub (exponential)
  • log (logarithmic)

To configure a 4-second transition with a logarithmic fade-out and exponential fade-in, use the following command:

ffmpeg -i input1.mp3 -i input2.mp3 -filter_complex "acrossfade=d=4:c1=log:c2=exp" output.mp3

Understanding Output Duration

When using acrossfade with overlapping enabled (the default), the total duration of the output file will be shorter than the sum of the two input files. The mathematical formula for the output length is:

\[\text{Output Duration} = \text{Duration of Input 1} + \text{Duration of Input 2} - \text{Transition Duration}\]

For example, if you have two 30-second tracks and configure a 5-second transition duration, the resulting output file will be 55 seconds long.