I’ve just stumbled upon Opus, a relatively new audio codec, with the release of version 1.1 implementation which improves encoding quality for VBR audio, automatically detect audio or speech to select the best encoding mode, and improved 5.1 surround quality/compression ratio. The new release also bring speed improvements for all architectures, and specifically for ARM, where decoding uses around 40% less CPU and encoding uses around 30% less CPU thanks to the use of NEON compared to an earlier version.
You can go to the online demo page to find more about the latest released, and try some of the latest improvements.
This all looks fun, but I wanted to know more about Opus, and especially how it compares against MP3 or AAC. It turns out Opus was not originally designed to compete against MP3/AAC which are used to store audio, but instead it was meant to be used for real-time applications like VoIP or video conferencing, which require a low latency. Opus codec is actually composed of two audio codecs SILK for voice, and CELT for music, and automatically selects the one most suited to the audio type to provide better quality and a lower bitrate.
I went over to Wikipedia for a couple of charts, and if these are correct, Opus is the holy grails of audio codecs. It’s royalty-free, and beats all other codecs in terms of latency, and quality/bitrate ratio. I haven’t found comparisons for encoding and decoding times, but it has to be very fast since VoIP is the main purpose of the codec. One downside is the lack of hardware decoding as seen for MP3 and AAC, so in a mobile device, it would most certainly lower the battery life compared to MP3 or AAC video.
Opus has a better latency compared to VoIP codecs (G.729, G.722, Speex,…) and is capable of high-fidelity at bitrate comparable to Vorbis, AAC, MP3.
Opus can support a very wide range of codecs thanks to its speech and music codec, and has superior quality for a given bitrate over all other codecs, except at very low bitrates (<~10kb/s) where AMR-WB, ARM-NB, and Speex may still have an advantage. Most of my MP3 files are usually encoded at 128kb/s or 192kb/s, and Opus can better the quality of MP3 @128kb/s, and is about the same as Vorbis and AAC. As Opus has about the same quality Vorbis, another royalty-free, open source code, and MP3 and AAC are omnipresent, it may struggle to gain traction in this area.
Opus is already supported in several well-known software and hardware platforms, such as Firefox, Chromium, Gstreamer, Icecast, VLC, ChromeCast and many more.
Building Opus Library and Samples
It’s open source, so let’s download the latest version. I’ll do that in Ubuntu 13.04, but you can also build libopus for Windows or Mac OS, or easier, directly download opus-tools. for these two platforms. Opus library and tools may already be in your Linux distribution repositories, but these will be an older version, so we’ll get the source code tarball, extract it and build the library and tools:
1 2 3 4 5 6 |
wget http://downloads.xiph.org/releases/opus/opus-1.1.tar.gz tar xzvf opus-1.1.tar.gz cd opus-1.1 ./configure make -j8 sudo make install |
The implementation uses floating point by default, so if you’re using an embedded platform, you may want to use the fixed point implementation instead for better performance, albeit slightly lower quality with:
1 |
./configure --enable-fixed-point |
Beside the libopus, this will generate opus_demo and opus_compare executables in the top directory, btu these are mainly for test purposes and use raw PCM files as input and output raw fiels that are unasble for distributions. Opus will use the Ogg encapsulation, and to create playable OggOpus files we’ll need the Opus tools:
1 2 3 4 5 6 |
sudo apt-get install libflac-dev git clone git://git.xiph.org/opus-tools.git cd opus-tools ./autogen.sh ./configure make -j8 |
This will generate two utilities:
- opusenc – Converts WAV, AIFF, FLAC, Ogg/FLAC, or raw files into OggOpus files
- opusdec – Converts OggOpus files into a WAV or raw file
I’ll download the audio file used for libopus tests in the first chart of this post:
1 |
wget http://people.xiph.org/~xiphmont/demo/opus/comp48s.wav |
Let’s encode it to OggOplus:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
export LD_LIBRARY_PATH=/usr/local/lib ./opusenc comp48s.wav comp48s.opus Encoding using libopus 1.1 (audio) ----------------------------------------------------- Input: 48kHz 2 channels Output: 2 channels (2 coupled) 20ms packets, 96kbit/sec VBR Preskip: 312 [/] 00:00:43.76 43.8x realtime, 102.9kbit/s Encoding complete ----------------------------------------------------- Encoded: 1 minute and 30.82 seconds Runtime: 1 seconds (90.82x realtime) Wrote: 1272070 bytes, 4541 packets, 93 pages Bitrate: 111.162kbit/s (without overhead) Instant rates: 1.2kbit/s to 197.2kbit/s (3 to 493 bytes per packet) Overhead: 0.794% (container+metadata) |
The original file is 17.4MB, and the resulting file 1.3MB. I went to Nautilus, clicked on comp48s.opus, and the file started to play in Rhythmbox. Awesome!
Finally, let’s decode the opus file back to wav:
1 2 3 4 5 |
./opusdec comp48s.opus comp48s-new.wav Decoding to 48000 Hz (2 channels) Encoded with libopus 1.1 ENCODER=opusenc from opus-tools 0.1.8 Decoding complete. |
A quick check to play it back in Rhythmbox, it works. Perfect.
If you want to find out more, visit opus-codec.org
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.
Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress