FFmpeg Sine Filter: Generate Tone with Sample Rate
This article explains how to use the sine audio source
filter in FFmpeg to generate a continuous, constant sine wave tone. You
will learn the exact command-line syntax required to customize the
frequency of the tone, define a specific audio sample rate, and control
the duration of the generated output file.
To generate a constant tone using FFmpeg, you use the Libavfilter
virtual input device (-f lavfi) combined with the
sine filter. This filter allows you to define the frequency
of the tone and the sample rate directly within the input
definition.
The Basic Command Structure
To generate a specific tone, use the following command structure:
ffmpeg -f lavfi -i "sine=frequency=1000:sample_rate=48000" -t 5 output.wavParameter Breakdown
-f lavfi: Tells FFmpeg to use the Libavfilter virtual input format.-i "sine=...": Specifies thesineaudio source filter.frequency(orf): Sets the carrier frequency of the generated sine wave in Hz. The default is440Hz (middle A). In the example above, it is set to1000Hz (1 kHz).sample_rate(orr): Sets the sample rate of the output audio in Hz. The default is44100Hz. In the example above, it is set to48000Hz (48 kHz).-t 5: Sets the duration of the output file (in this case, 5 seconds).
Alternative Syntax (Shortened)
You can use short-hand aliases for the filter parameters to keep the
command concise. The alias for frequency is f,
and the alias for sample_rate is r. You can
also set the duration inside the filter using duration (or
d).
The following command achieves the same result as above but uses short-hand parameter names and defines a 10-second duration inside the filter:
ffmpeg -f lavfi -i "sine=f=1000:r=48000:d=10" output.wavSpecifying Output Codecs
By default, FFmpeg will choose an appropriate codec based on the
output file extension (such as PCM 16-bit for .wav files).
If you need to explicitly define the codec or bit depth (for example, to
ensure a 24-bit PCM output), append the -c:a flag:
ffmpeg -f lavfi -i "sine=f=440:r=96000:d=5" -c:a pcm_s24le output.wavThis command generates a 440 Hz tone at a high-resolution 96 kHz sample rate, saved as a 24-bit WAV file.