I have a ton of various music files on my machine that are in various states of migrating from .mp3 to different formats. The primary reason for this is because of the issue of licensing between Linux and the MP3 format. And although there are GUI tools to do nearly every job you need, there are times when the command line is still your friend. For instance, say you want to do batch jobs - the command line is good for this. Or say you want to (for whatever reason) secure shell into a remote machine and then convert your files. For whatever reason you need, it's good to know that the tools are available for the job.
The tools I am talking about are mpg123 and mpg321. Although mpg321 claims to be a drop-in replacement for mpg123, I still prefer to use both tools (the former for converting .mp3 to .wav and the latter for converting .mp3 to .ogg). And in this article you will see how simple it is (using the command line) to convert these file types.
Since we will be using the command line for the conversion, we'll install the tools from the command line. The distribution I am using for example is based on the recent, stable Debian. You will not need to add any repositories to your /etc/apt/sources.list file, because all of the tools are found on the standard repositories. To install these tools, follow these steps:
That's it. Now let's take a look at how the tools are used.
Convert .mp3 to .wav
The first conversion is to .wav. Why use .wav? First and foremost, the .wav file is not compressed and is lossless, so the sound is better. The only downfall is that the files are much bigger. So, if you have a particular file and you want to retain as much quality as you can, .wav is the format to use. Of course, in this instance we are converting a lossy file type (.mp3) so there is already diminished sound quality. But why diminish it further? To make this conversion, the command looks like this:
mpg123 -w output_file.wav input_file.mp3
Where output_file is the name of the .wav file that will be converted from the mp3 file named input_file. So let's say you want to convert the file Rush_Tom_Sawyer.mp3 to .wav. That command would look like:
mpg123 -w Rush_Tom_Sawyer.wav Rush_Tom_Sawyer.mp3
Convert .mp3 to .ogg
The .ogg format is the open source equivalent to .mp3 and is supported by many players. The .ogg format is a good format to use when creating "mix cd's" (I'm old, I still want to say "mix tapes"), because you can fit more files per CD than if you were using the .wav format. But to convert the .mp3 to .ogg the command looks like:
mpg321 Input_File.mp3 -w raw && oggenc raw -o Output_file.ogg
Let's examine the same file we converted to .wav above. The command to convert to .ogg from .mp3 would look like:
mpg321 Rush_Tom_Sawyer.mp3 -w raw && oggenc raw -o Rush_Tom_Sawyer.ogg
Now you can get crafty and create batch scripts that will allow you to do batch conversions. Naturally many will think "Why would I go through that, when I can just download a handy GUI tool like Soundconverter to do the job? Why? Because it's always smart to have the command line option around. One day you might need it.
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats (video ads) or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.