Creating silence with FFmpeg

Note that the following commands will be too long to easily read on a single line, so I will split the command across multiple lines using the usual \ character.

The old way to Create a never-ending mono stream of silence

The old way to create silence is to say the input file is of a format of raw-uncompressed audio and read from /dev/zero. This creates an infinitely long audio stream.

ffmpeg \
-ar 48000 -ac 1 -f s16le -i /dev/zero \
-t 10 -y silence.wav

When adding that to a video source to an infinitely long audio stream you need to stop reading the silence when when the video source stops.

The usual way to do that is to use the -shortest output command-line option.

-shortest

If you know length of the source video you could use the -frames output command-line option, or the -t output command-line option.

-t 60000ms

Duration can be in seconds or other FFmpeg time formats

The current way to create a never-ending mono stream of silence

Reading from /dev/zero is a bit of a ‘caveman’ approach.

The filter source aevalsrc can create audio from a mathmatical formula.

Creating silence is simple.

-f lavfi -i "aevalsrc=0:s=48000:n=1920" \
-shortest

It might be better to create one audio block per frame - which is easy for UK frame rates:

n = sample_rate ÷ frame_rate

for example:

Create a time bound mono stream of silence

If you are adding silence to a video source, and you know length of the source video you could use the duration option to the aevalsrc filter source.

-f lavfi -i "aevalsrc=0:n=1920:s=48000:d=60.0"

duration can be in seconds or other FFmpeg time formats

for example:

Multiple streams of time bound mono stream of silence

If you need multiple streams - just create multiple inputs.

-f lavfi -i "aevalsrc=0:n=1920:s=48000:d=60.0" \
-f lavfi -i "aevalsrc=0:n=1920:s=48000:d=60.0" \
-map 0:a \
-map 1:a \

Do it in a fliter instead

Alternatively, especially if you are going to use -filter_complex in your full command-line, you can ‘just’ make a stream in the filter, and use other filter commands to manipulate the stream.

-filter_complex "aevalsrc=0:n=1920:s=48000:d=60000ms,asplit=4[a0][a1][a2][a3]" \
-map "[a0]" \
-map "[a1]" \
-map "[a2]" \
-map "[a3]" \