James Slocum


A random collection of thoughts on a variety of topics

“Installing opus-1.0.1 and libogg-1.3 on Ubuntu 12.04”


Recently I have been looking into Opus, a really awesome audio codec that is optimized for well… everything. It’s good for streaming audio, and storage audio. It can handle high bitrate music, and low bitrate mono voice recordings. The streaming optimizations make it very robust against packet loss which is a huge plus for live audio content. You can find the full specification for the codec in RFC-6716

To install it on ubuntu 12.04, you will need to install it from source.

To compile any software in Ubuntu you must have build-essential installed. You can install that with the apt-get command.

sudo apt-get install build-essential

If you haven’t done so already grab a copy of opus-1.0.1. Extract the files, configure, make, and make install.

tar -zxvf opus-1.0.1.tar.gz
cd opus-1.0.1
./configure --prefix=/usr
sudo make install

If you run into trouble check out the README document.

One you have libopus installed, you will want to install opus-tools to use the reference encoder and decoder provided. However to do this requires that libogg be updated since Ogg is the container of choice for Opus audio. The default version of libogg that ships with Ubuntu is 1.2.2. opus-tools requires version 1.3 or greater. To start grab a fresh copy of libogg-1.3. I already had a copy of libogg-1.2.2 installed and I want to replace it with libogg-1.3. Ubuntu has a strange layout for libraries, so to do that I will install libogg-1.3 like “normal” then copy the new .so file to /usr/lib/x86_64-linux-gnu directory and run ldconfig. This will keep the old library just in case, but update the references to libogg to use the new library.

tar -zxvf libogg-1.3.tar.gz
cd libogg-1.3
./configure --prefix=/usr
sudo make install
cd /usr/lib
cp libogg.so.0.8.0 x86_64-linux-gnu/
sudo ldconfig

Now you should see two versions of libogg (if you already had the default one installed), and libogg.so.0 should point to the newer one.

lrwxrwxrwx 1 root root 15 Nov 26 18:27 libogg.so.0 -> libogg.so.0.8.0
-rwxr-xr-x 1 root root 65971 Nov 26 18:27 libogg.so.0.8.0
-rw-r--r-- 1 root root 26776 Aug 12 2011 libogg.so.0.7.1
-rw-r--r-- 1 root root 26816 Aug 12 2011 libogg.a
lrwxrwxrwx 1 root root 15 Aug 12 2011 libogg.so -> libogg.so.0.7.1

Note: If you didn’t already have a copy of libogg installed, you can skip the last 3 steps in the above instructions.

Now it is possible to compile and install opus-tools. Grab a copy of opus-tools if you haven’t done so already. Then its the usual extract, configure, make, and make install.

tar -zxvf opus-tools-0.1.5.tar.gz
cd opus-tools-0.1.5
sudo make install

Now you should have 3 new tools. opusenc, opusdec, and opusinfo. opusenc is used to encode a wav or raw PCM file into an opus file. opusdec will decode an opus file and either play it out, or you can write the decoded data to a file. opusinfo will tell you about an opus file. I was shocked at sound quality this codec could produce with a low bitrate. I converted a 128Kbps mp3 file to a 48Kbps opus file and could hardly tell the difference.

mpg123 -s "06 - Me And You.mp3" | opusenc --bitrate=48 --raw - "Me and You.opus"

To play this out in ubuntu (which uses pulse audio) you need to use pacat

opusdec “Me and You.opus” - | pacat

Of course converting from an MP3 already leaves you with a lossy source. I recommend converting some native flac files for a better test as flac is a lossless codec. Check out some different bitrates and hear the difference for yourself!

comments powered by Disqus