How to create silent .ogg audio file
Asked Answered
S

2

9

In answer to the question "How-to make a silent mp3 or wav-file" on ubuntuforums.org FakeOutdoorsman provided the following recipe:

Another method by using FFmpeg. 60 seconds of silent audio in WAV:

ffmpeg -ar 48000 -t 60 -f s16le -acodec pcm_s16le -ac 2 -i /dev/zero -acodec copy output.wav

60 seconds of silent audio in MP3:

ffmpeg -ar 48000 -t 60 -f s16le -acodec pcm_s16le -ac 2 -i /dev/zero -acodec libmp3lame -aq 4 output.mp3

How could I do something similar to create a silent .ogg audio file?

For a web app, I want to create a very short file for testing whether the browser will preload an audio file, or whether it will wait until the file is actually played before starting to stream it.

Stickle answered 14/8, 2015 at 20:0 Comment(0)
T
5

Specify -acodec to be vorbis (instead of libmp3lame) and put .ogg at the end of the output file (in place of .mp3).

Tiny answered 14/8, 2015 at 20:16 Comment(2)
Thanks! I needed to use libvorbis instead of vorbis. The output for 30ms is 3,694 bytes. I can get a 30ms MP3 file for 333 bytes. At wittnl's page on GitHub I found a dataURL for a silent ogg that is less than 300 bytes, including base64 encoding...Stickle
Nice. I'm glad you know how to fill in the blanks. About the size discrepancy you observed, I wager that FFmpeg probably writes a metadata block into the file and that the smaller file you found likely omits it.Tiny
A
17

Silent audio

That's an outdated method. You can now use the anullsrc filter instead, and it will work on any OS:

ffmpeg -f lavfi -i anullsrc -t 5 -c:a libvorbis output.ogg
  • Default sample rate is 44100, and default channel layout is stereo. If you want something different you can do something like: anullsrc=r=48000:cl=mono (or use cl=1 for mono).

  • For Vorbis in general, avoid the native encoder vorbis if possible; libvorbis will provide a better output (although it doesn't really matter with a silent output).


Other somewhat related examples

Test tone

An annoying tone or beeping tone can be made with sine filter. Generate a 220 Hz sine wave with a 880 Hz beep each second, for 5 seconds:

ffmpeg -f lavfi -i sine=f=220:b=4:d=5 -c:a libvorbis output.oga

Just black video

Using the color filter.

ffmpeg -f lavfi -i color=d=5 -c:v libtheora output.ogv
  • Default frame rate is 25 and default video size is 320x240. To change it: color=r=24:s=1280x720:d=5.

  • But who uses Theora anymore? A more modern alternative that likely fills its niche is VP8/VP9 + Vorbis in WebM: -c:v libvpx output.webm.

Test pattern + 440 Hz tone

Using testsrc and sine filters:

ffmpeg -f lavfi -i testsrc -f lavfi -i sine -t 10 -c:v libtheora -c:a libvorbis \
-q:v 5 -q:a 5 output.ogv

Also see

Alcoholize answered 15/8, 2015 at 17:6 Comment(2)
Thanks! Your command gives this output: size= 4kB time=00:00:04.98 bitrate=7.3kbits/s video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:4kB muxing overhead: 2004.608276% Is it possible to create the .ogg file without any global headers, to get the minimum viable output file?Stickle
If you want to avoid problems when concatenating silence with other sounds, do create the silence with the SAME parameters than the sound you will mix with (mono/stereo and Hz).Starlin
T
5

Specify -acodec to be vorbis (instead of libmp3lame) and put .ogg at the end of the output file (in place of .mp3).

Tiny answered 14/8, 2015 at 20:16 Comment(2)
Thanks! I needed to use libvorbis instead of vorbis. The output for 30ms is 3,694 bytes. I can get a 30ms MP3 file for 333 bytes. At wittnl's page on GitHub I found a dataURL for a silent ogg that is less than 300 bytes, including base64 encoding...Stickle
Nice. I'm glad you know how to fill in the blanks. About the size discrepancy you observed, I wager that FFmpeg probably writes a metadata block into the file and that the smaller file you found likely omits it.Tiny

© 2022 - 2024 — McMap. All rights reserved.