Generate White Noise of Specific Duration in FFmpeg
This guide demonstrates how to generate white noise of a specific
duration in FFmpeg using audio source filters. While the
sine source is designed for pure tones, the
aevalsrc (expression evaluation) source is the primary tool
for mathematically generating custom white noise. Below, you will find
direct commands to create white noise using the evaluation source,
alongside the standard native noise generator.
Generating
White Noise with the Eval Source (aevalsrc)
The expression evaluation source (aevalsrc) allows you
to generate audio using mathematical formulas. To generate white noise,
you can use a random number generator scaled to the standard audio
amplitude range of -1.0 to 1.0.
Run the following command to generate 10 seconds of white noise:
ffmpeg -f lavfi -i "aevalsrc=-1+random(0)*2:duration=10" output.wavParameter Breakdown: * -f lavfi: Forces
the input format to use FFmpeg’s Libavfilter input virtual device. *
aevalsrc=: The audio evaluation source filter. *
-1+random(0)*2: The mathematical formula.
random(0) produces a pseudo-random number between 0 and 1.
Multiplying this by 2 and subtracting 1 scales the output to a range
between -1.0 and 1.0, creating white noise. * duration=10
(or d=10): Sets the duration of the generated audio to
exactly 10 seconds.
Why the
sine Source is Not Used for White Noise
The sine source in FFmpeg is designed to generate a
pure, single-frequency sine wave.
# This generates a pure 440Hz tone, NOT white noise:
ffmpeg -f lavfi -i "sine=frequency=440:duration=10" output.wavBy definition, white noise contains an equal intensity at all
frequencies across the audible spectrum. Because a sine wave only
produces a single frequency, it cannot be used to generate white noise.
For mathematical generation, you must use the aevalsrc
method shown above.
The Standard Alternative:
anoisesrc
While aevalsrc is highly customizable, FFmpeg has a
dedicated native source for generating noise called
anoisesrc. It is highly optimized and easier to write.
To generate 10 seconds of white noise using the dedicated noise source, use this command:
ffmpeg -f lavfi -i "anoisesrc=color=white:duration=10:samplerate=44100" output.wavParameter Breakdown: * color=white:
Specifies the noise color (you can also use pink or
brown). * duration=10: Sets the audio length
to 10 seconds. * samplerate=44100: Sets the output sample
rate to 44.1 kHz.