How to Use FFmpeg afade Filter for Audio Fades
This guide provides a practical overview of how to apply fade-in and
fade-out effects to audio files using the FFmpeg afade
filter. You will learn the essential parameters of the filter, how to
construct commands for single fades, and how to chain filters together
to apply both fade-in and fade-out effects to a single audio track.
The afade filter in FFmpeg accepts several parameters to
customize the behavior of the audio transition. The three most commonly
used parameters are:
type(ort): Specifies the fade type. Useinfor a fade-in andoutfor a fade-out.start_time(orst): Specifies the time in seconds when the fade effect should begin.duration(ord): Specifies the length of the fade effect in seconds.
Applying an Audio Fade-In
To apply a fade-in effect at the beginning of an audio file, define
the type as in, set the start time to 0, and
choose your desired duration.
ffmpeg -i input.mp3 -filter:a "afade=type=in:start_time=0:duration=5" output.mp3In this example, the audio will gradually fade in from silence over the first 5 seconds of the file.
Applying an Audio Fade-Out
To apply a fade-out effect, you must know the duration of your audio
file or the specific timestamp where you want the fade to begin. Set the
type to out and specify the start time and duration.
ffmpeg -i input.mp3 -filter:a "afade=type=out:start_time=115:duration=5" output.mp3In this example, the audio will begin fading out to silence at the 115-second mark (1 minute and 55 seconds) and the fade-out process will last for 5 seconds.
Applying Both Fade-In and Fade-Out
To apply both a fade-in at the beginning and a fade-out at the end of
the same audio file, you must chain two afade filters
together. This is done by separating the filter arguments with a
comma.
ffmpeg -i input.mp3 -filter:a "afade=type=in:start_time=0:duration=3,afade=type=out:start_time=175:duration=5" output.mp3In this combined command, the audio will fade in for 3 seconds at the very start, play normally, and then fade out for 5 seconds starting at 175 seconds.