Generating Continuous Test Tones with FFmpeg
This article provides a quick overview and practical guide on how to generate continuous audio test tones directly from the Linux command line using the powerful FFmpeg multimedia framework. You will learn the essential commands to create standard sine waves, adjust frequencies, configure audio sample rates, and output the generated audio either to a saved file or as a live stream.
The Basic Command for a Sine Wave
To generate a continuous test tone, FFmpeg utilizes the
lavfi (Libavfilter) virtual input device along with the
sine audio source filter. By default, this filter generates
a 440 Hz sine wave (the musical note A4).
The fundamental command structure to generate a 5-second test tone and save it as an MP3 file looks like this:
ffmpeg -f lavfi -i sine=duration=5 -c:a libmp3lame output.mp3In this command:
- -f lavfi: Specifies that the input format is the Libavfilter virtual device.
- -i sine=duration=5: Defines the input filter as a sine wave with a set duration of 5 seconds.
- -c:a libmp3lame: Encodes the audio using the MP3 codec.
Generating Truly Infinite or Continuous Tones
If your goal is to generate an ongoing tone without a hardcoded
expiration time—useful for live hardware testing or continuous signal
loops—you can omit the duration parameter. To stop a truly continuous
command, you simply press Ctrl + C in your terminal.
ffmpeg -f lavfi -i sine -c:a pcm_s16le output.wavCustomizing Frequency and Sample Rate
You can precisely control the pitch of the tone and the quality of
the audio stream by passing additional arguments to the sine filter. The
frequency (or f) parameter dictates the pitch
in Hz, while the sample_rate (or r) parameter
dictates the audio sampling frequency.
For example, to generate a 1000 Hz (1 kHz) test tone at a standard CD-quality sample rate of 44100 Hz, use the following syntax:
ffmpeg -f lavfi -i sine=frequency=1000:sample_rate=44100 -t 10 output.wavNote: The
-t 10flag is an alternative way to specify a duration limit of 10 seconds, placed as an output option rather than inside the filter itself.
Real-Time Audio Playback
If you want to hear the continuous test tone immediately through your
system speakers instead of saving it to a file, you can pipe the FFmpeg
output into a native Linux playback utility like aplay
(part of the ALSA toolset).
ffmpeg -f lavfi -i sine=frequency=440 -f audiotoolbox - | aplayAlternatively, if you have FFmpeg’s companion media player FFplay installed on your Linux system, you can achieve live playback natively in a single short command:
ffplay -f lavfi sine=frequency=440