10

I'm looking for an audio format where a silence of a couple of hours at the beginning does not affect the overall file size. Has anyone any idea which one to use and what settings I have to use? I tried m4a, ogg and mp3 so far with no luck. An audio sample with 4 hours of silence in the beginning leads to a 400 MB file in some formats.

2
  • 1
    Just to satisfy myself and other pedants, m4a and ogg aren't audio formats, but container formats. ogg files often contain Vorbis encoded audio, but can also contain eg. Opus or FLAC encoded audio. m4a files often contain AAC encoded audio, but can also contain eg. ALAC or ALS encoded audio.
    – AkselA
    Commented Oct 8, 2016 at 8:59
  • Some container formats (MP4 specifically) have data time stamped in which case you simply don't need to write data which is identified as silence into output file. Otherwise, your question is about compression that compresses silence to close to zero output, and you don't define silence - whether it's a real silence, noise or no-voice data. That is, there is quite some uncertainty involved. Commented Oct 8, 2016 at 9:00

4 Answers 4

10

Of course, dealing with it programmatically would be the more sensible and SO way, something like SoX and the silence/pad effects. After all, any bit of silence is identical to any other bit of silence, trying to compress it is a bit of waste of effort.

Having said that, I was a little curious about this myself so I had a go at comparing how well the different codecs fared at compressing pure digital silence.

I created two test files. The first was a 44.1kHz 16bit 30 minutes long stereo WAVE file containing uncorrelated brown noise at -10.66 dBFS RMS. The second file was the same, except padded with 210 minutes of silence, making the total duration 240 minutes (or 4 hours). Next I encoded the files to various lossy and lossless codecs and looked at the size difference between the padded and unpadded files to gauge how efficiently the silence was encoded.

enter image description here

 codec    noise  noise.silence      diff  ratio
   wav    317.5         2540.0    2222.5    8.0
he-aac     14.6          116.5     101.9    8.0
vorbis     36.4          237.1     200.7    6.5
   mp3     38.2          217.2     179.0    5.7
  opus     27.0           81.6      54.6    3.0
   tta    213.8          544.1     330.3    2.5
   aac     54.0          131.7      77.7    2.4
    wv    211.3          444.1     232.8    2.1
  alac    212.5          393.7     181.2    1.9
  flac    211.5          404.8     193.3    1.9
   als    209.7          384.2     174.5    1.8
   ofr    209.3          356.9     147.6    1.7

Codecs used:

Lossless
wav:    WAVE
tta:    True Audio v3.4.1
wv:     WavPack v4.80.0 (wavpack -x)
alac:   Apple Lossless
ofr:    OptimFROG v5.100 (ofr --preset 2)
als:    MPEG-4 Audio Lossless Coding v23 (mp4alsRM23 -a -b -o50)
flac:   Free Lossless Audio Codec v1.3.1 (flac -8)

Lossy vbr
mp3:    LAME MP3 v3.99.5 (lame -h -V2)
opus:   Opus v1.1.2 (opusenc --bitrate 128 --framesize 40)
aac:    Advanced Audio Codec v2.0 (afconvert -f 'm4af' -d aac -q 127 -s 3 -u vbrq 100)
vorbis: Vorbis aoTuV b5.5 (oggenc -q 5)

Lossy cbr
he-aac: High-Efficiency AAC v1 (afconvert -f 'm4af' -d aach -q 127 -s 0 -b 64000)
2
  • Interesting (and maybe meaningless) that opus didn't have the best ratio but had the smallest resulting file size with the silence. Is that a much lower resulting quality than the others?
    – xr280xr
    Commented Apr 26, 2019 at 3:13
  • @xr280xr: All the lossy encodings (apart from HE-AAC) were chosen to be transparent, with some margin. As such they should be roughly comparable. In hindsight I think I should have set AAC to -u vbrq 90, or maybe even lower, to bring it more in line with the others.
    – AkselA
    Commented Apr 26, 2019 at 8:05
1

If you encode your audio file in .wav format, according to the "Multimedia Programming Interface and Data Specifications 1.0" at pages 56-60 you can encode, instead of the usual single "data" chunk, a "LIST" chunk of type 'wavl' alternating "data" and "slnt" chunks. For an interpretation of the obscure (and buggy) specification refer to the wikipedia page on the WAV format.

0

I'm not sure whether this helps, but if the size causes problems in storage or transfer, you can simply ZIP the wav and voilá! all the empty bytes disappear. For usage you have to unpack it again though.

-1

You might consider hacking the encoder to "pause" when it encounters more than a second or so of silence. Any of the codecs out there can be hacked to do this, though you will need to understand how they work before starting on changes like that...

Another option is to pipe the output of an MP3 encoder through a program that strips out "extra" silent frames. That might be less overall work (though you're still going to have to understand how MP3 framing & the Layer III bit reservoir work).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.