How to Fade Out Audio with FFmpeg afade Filter
This article provides a straightforward guide on how to use the
FFmpeg afade filter to apply a smooth fade-out effect to an
audio track. You will learn the basic command syntax, the essential
parameters for controlling the timing of the fade, and practical
examples for processing both standalone audio files and audio within
video files.
Understanding the afade Filter Parameters
To apply a fade-out effect, you need to use the afade
audio filter and define three primary parameters:
type(ort): Specifies the fade direction. For a fade-out, this must be set toout.start_time(orst): The time (in seconds) from the beginning of the track where the fade-out effect should start.duration(ord): The length of time (in seconds) that the fade-out effect should last.
Basic Command Example for Audio Files
If you have an audio file (like an MP3 or WAV) and you want to start a 5-second fade-out at the 10-second mark, use the following command:
ffmpeg -i input.mp3 -filter_complex "afade=type=out:start_time=10:duration=5" output.mp3Alternatively, you can use the shorthand parameter names:
ffmpeg -i input.mp3 -filter_complex "afade=t=out:st=10:d=5" output.mp3In this example, the audio will play at normal volume until 10 seconds, gradually decrease in volume over the next 5 seconds, and become completely silent at 15 seconds.
Calculating Fade-Out for the End of an Audio Track
To fade out at the very end of an audio file, you must first know the
total duration of the track. Use this formula to find your start time
(st):
\[\text{st} = \text{Total Track Duration} - \text{Desired Fade Duration}\]
For example, if your audio track is exactly 3 minutes (180 seconds) long and you want a 10-second fade-out at the end:
- Start Time (
st): \(180 - 10 = 170\) seconds. - Duration (
d): 10 seconds.
The command will look like this:
ffmpeg -i input.wav -filter_complex "afade=t=out:st=170:d=10" output.wavApplying Audio Fade-Out to a Video File
To apply an audio fade-out to a video file while keeping the original video stream intact without re-encoding it, use the following command structure:
ffmpeg -i input.mp4 -filter_complex "[0:a]afade=t=out:st=55:d=5[a]" -map 0:v -map "[a]" -c:v copy output.mp4[0:a]: Selects the audio stream of the first input file.[a]: Assigns the filtered audio to a temporary label.-map 0:v: Copies the original video stream directly.-map "[a]": Uses the newly filtered audio track for the output.-c:v copy: Stream copies the video to save processing time and maintain original quality.