This guide is also available in PDF format. You can download it for free from
here!
This guide focuses on showing you how to manipulate and convert various audio files using tools included in the Ubuntu repositories. It contains mostly everything you need to know to convert various formats to the free format Ogg Vorbis, including explanations on how to convert FLAC to WAV and vice-versa, convert FLAC, WAV, APE, AC3, WMA or SHN to Ogg Vorbis, edit tags from command-line for free audio formats, and much more.
The guide is divided into the following sections, so that you can click on any of them to jump directly to the chapter which is of interest to you:
Introduction to Audio Manipulation on Linux
The Setup: Tools That We Need
Converting FLAC to WAV and Vice-Versa
Converting FLAC or WAV to Ogg Vorbis
Editing Ogg Vorbis Tags
Converting FLAC or WAV to MP3
Ripping Audio CDs
Split FLAC, WAV or APE With a CUE File
Converting WMA to Ogg Vorbis
Converting APE to Ogg Vorbis or MP3
Converting AC3 to WAV Using MPlayer
Music Players
As a side note, this tutorial does not include references on how to edit or record sound (for example with Audacity or some other audio editor). Also, all the methods explained here make use of the command-line and command-line (or text user interface) tools. At the end of the guide there are several links to helpful links, a list of music players for Linux (both for GUI and CLI), as well as links to reviews for those.
Note: This tutorial works on both Debian and Ubuntu, and probably other distributions too, except for commands which pertain to the package manager (e.g. apt-get). Commands which are prefixed with sudo should be ran as root in Debian (type su, enter the root password and then type the rest of the command without the sudo part.
This guide focuses on showing you how to manipulate and convert various audio files using tools included in the Ubuntu repositories. It contains mostly everything you need to know to convert various formats to the free format Ogg Vorbis, including explanations on how to convert FLAC to WAV and vice-versa, convert FLAC, WAV, APE, AC3, WMA or SHN to Ogg Vorbis, edit tags from command-line for free audio formats, and much more.
The guide is divided into the following sections, so that you can click on any of them to jump directly to the chapter which is of interest to you:
Introduction to Audio Manipulation on Linux
The Setup: Tools That We Need
Converting FLAC to WAV and Vice-Versa
Converting FLAC or WAV to Ogg Vorbis
Editing Ogg Vorbis Tags
Converting FLAC or WAV to MP3
Ripping Audio CDs
Split FLAC, WAV or APE With a CUE File
Converting WMA to Ogg Vorbis
Converting APE to Ogg Vorbis or MP3
Converting AC3 to WAV Using MPlayer
Music Players
As a side note, this tutorial does not include references on how to edit or record sound (for example with Audacity or some other audio editor). Also, all the methods explained here make use of the command-line and command-line (or text user interface) tools. At the end of the guide there are several links to helpful links, a list of music players for Linux (both for GUI and CLI), as well as links to reviews for those.
Note: This tutorial works on both Debian and Ubuntu, and probably other distributions too, except for commands which pertain to the package manager (e.g. apt-get). Commands which are prefixed with sudo should be ran as root in Debian (type su, enter the root password and then type the rest of the command without the sudo part.
Introduction to Audio Manipulation on Linux
Free formats
In this tutorial I will focus mostly on manipulating and converting files to free formats, which in our case will be FLAC (Free Lossless Audio Codec) and Ogg Vorbis (free lossy codec), but support for MP3 is also included where it is the case. These formats are not patented and are free to use without the need to pay for using them. More details on this can be found on the official Xiph.org website.
I strongly encourage the use of free formats over those which are proprietary. First of all, using free formats will make your life easier on Linux, since all distributions include audio players which come with support for these by default, without the need to install additional codecs. There is also a drawback to this though: most portable players out there support MP3, but not Ogg. This isn't a very big issue because there are also portable players who support Ogg too in addition to MP3, and there are also solutions like Rockbox, which replaces the firmware on those players who can't read Ogg Vorbis or FLAC and adds support for those too.
The difference between lossless and lossy
Lossless formats are the ones which preserve the quality of the sound encoded at the expense of file size. Examples of such formats would be FLAC or WAV. On the other hand, lossy formats use lossy compression algorithms which create smaller files, but discard some of the audio data. However, on bitrates of 128 kbps and above the human ear cannot distinguish whether it's a lossy or a lossless sound they hear. Lossy formats include Ogg Vorbis and MP3. Use lossy to save disk space (for example for your personal music collection or for music on a portable player), and use lossless if you really need to preserve the original quality of the sound.
In this tutorial I will focus mostly on manipulating and converting files to free formats, which in our case will be FLAC (Free Lossless Audio Codec) and Ogg Vorbis (free lossy codec), but support for MP3 is also included where it is the case. These formats are not patented and are free to use without the need to pay for using them. More details on this can be found on the official Xiph.org website.
I strongly encourage the use of free formats over those which are proprietary. First of all, using free formats will make your life easier on Linux, since all distributions include audio players which come with support for these by default, without the need to install additional codecs. There is also a drawback to this though: most portable players out there support MP3, but not Ogg. This isn't a very big issue because there are also portable players who support Ogg too in addition to MP3, and there are also solutions like Rockbox, which replaces the firmware on those players who can't read Ogg Vorbis or FLAC and adds support for those too.
The difference between lossless and lossy
Lossless formats are the ones which preserve the quality of the sound encoded at the expense of file size. Examples of such formats would be FLAC or WAV. On the other hand, lossy formats use lossy compression algorithms which create smaller files, but discard some of the audio data. However, on bitrates of 128 kbps and above the human ear cannot distinguish whether it's a lossy or a lossless sound they hear. Lossy formats include Ogg Vorbis and MP3. Use lossy to save disk space (for example for your personal music collection or for music on a portable player), and use lossless if you really need to preserve the original quality of the sound.
The Setup: Tools That We Need
In this section we will install all the tools you need for this tutorial, however notice that not all of
these are needed to perform only a specific task, like converting from FLAC to Ogg Vorbis for example. In each
section I will include again only the tools needed for that particular task, so it's not absolutely necessary
to install everything listed here. That being said, here are all the packages which need to be installed:
Below is a brief overview of each package installed:
Below is a brief overview of each package installed:
- vorbis-tools - this package contains Ogg Vorbis tools: oggenc (encoder), ogg123 (Ogg Vorbis and FLAC command-line player), ogginfo (displays Ogg information), oggdec (decoder), vcut (Ogg file splitter), vorbiscomment (Ogg comment editor)
- flac - this package contains FLAC tools: flac (encoder/decoder) and metaflac (manipulates FLAC metadata)
- cuetools - this package contains tools used to manipulate CUE files; we will only need the cuebreakpoints tool from this package
- shntool - this is a utility for processing WAV files
- cdparanoia - used to rip audio CDs
- abcde - used to rip audio CDs
- mplayer - used to convert AC3 to WAV
- id3v2 - used to view or edit ID3v2 tags
- lame - free MP3 encoder
- monkeys-audio - package which contains the mac decoder for the APE format
- dir2ogg - used here to convert WMA to Ogg
Converting FLAC to WAV and Vice-Versa
Prerequisites
For this we will need to install only the flac package:
Converting FLAC to WAV (and Vice-Versa)
To convert a FLAC file to WAV we would issue the following command:
The -d switch tells flac to decode the input file specified as argument. Here's an example:
The simplest command to convert from WAV to FLAC is this:
This will create the file input_file.flac. You can also specify the output filename, e.g.:
You can also specify a compression level (from 1 to 8, default is 5). The higher the compression level,
the smaller the resulting file will be:
This will produce output_file.flac with the highest compression level (8).
For this we will need to install only the flac package:
$ sudo apt-get install flac
To convert a FLAC file to WAV we would issue the following command:
$ flac -d input_file.flac
The simplest command to convert from WAV to FLAC is this:
$ flac input_file.wav
$ flac input_file.wav -o output_file.flac
$ flac -8 input_file.wav -o output_file.flac
Converting FLAC or WAV to Ogg Vorbis
Ogg Vorbis is a patent-free, lossy audio format which is very well supported on all the major
Linux distributions. Ogg Vorbis is the format of choice for many open-source games and applications.
In the following example I'll show how to convert FLAC to Ogg Vorbis (the exact same command applies for WAV too) using several common options. For this we will use the oggenc tool, which is the official Ogg encoder:
This will produce an Ogg file called input_file.ogg using the default quality (3). The quality
can be anywhere between -1 (~ 45 kbps) and 10 (~ 500 kbps).
The default quality level is 3 (~ 112 kbps). Fractional quality levels are permitted too.
We can also specify the output file name.
For example, the following command will encode a FLAC file to Ogg Vorbis using a quality level of 6
(~ 192 kbps). The
resulting file will be called output_file.ogg:
Instead of specifying a quality factor, we can specify the bitrate:
In the following example I'll show how to convert FLAC to Ogg Vorbis (the exact same command applies for WAV too) using several common options. For this we will use the oggenc tool, which is the official Ogg encoder:
$ oggenc input_file.flac
$ oggenc -q 6 input_file.flac -o output_file.ogg
$ oggenc -b 192 input_file.flac -o output_file.ogg
Editing Ogg Vorbis Tags
Prerequisites
For this we will only need to install the vorbis-tools package, which includes the vorbiscomment tool used for editing tags:
Using 'vorbiscomment'
vorbiscomment is a utility which comes with the vorbis-tools package and which allows us to edit or remove Ogg Vorbis tags like song title, artist, album, year, track and so on. Custom fields are also possible.
Let's see how it works by adding a new tag to a song, called "TITLE", and adding a value for this tag, say "Wasted Years":
The above command will use the -t (or --tag) switch to add the tag TITLE
with the value Wasted Years, and write it (-w) to input_file.ogg. To see the result, use:
The -l switch is used to list tags in a Vorbis file. Notice that the -w switch will rewrite
the file and any existing tags will be lost. In order to append a tag to existing ones, use -a
instead of -w.
An alternate way of doing it is to read tags from a text file. For example:
And the file file.txt could contain tags, one per line, like this:
The easiest way to clear all the tags is to create an empty file, and then use vorbiscomment to read
and write the contents of it to the Ogg Vorbis file, e.g.:
What follows is a short script to remove all the tags from all Vorbis files in a directory:
And here is another script which automatically fills the TRACKNUMBER tag for each Ogg Vorbis file
in a directory:
This time we used the -a switch to append this tag to existing tags. If we would've used -w, the
file would've been rewritten and the existing tags lost.
For this we will only need to install the vorbis-tools package, which includes the vorbiscomment tool used for editing tags:
sudo apt-get install vorbis-tools
vorbiscomment is a utility which comes with the vorbis-tools package and which allows us to edit or remove Ogg Vorbis tags like song title, artist, album, year, track and so on. Custom fields are also possible.
Let's see how it works by adding a new tag to a song, called "TITLE", and adding a value for this tag, say "Wasted Years":
$ vorbiscomment -t "TITLE=Wasted Years" -w input_file.ogg
$ vorbiscomment -l input_file.ogg
An alternate way of doing it is to read tags from a text file. For example:
$ vorbiscomment -c file.txt -w input_file.ogg
ARTIST=Iron Maiden TITLE=Wasted Years ALBUM=Somewhere in Time YEAR=1986 TRACKNUMBER=2
$ touch empty_file $ vorbiscomment -c empty_file -w input_file.ogg
#!/bin/bash echo "Ogg Tag Remover" echo "Creating empty file..." touch empty_file echo "Removing all tags in Ogg files..." for i in *.ogg; do vorbiscomment -c empty_file -w "$i" done echo "Removing empty file..." rm empty_file echo "Done!"
#!/bin/bash echo "Ogg TRACKNUMBER Editor" n=1 for i in *.ogg; do vorbiscomment -t "TRACKNUMBER=$n" -a "$i" n=$((n + 1)) done echo "Done!"
Converting FLAC or WAV to MP3
Prerequisites
For encoding FLAC or WAV to MP3 we will use lame (http://lame.sourceforge.net/), a free MP3 encoder. To install it in Ubuntu type in a terminal:
To install it in Debian, add the
Debian Multimedia repositories to your /etc/apt/sources.list
file (follow the instructions on the site) and issue the following commands as root:
Converting FLAC or WAV to MP3 Using LAME
If our files are in FLAC format we will first need to convert them to WAV (e.g. flac -d input_file.flac -o output_file.wav). Next, the simplest way to convert WAV to MP3 with LAME is like this:
This will result in an MP3 file called input_file.wav.mp3 encoded at 128 kbps. You can specify
the output file name like this:
To specify a certain bitrate, use the -b switch:
Unfortunately lame doesn't support wildcards, so converting using a command such as
lame [0-9]*.wav will not work, you will have to use something like the following one-liner:
Again, do not use wildcards with lame. If for example you have two WAV files in a directory called, say,
file1.wav and file2.wav and issue the command lame *.wav, this will expand into
lame file1.wav file2.wav, and lame will interpret file2.wav as the output filename after converting
file1.wav. This will result in file2.wav being rewritten by an MP3 file.
For encoding FLAC or WAV to MP3 we will use lame (http://lame.sourceforge.net/), a free MP3 encoder. To install it in Ubuntu type in a terminal:
sudo apt-get install lame
apt-get update apt-get install lame
If our files are in FLAC format we will first need to convert them to WAV (e.g. flac -d input_file.flac -o output_file.wav). Next, the simplest way to convert WAV to MP3 with LAME is like this:
lame input_file.wav
lame input_file.wav output_file.mp3
lame -b 192 input_file.wav output_file.mp3
for i in *.wav; do lame $i; done
Ripping Audio CDs
Prerequisites
The tool for ripping audio CDs is cdparanoia (http://www.xiph.org/paranoia/). To install it use:
We will also need id3v2, an ID3v2 tag viewer and editor (this is only used by the abcde tool):
Ripping Audio CDs With cdparanoia
The simplest way to use cdparanoia is just like this:
The -B switch will tell cdparanoia to split the output into multiple WAV files. The files will have the
name starting with trackN.cdda.wav and followed by a number (e.g. track01.cdda.wav).
Additional parameters can be passed to cdparanoia, for example to rip a single track:
Or to rip, say, tracks 4-9 we would use:
You can also rip a certain track from a specified time up to another specified time:
This will rip track 5 starting at second 20 and stopping at minute 5 and 30 seconds.
The files will be in WAV format by default, so you can convert them to FLAC, to Ogg Vorbis or to MP3 if you like.
Using abcde
abcde (A Better CD Encoder) is a frontend to cdpranoia and several other tools which allows you to rip audio CDs, encode and tag the resulting files. Here's an example of using abcde:
Which will rip audio CD from device /dev/cdrom and encode the output to MP3 format.
The tool for ripping audio CDs is cdparanoia (http://www.xiph.org/paranoia/). To install it use:
sudo apt-get install cdparanoia
sudo apt-get install id3v2
The simplest way to use cdparanoia is just like this:
cdparanoia -B
Additional parameters can be passed to cdparanoia, for example to rip a single track:
cdparanoia -B 3
cdpranoia -B 4-9
cdparanoia "5[:20.00]-5[5:30.00]"
The files will be in WAV format by default, so you can convert them to FLAC, to Ogg Vorbis or to MP3 if you like.
Using abcde
abcde (A Better CD Encoder) is a frontend to cdpranoia and several other tools which allows you to rip audio CDs, encode and tag the resulting files. Here's an example of using abcde:
$ abcde -d /dev/cdrom -o mp3
Split FLAC, WAV or APE Using With a CUE File
Prerequisites
For this we will need three packages: cuetools, which contains the cuebreakpoints utility for reading CUE files, shntool, a WAV processing tool, and monkeys-audio, a package which contains the mac utility, for creating Monkey's Audio lossless files. To grab them type in a terminal:
Split FLAC/WAV Using a CUE File
A CUE file will hold the information about starting and ending time of a track, information which can be used to split larger files (like an album which comes as a single FLAC or WAV file instead of individual tracks). The command to split these is the following (I used .flac in this example, but the same goes for WAV):
You can also edit the CUE file using a text editor and alter track lengths, for example for concatenating
two melodies or more in a single one.
Split APE Using a CUE File
First we will convert our APE file to WAV:
If you have more than one APE files inside a directory, use the following one liner:
Now we can proceed and split the WAV just like we did in the section above:
For this we will need three packages: cuetools, which contains the cuebreakpoints utility for reading CUE files, shntool, a WAV processing tool, and monkeys-audio, a package which contains the mac utility, for creating Monkey's Audio lossless files. To grab them type in a terminal:
$ sudo apt-get install cuetools shntool monkeys-audio
A CUE file will hold the information about starting and ending time of a track, information which can be used to split larger files (like an album which comes as a single FLAC or WAV file instead of individual tracks). The command to split these is the following (I used .flac in this example, but the same goes for WAV):
$ cuebreakpoints cue_file.cue | shnsplit audio_file.flac
Split APE Using a CUE File
First we will convert our APE file to WAV:
$ mac input_file.ape output_file.wav -d
$ for in *.ape; do mac "$i" "$i.wav" -d; done
cuebreakpoints cue_file.cue | shnsplit output_file.wav
Converting WMA to Ogg Vorbis
Prerequisites
For this one we will need a tool called dir2ogg, which is a Python script that allows us to convert formats like MP3, M4A and WAV to Ogg Vorbis:
Converting WMA to Ogg Vorbis
Using dir2ogg is very simple:
Or, for all the WMA files in a directory:
For this one we will need a tool called dir2ogg, which is a Python script that allows us to convert formats like MP3, M4A and WAV to Ogg Vorbis:
sudo apt-get install dir2ogg
Using dir2ogg is very simple:
dir2ogg input_file.wma
dir2ogg *.wma
Converting APE to Ogg Vorbis or MP3
Prerequisites
We will need the vorbis-tools (for Ogg Vorbis encoding), lame (for MP3 encoding) and monkeys-audio (for APE) packages:
In Debian, add the Debian Multimedia repositories to install
lame.
Converting APE to Ogg Vorbis or MP3
First we will use the mac tool (the command-line APE decoder frontend) to convert APE to WAV:
If you have several APE files in a directory and you want to convert them all, use this one-liner:
Now, we'll convert WAV to Vorbis the normal way:
Or, for MP3:
We will need the vorbis-tools (for Ogg Vorbis encoding), lame (for MP3 encoding) and monkeys-audio (for APE) packages:
$ sudo apt-get install vorbis-tools lame monkeys-audio
Converting APE to Ogg Vorbis or MP3
First we will use the mac tool (the command-line APE decoder frontend) to convert APE to WAV:
$ mac input_file.ape output_file.wav -d
for i in *.ape; do mac "$i" "$i.wav" -d; done
oggenc -b 256 input_file.wav
lame -b 256 input_file.wav
Converting AC3 to WAV Using MPlayer
Prerequisites
We will need to install mplayer (http://www.mplayerhq.hu/design7/news.html):
Converting AC3 to WAV
The command we will use goes like this:
This will convert input_file.ac3 to output_file.wav using the PCM audio output.
We will need to install mplayer (http://www.mplayerhq.hu/design7/news.html):
sudo apt-get install mplayer
The command we will use goes like this:
mplayer -ao pcm:file=output_file.wav input_file.ac3
Music Players
Music players
There are many good music players for Linux, for both GUI and terminal. I'll mention a few graphical ones like:
In addition to these, there are also client-server players like MPD or XMMS2, with clients like Sonata or GMPC.
There are many good music players for Linux, for both GUI and terminal. I'll mention a few graphical ones like:
- Amarok - Very powerful and popular music player for KDE
- Rhythmbox - The default music player in GNOME
- Banshee - Powerful GTK-based music player
- Clementine - A port of the classic Amarok 1.4 to KDE4
- Jajuk - Java-based, full-featured audio player
- Qmmp - XMMS-like audio player for KDE
- Audacious - XMMS-like audio player for GNOME
- CMus - feature-rich player using ncurses text user interface
- moc - yet another music player using TUI
- mp3blaster - powerful console music player
- ogg123 - command-line player for Ogg Vorbis and FLAC
- mpg123 - command-line player for MP3 and various other formats
- mplayer - very powerful audio and video player
In addition to these, there are also client-server players like MPD or XMMS2, with clients like Sonata or GMPC.
Discussion