How to Generate Silent Audio Using FFmpeg anullsrc

This article provides a practical guide on how to use the FFmpeg anullsrc (audio null source) filter to generate silent audio tracks. You will learn the basic command structure, how to customize audio properties like sample rate and channel layout, and how to merge a silent audio track with an existing video file.

What is anullsrc?

The anullsrc filter is a virtual audio source helper in FFmpeg that generates a silent audio signal. It is highly useful for creating dummy audio tracks, padding videos that lack audio, or debugging audio pipelines.

Generating a Standalone Silent Audio File

To generate a simple silent audio file, you must define the input format as lavfi (Libavfilter virtual input) and pass anullsrc as the input.

ffmpeg -f lavfi -i anullsrc -t 10 silence.mp3

Customizing Sample Rate and Channel Layout

By default, anullsrc generates stereo audio at a sample rate of 44,100 Hz. You can customize these parameters by passing arguments to the filter using the channel_layout (or cl) and sample_rate (or r) options.

To generate a 5-second mono WAV file at 48,000 Hz:

ffmpeg -f lavfi -i anullsrc=channel_layout=mono:sample_rate=48000 -t 5 silence.wav

Alternatively, you can use the shorthand syntax:

ffmpeg -f lavfi -i anullsrc=cl=stereo:r=96000 -t 5 silence.wav

Adding a Silent Audio Track to a Video

A common use case is adding a silent audio track to a video file that has no sound. This is often required by social media platforms or video players that demand an audio stream to play correctly.

ffmpeg -i input_video.mp4 -f lavfi -i anullsrc -c:v copy -c:a aac -shortest output_video.mp4