How to Use FFmpeg acrossfade Filter

This article provides a straightforward guide on how to use the acrossfade filter in FFmpeg to seamlessly transition between two audio tracks. You will learn the basic command structure, the key parameters that control the duration and curve of the fade, and practical examples to help you implement smooth audio crossfades in your projects.

The acrossfade filter in FFmpeg merges two audio streams by fading out the first stream while fading in the second stream over a specified overlapping period. This is highly useful for creating playlists, music mixes, or smooth transitions in video soundtracks.

Basic Command Structure

To apply a crossfade between two audio inputs, you must use the -filter_complex option to route both audio streams through the acrossfade filter.

Here is the fundamental command template:

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

Key Parameters Explained

You can customize the transition by adjusting the filter’s parameters inside the acrossfade argument, separated by colons:

Available Curve Types

You can choose from several mathematical curves to alter the feel of the transition. Common options include: * linear (linear transition, default) * tri (triangular, helpful for maintaining constant volume) * qsin (quarter sine wave) * esinh (exponential sine) * exp (exponential)

Practical Examples

1. A Simple 3-Second Linear Crossfade

This command merges two files with a standard 3-second linear transition:

ffmpeg -i song1.wav -i song2.wav -filter_complex "[0:a][1:a]acrossfade=d=3:c1=linear:c2=linear[out]" -map "[out]" mixed.wav

2. Smooth Exponential Crossfade

For a more natural-sounding transition where the volume drops slowly at first and then quickly (and vice versa for the fade-in), use the exponential curve:

ffmpeg -i track1.mp3 -i track2.mp3 -filter_complex "[0:a][1:a]acrossfade=d=6:c1=exp:c2=exp[out]" -map "[out]" output.mp3

Important Considerations