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-f lavfi: Specifies that the input comes from the Libavfilter virtual input device.-i anullsrc: Sets the input source to the null audio source helper.-t 10: Restricts the duration of the output file to 10 seconds.silence.mp3: The output file name and format.
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.wavAlternatively, you can use the shorthand syntax:
ffmpeg -f lavfi -i anullsrc=cl=stereo:r=96000 -t 5 silence.wavAdding 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-i input_video.mp4: The original video file without audio.-c:v copy: Copies the video stream directly without re-encoding, preserving quality and saving time.-c:a aac: Encodes the generated silent audio stream into AAC format.-shortest: Tells FFmpeg to end the conversion as soon as the shortest input stream ends. Sinceanullsrcgenerates an infinite stream by default, this flag ensures the output matches the exact length of the input video.