MP3 encoding

Share your own howto's etc. Not for support questions!

MP3 encoding

Postby Rolling Stone » 2010-06-27 09:41

Since the MPEG-1 layer 3 (aka MP3) encoding is patent encumbered in some countries, most distros don't include an encoder. (A software for making MP3 files.) This is problematic because some stupid portable players only support MP3 format.

So you either have to acquire a MP3 encoder by hand (E.g. LAME) or then in some cases you could use a MPEG-1 layer 2 (MP2) encoder (E.g. TooLame, which is included in many distros) as a drop in replacement and then just rename the .mp2 files to .mp3 to fool the portable player. Using MP2 will result in somewhat bigger files.

And of course, if you're not encoding for a portable player (where disk space is very limited) you might want to use lossless compression instead for superior (original) quality (and larger file sizes). (E.g. FLAC, encoder included in most distros)
User avatar
Rolling Stone
Posts: 372
Joined: 2009-02-15 18:55
Location: Turku, Finland

Re: MP3 encoding

Postby julian67 » 2010-06-27 13:27

The easiest way in Debian to get an mp3 encoder is to add the debian-multimedia repos and install lame (or whatever you like) from there. It's still free software.

My method for converting any audio file to mp3:

Install gstreamer-tools, good bad and ugly plug-ins, and gstreamer0.10-lame


Code: Select all
#! /bin/bash
# converts to mp3 any audio file supported by gstreamer

for TRACK in "$@" ; do

MP3OUT=$(ls "$TRACK" |sed 's/\(.*\)\..*/\1/')

gst-launch filesrc location="$TRACK" ! decodebin! audioconvert ! \
lame name=enc vbr=4 vbr-quality=4 ! xingmux ! id3mux ! \
filesink location="$MP3OUT.mp3"
# mode=4  means joint-stereo (default)
# vbr=4 means use new lame settings
# vbr-quality means 0 best to 9 worst - you can change this as you like.
# id3mux means use default id3v2.3
# use gst-inspect-0.10 lame for lame options
# use gst-inspect-0.10 id3mux for id3mux options

So just run ` <file>` or ` <file> <file> <file>` for multiple files.

For a better batch audio conversion try pacpl or try another gstreamer based script which can
convert directories of almost any music files to oggvorbis
or mp3. It uses gstreamer so it can decode any file that gstreamer
can decode, including aac,flac,wv,ape,mp3,ogg,oga,wma,mpc,m4a etc
The new files are created in a new directory of the same name as the
original, in a destination of your choice. If no destination is chosen
then the new directory is nested within the original. All metadata is
retained. This includes the usual tags and also cover art and
replaygain tags. If the source files do not have replaygain tags then
it can run replaygain on the new files.
Any images (jpg,tif,bmp,png etc) in the source directory are also
copied over. Finally a simple playlist is written.
Wisdom from my inbox: "do not mock at your pottenocy"
User avatar
Posts: 4648
Joined: 2007-04-06 14:39
Location: Just hanging around

Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 1 guest