Generate Sine Wave Audio with Custom Frequency in FFmpeg
This article provides a quick guide on how to generate a custom frequency sine wave audio tone using FFmpeg. You will learn the exact command-line syntax required to define the frequency, set the audio duration, control the volume, and save the output in your preferred audio format.
To generate a simple sine wave tone, you can use FFmpeg’s built-in
virtual audio source filter called sine.
The Basic Command
The most straightforward way to generate a sine wave is by using the following command:
ffmpeg -f lavfi -i "sine=frequency=440:duration=5" output.wavHere is a breakdown of what each parameter does: *
-f lavfi: Tells FFmpeg to use the
Libavfilter input virtual device. *
-i "sine=...": Specifies the sine
generator filter as the input. *
frequency=440 (or shorthand
f=440): Sets the frequency of the tone in Hertz (Hz). In
this case, 440 Hz represents the musical note A4. *
duration=5 (or shorthand
d=5): Sets the length of the generated audio to 5 seconds.
* output.wav: The name and format of the
output file. You can change this to .mp3,
.ogg, or .flac as needed.
Customizing Sample Rate and Volume
By default, the sine filter generates audio at a sample
rate of 44,100 Hz at maximum amplitude, which can sometimes cause
digital clipping.
To set a custom sample rate and lower the volume to a safer level, use the following command:
ffmpeg -f lavfi -i "sine=frequency=1000:sample_rate=48000:duration=10" -filter:a "volume=0.5" output.wavIn this expanded command: *
sample_rate=48000 (or shorthand
r=48000): Sets the audio sample rate to 48 kHz. *
-filter:a "volume=0.5" (or shorthand
-af "volume=0.5"): Reduces the volume to 50% of the maximum
level to prevent audio distortion.