FFmpeg acrossfade: Concatenate Audio with Crossfade

This article explains how to use the acrossfade filter in FFmpeg to create seamless transitions between concatenated audio files. You will learn the basic command syntax, how to adjust transition duration and fade curves, and how to chain multiple audio files together for a professional-sounding audio mix.

The acrossfade filter in FFmpeg allows you to apply a crossfade effect when joining two audio streams. Unlike simple concatenation, which can result in abrupt transitions, crossfading gradually fades out the ending of the first audio file while fading in the beginning of the second audio file over a specified duration.

Basic Syntax for Two Audio Files

To crossfade two audio files, you must use FFmpeg's -filter_complex option because the process requires managing multiple inputs. Here is the standard command:

ffmpeg -i input1.mp3 -i input2.mp3 -filter_complex "[0:a][1:a]acrossfade=d=5:c1=tri:c2=tri[aout]" -map "[aout]" output.mp3

Understanding the Parameters

  • [0:a][1:a]: These labels specify the input streams. [0:a] refers to the audio of the first input file, and [1:a] refers to the audio of the second input file.
  • d=5: This sets the duration of the crossfade in seconds. In this example, the files will overlap and fade for 5 seconds.
  • c1 and c2: These define the transition curves (fade shapes) for the first and second files respectively.
    • tri (triangular, default) provides a linear-like power fade.
    • qsin (quarter sine) offers a smoother, natural-sounding transition.
    • exp (exponential) is ideal for dramatic fades, especially with music.
    • log (logarithmic) starts slow and speeds up.
  • [aout]: This names the resulting audio stream, which is then mapped to the output file using -map "[aout]".

Chaining Three or More Audio Files

Because the acrossfade filter only accepts two input streams at a time, you must chain multiple filters together in sequence if you have three or more audio files.

The command below demonstrates how to transition between three files:

ffmpeg -i input1.mp3 -i input2.mp3 -i input3.mp3 -filter_complex "[0:a][1:a]acrossfade=d=5:c1=qsin:c2=qsin[fade1]; [fade1][2:a]acrossfade=d=5:c1=qsin:c2=qsin[aout]" -map "[aout]" output.mp3

In this command, input1.mp3 and input2.mp3 are crossfaded first, creating an intermediate stream named [fade1]. Then, [fade1] is crossfaded with input3.mp3 ([2:a]) to produce the final [aout] stream.