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.wav

Parameter Breakdown

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.wav

Specifying 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.wav

This command generates a 440 Hz tone at a high-resolution 96 kHz sample rate, saved as a 24-bit WAV file.