Building MP3 support into Sox

I rip all my old CDs as MP3s now.  I used to rip as Ogg Vorbis, both for the higher quality, and because Ogg isn’t a patent-encumbered format, but there are just too many music applications (both software and embedded systems, such as the Netgear MP-101 wireless music streamers I picked up cheap to scatter around the house) that don’t understand Ogg, so I gave up.  MP3 it is.

Now, I’m trying to put together a simple script to merge an MP3 playlist into a single MP3.  Sox should do the trick … but it doesn’t come with built-in MP3 support (for obvious reasons).  Here’s what I did to build MP3 support into Sox — many thanks to a good post by Michael Walma on the Ubuntu Forums.

First, make sure you have what you’ll need.  LibLAME is the library for encoding MP3s — your specific version may vary from what’s below (use Synaptic Pkg Mgr to check what’s available with a search on “lame” if in doubt).  Be sure that you have universe, multiverse and restricted enabled in your package sources (/etc/apt/sources.list), as anything MP3-related is going to come from the non-standard locations.

sudo apt-get install sox liblame0 liblame-dev
sudo apt-get build-dep sox

Switch to where you’re going to build it (e.g., cd /usr/local/src).

sudo apt-get source sox

Unpack the source and switch to the source directory (your version is likely to vary):

sudo dpkg-source -x sox_14.0.0-5.dsc
cd sox-14.0.0

Now you need to enable LAME support:

sudo vi debian/rules

And comment out the line that reads:

DEB_CONFIGURE_EXTRA_FLAGS := --disable-lame

Build it:

sudo dpkg-buildpackage -b

Back up to the parent directory (cd ..) and install the newly-built packages.  For me, only new Sox packages were in the directory, so I just swept them up together.  Otherwise, you’d need to do them one by one, or with a filter such as *sox*.deb:

sudo dpkg -i *.deb

And, now, you should be able to confirm that you have support with:

sox -h

Success!

4 thoughts on “Building MP3 support into Sox”

  1. Thanks. This beats compiling sox from the tarball.

    Just a few notes, relevant to Ubuntu 9.10:

    liblame0 and liblame-dev don’t seem to be in the repositories. However,

    libmp3lame and libmp3lame-dev are there.

    In debian/rules I did not find –disable-lame, but I did find

    –without-mp3

    Editing that out worked.

    Finally, when I initially ran

    dpkg-buildpackage -b

    I found a whole host of dependencies that had to be installed. Most of these were -dev packages. I’m not going to list them all here, since the packages you see will depend on the state of your machine when you do the build. However, be prepared to

    apt-get install all the packages buildpackage says you’ll need.

    Interestingly, when the compile was going on I saw several messages saying that certain dependencies were not needed.

    Anyway, after all this, my copy of sox now supports mp3 files. Thanks.

  2. OK, here’s a problem. I installed the sox-related .deb files as outlined above. The next time I ran “apt-get update” I was “offered” (as in one you can’t refuse) the option to update my all my sox files.

    And, of course, the updated sox files don’t have mp3 support.

    Any way to take all of the sox .deb files out of update’s search?

  3. Thanks. Just a few notes, relevant to Ubuntu 10.10:
    – Install libmp3lame and libmp3lame-dev instead liblame0 and liblame-dev
    – In debian/rules edit “–without-lame” to “–with-lame”

    And follow the post rules above.

    Thanks by the excelent post.

  4. Running ubuntu 10.04 here still and using your instructions and Hicker’s changes I was able to get mp3 support. Thanks!

Leave a Reply

Your email address will not be published.

two × four =