Pad Audio with Silence Using FFmpeg apad Filter

Adding silence to the end of an audio track is a common task in audio post-production, often used to create natural fades, meet specific duration requirements, or prepare files for video synchronization. This article provides a straightforward guide on how to use the FFmpeg apad filter to pad the end of an audio file with silence, explaining the necessary commands, key parameters, and practical examples for various use cases.

The apad (audio pad) filter in FFmpeg is designed specifically for appending silence to the end of an audio stream. There are three primary ways to use this filter depending on whether you want to add a specific duration of silence, pad the file to a specific total duration, or use sample counts.

Method 1: Add a Specific Duration of Silence

To append a precise duration of silence (for example, 5 seconds) to the end of your audio file, use the pad_dur option.

ffmpeg -i input.mp3 -af "apad=pad_dur=5" output.mp3

In this command: * -i input.mp3 specifies your source audio file. * -af "apad=pad_dur=5" applies the audio filter (-af) using apad with a pad duration of 5 seconds.

Method 2: Pad to a Specific Total Duration

If you want the output file to reach a specific total length (for example, exactly 30 seconds), you can use the whole_dur option. If the input audio is shorter than 30 seconds, FFmpeg will fill the remaining time with silence.

ffmpeg -i input.mp3 -af "apad=whole_dur=30" output.mp3

Note: If the input file is already longer than the whole_dur value, no silence will be added, and the file will remain its original length.

Method 3: Using Sample Counts

For precise audio editing, you can pad the audio by a specific number of audio samples instead of seconds. This is done using the pad_len (samples to add) or whole_len (target total samples) options.

To add exactly 44,100 samples of silence (which equals 1 second of audio at a 44.1 kHz sample rate):

ffmpeg -i input.wav -af "apad=pad_len=44100" output.wav

Method 4: Infinite Padding with a Global Limit

Applying apad without any arguments generates an infinite stream of silence. You can pair this with the global -t limit option to define the exact duration of the output file.

ffmpeg -i input.mp3 -af "apad" -t 15 output.mp3

In this case, -t 15 stops the processing at exactly 15 seconds, capping the infinite silence generated by the filter.