FFmpeg acrossfade: How to Crossfade Two Audio Files
This article provides a straightforward guide on how to use the
FFmpeg acrossfade filter to seamlessly blend the end of one
audio file into the beginning of another. You will learn the essential
command syntax, key parameters such as transition duration and fade
curves, and practical examples to help you achieve smooth audio
transitions.
The Basic Command
To crossfade two audio files, you need to use FFmpeg’s
-filter_complex option with the acrossfade
filter. This filter takes two input audio streams, overlaps them by a
specified duration, and applies a fade-out to the first file while
applying a fade-in to the second.
Here is the standard command to crossfade two MP3 files with a 5-second overlap:
ffmpeg -i input1.mp3 -i input2.mp3 -filter_complex "acrossfade=d=5" output.mp3How It Works:
-i input1.mp3 -i input2.mp3: Specifies the two input audio files.-filter_complex "acrossfade=d=5": Calls the complex filtergraph and appliesacrossfade. Thed=5parameter sets the transition duration to 5 seconds.output.mp3: The resulting audio file containing the merged, crossfaded tracks.
Key Parameters for
acrossfade
You can customize the transition by adjusting the filter’s parameters:
duration(ord): The duration of the crossfade in seconds. (e.g.,d=3for a 3-second fade).overlap(oro): A boolean value (1or0) indicating whether the files should overlap. This defaults to1(true). If set to0, the tracks will play sequentially without overlapping, though they will still fade.curve1(orc1): The fade curve for the first stream (fade-out).curve2(orc2): The fade curve for the second stream (fade-in).
Transition Curve Types
FFmpeg supports several curve shapes to control the volume transition
speed. Common curves include: * tri (Double linear /
triangular - default) * qsin (Quarter sine) *
esin (Exponential sine) * log (Logarithmic) *
exp (Exponential) * lin (Linear)
Advanced Example: Customizing Fade Curves
To create a more professional-sounding transition, you can specify
custom fade curves. For example, using exponential curves
(exp) often results in a smoother acoustic transition:
ffmpeg -i input1.mp3 -i input2.mp3 -filter_complex "acrossfade=d=4:c1=exp:c2=exp" output.mp3In this command: * The crossfade duration is set to 4 seconds
(d=4). * Both the fade-out (c1=exp) and
fade-in (c2=exp) use exponential curves to prevent sudden
drops in volume during the mix.