# The Power of Opus Compression

When you like to listen to a lot of Podcasts, lectures or audio books for instance, and you want to carry with you as much of it as you can then the opus audio codec is something you might be interested in. I rarely use this term but here it can be applied: The results blew my mind. It's astonishing how much audio you can pack on a mobile device with severe capacity limits.

I just converted this:

none 162 Files mp3, 44100 Hz, mono, s16p, 129 kb/s Total Length: 6d 14h 47min 49 Total Size: 9.05 GB

From 9.05 GB to 555 MB and am content with the results.

Please consider that this is a conversion from mp3 as source. Yes, that's right, I went from 128k mp3 to 6k opus and a weeks worth of audio is reduced to half a gig, and it has been converted from an unfavourable source. Though this is my personal hardcore setting, in my research I found out that you almost can't go wrong with 16k, no matter how bad the source.

## What is Opus?

In their own words: > Opus is a totally open, royalty-free, highly versatile audio codec. Opus is unmatched for interactive speech and music transmission over the Internet, but is also intended for storage and streaming applications. It is standardized by the Internet Engineering Task Force (IETF) as RFC 6716 which incorporated technology from Skype’s SILK codec and Xiph.Org’s CELT codec.

## Comparison Chart Between MP3, AAC HE and Opus

LengthuncompressedCodecBitratecompressedFactor
24 h14.88 GBMP3128k1382.411
24 h14.88 GBAAC HE64k691.2 MB22
24 h14.88 GBOpus16k172.8 MB86
24 h14.88 GBOpus6k64.8 MB233
7 d104 GBMP3128k9.7 GB11
7 d104 GBAAC HE64k4.8 GB22
7 d104 GBOpus16k1.2 GB86
7 d104 GBOpus6k0.5 GB233
30 d446 GBMP3128k41.5 GB11
30 d446 GBAAC HE64k20.7 GB22
30 d446 GBOpus16k5.2 GB86
30 d446 GBOpus6k1.9 GB233
365 d5.4 TBMP3128k504.6 GB11
365 d5.4 TBAAC HE64k252.3 GB22
365 d5.4 TBOpus16k63.1 GB86
365 d5.4 TBOpus6k23.6 GB233

## Bitrate Calculator

 Bitrate kbit/s Length s Filesize MB

Please note that opus uses VBR (it can be tweaked to CBR, which I do not recommend after seeing the results). Therefore final file size close but varies.

## The Conversion Command

You can almost do no wrong with 16k. In my experience even heavily compressed, bad sounding sources result in nearly as good quality as the source.

bash ffmpeg -i <input.file> -acodec libopus -b:a 16k <output.opus>

When the source files are of higher quality you still get impressive results with 6k, which is the absolute minimum setting opus offers, but you can definitely hear the impact this massive compression brings along with it.

I personally use 6k bitrate compression even if the source is of minor quality, because I prefer having more in a tighter space with less quality, than having less with higher quality. That's the decision you have to make for yourself.

This is the hardcore setting I use:

bash ffmpeg -i <input.file> -acodec libopus -b:a 6k -application voip output.opus

## Conversion Options

By default the options for libopus are solid. For the purpose of extreme size reduction we lower the bitrate. Then we optimize for speech recognition with the application option in our particular case.

application (N.A.) Set intended application type. Valid options are listed below:

• voip -> Favor improved speech intelligibility.
• audio -> Favor faithfulness to the input (the default).
• lowdelay -> Restrict to only the lowest delay modes.

## Handle Multiple Files Simultaneously

bash for f in *; do ffmpeg -n -i "$f" -acodec libopus -b:a 16k -application voip "encoded_"${f}".opus"; done

This command iterates through all files in the working directory and converts them into the opus format. The rendered files are stored in the same directory having the same name as the original files with a prefixed encoded_. The Opus codec operates only single threaded.

## Speed Things Up with Multithreading

Opus doesn't support multithreading and encodes are assigned to a single CPU core but you can parallelize the encoding process with the following bash commands.

bash bash -c 'ffmpeg_pids=(); for f in *; do ffmpeg -n -i "$f" -acodec libopus -b:a 16k -application voip encoded_"${f}".opus & ffmpeg_pids+=("$!"); done; wait "${ffmpeg_pids[@]}"'

bash # -P8 indicates Number of threads (of 4 core i7 in this case) find . -name "*.mp3" -print0 | xargs -0 -P8 -n1 -I {} ffmpeg -i {} -acodec libopus {}.opus

The first command will convert all files in the working directory simultaneously. And the second command converts as much as threads as are assigned but not more than that. The second command should be better when there are many files in the working directory.

Or use gnu parallel.

## Opus Media Players for iOS

At least VLC does it.

## Final Notes

I know, a lot of people will disagree with me on the 6k setting. In this case please simply use 16k.