How to generate a sine wave with ffmpeg?

12

2

I would like to generate an audio file with a sine (sinusoid) wave with FFmpeg. I know there is a sine filter but that's as far as it goes.

I tried:

fmpeg -filter "sine=48:1:5" -c:a pcms16le test

to create 5 seconds of audio at 48kHz in PCM S16LE format, but I got the following error message:

Output file #0 does not contain any stream

and the test file is empty.

UmNyobe

Posted 2014-03-04T10:46:31.983

Reputation: 305

You can also play a sine without creating a file with ffplay: https://stackoverflow.com/questions/5109038/linux-sinus-audio-generator/57610684#57610684

– Ciro Santilli 新疆改造中心法轮功六四事件 – 2019-08-22T14:03:33.497

Answers

21

To generate a 1000 Hz signal for 5 seconds duration use this:

ffmpeg -f lavfi -i "sine=frequency=1000:duration=5" test.wav

You can add -c:a pcm_s16le:

ffmpeg -f lavfi -i "sine=frequency=1000:duration=5" -c:a pcm_s16le test.wav    

To also set the sampling rate to 48 KHz:

ffmpeg -f lavfi -i "sine=frequency=1000:sample_rate=48000:duration=5" -c:a pcm_s16le test.wav

Rajib

Posted 2014-03-04T10:46:31.983

Reputation: 2 406

1You can also set the amplitude by adding for example: -af "volume=-18dB" (for -18dBFS). – mivk – 2017-12-29T15:16:17.157

6

Apologies for necro-ing this, but in the event that someone from the future comes looking for this, if you wanted to do this in stereo, you would do the following:

ffmpeg -f lavfi -i "sine=frequency=1000:duration=5" -ac 2 output.wav

You could also use -filter_complex with amerge:

ffmpeg -f lavfi -i "sine=frequency=1000:duration=5" -filter_complex "[0:a][0:a]amerge=inputs=2[aout]" -map "[aout]" output.wav

ocdude

Posted 2014-03-04T10:46:31.983

Reputation: 61