Generate Audio Tones with FFmpeg Sine Filter
FFmpeg provides powerful built-in audio synthesis tools to generate
tones, test signals, and alerts directly from the command line without
requiring external audio files. While FFmpeg does not feature a filter
named siren, tone generation is handled by the
sine audio source filter, while complex modulated tones
like emergency sirens are generated using the aevalsrc
filter. This guide explains how to use the sine filter to
generate standard synthesized tones and how to modulate frequencies to
produce a classic siren sound.
Generating a Basic Synthesized Tone
The sine filter is invoked via the lavfi
(Libavfilter) virtual input device. It creates an audio stream based on
a sine wave.
To generate a standard 440 Hz tone (musical note A4) lasting 5 seconds:
ffmpeg -f lavfi -i "sine=frequency=440:duration=5" output.wavKey Parameters of the
sine Filter
frequency(orf): Sets the carrier frequency in Hz. The default is 440 Hz.duration(ord): Specifies the length of the generated audio stream in seconds.sample_rate(orr): Defines the audio sample rate in Hz. The default is 44,100 Hz.beep_factor(orb): Introduces a periodic beep by multiplying the frequency at regular intervals.
To generate a 1,000 Hz reference tone with a 48,000 Hz sample rate lasting 10 seconds:
ffmpeg -f lavfi -i "sine=f=1000:r=48000:d=10" reference_tone.wavCreating an Intermittent Beeping Tone
You can use the beep_factor parameter to create a
periodic alert signal. When set, the tone will alternate between the
base frequency and a multiplied frequency every second:
ffmpeg -f lavfi -i "sine=f=800:b=2:d=6" beeps.wavIn this command, the tone plays at 800 Hz and periodically jumps by a factor of 2 (to 1,600 Hz).
Synthesizing an Emergency Siren Effect
Because the sine filter only outputs fixed carrier
frequencies, synthesizing a true rising and falling siren requires
frequency modulation. The aevalsrc (audio evaluation
source) filter allows mathematical expressions to drive frequency over
time.
Two-Tone Ambulance Siren
To alternate between two distinct frequencies (700 Hz and 900 Hz) every half-second:
ffmpeg -f lavfi -i "aevalsrc='sin(2*PI*(800+100*sgn(sin(2*PI*t)))*t)':d=8" two_tone_siren.wavContinuous Wail Police Siren
To create a smooth, continuous frequency sweep that oscillates between 600 Hz and 1,200 Hz:
ffmpeg -f lavfi -i "aevalsrc='sin(2*PI*(900+300*sin(2*PI*0.5*t))*t)':d=10" wail_siren.wav900: The center frequency in Hz.300: The frequency deviation (modulates ±300 Hz, swinging from 600 Hz to 1,200 Hz).0.5*t: The speed of the modulation cycle (one full cycle every 2 seconds).d=10: Total duration of 10 seconds.