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.
Installation
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:
- Open up a terminal window.
- If needed, su to root (if you use sudo in place of root, just add sudo to the beginning of the installation commands below).
- Issue the command apt-get install mpg123 mpg321 vorbis-tools
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
Easy right?
Final thoughts
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.
Enjoyed the article?: Then sign-up for our free newsletter or RSS feed to kick off your day with the latest technology news and tips, or share the article with your friends and contacts on Facebook or Twitter.Related Articles:
Make Screenshots Of The Command LineLinux tips: Encrypting and decrypting files from command line with gpg
Join Mp3 From The Command Line
Linux Command Line Fu
Aspell: Command line spell check

You are right guys, it may occur that the quality changes. But not this is what I wanted to tell you. What I wanted to tell you is that this is not statutory! What I claim is that quality loss converting from one format to an other one is not essential. Ok, it may occur, but if you know what you do this is not always happen.
This is supported by benq as well who gave us some quotes from the vorbis faq:
“The decoded MP3 will be missing the parts of the original audio that the MP3 encoder chose to discard. The Ogg Vorbis encoder will then discard other audio components when it compresses the data. At best, the result will be an Ogg file that sounds the same as your original MP3, but it is most likely that the resulting file will sound worse…”
Thus, at best you will obtain the same quality ogg which fact is also scientifically justified by my document posted a few hours before:
https://docs.google.com/fileview?id=0BzG2hFQvTug6NWY3ZGUyMTEtYTA4Yi00NDYzLTgyZDUtZTZiNTJiMGUxOWJj&hl=en
Take Care!
“but it is most likely that the resulting file will SOUND WORSE”. Re-Encoding looses a little bit of information each time. How important depends on the listener ears. There are people that can tell on the first encode, and there would be people that can not tell after 5 encodes. But you ALWAYS LOOSE QUALITY at each re-encode. Even on the same format.
By the way Owl, you did not do the same than me because you used VBR encoding instead of CBR. Of course, it is very difficult to keep the quality using VBR after subsequent compressions. My 10 times compressed file has almost the same quality than the first compression. And the difference is only that amount you can see on the graphs I posted in the first document (because there are some):
https://docs.google.com/fileview?id=0BzG2hFQvTug6NTcyMTI3ZWQtYmYzMS00MDhmLWE3NDUtMDA2NDMxM2RmOWRl&hl=en
If it’s VBR it’s because you used VBR, since I used the exact same switches as you when encoding… As I clearly stated :)
The problem with your sound sample, Owl, is that it is full of noise-like effects. This means that every spectral components of your sound sample is almost equally presented. (You can try it to plot with the code I showed you before.) This was not my case therefore I had not to care too much about the high frequency components. The simplest solution to get essentially the same sound quality after ten times re-encoding with ogg to choose a higher bit rate because higher frequencies require higher number of sampling points. I’ve tried it with 192 and the quality was OK but you can choose even higher and I am sure you won’t here any difference.
You have also the choice to change the spectral treatment behaviour of vorbis encoder with the
–advanced-encode-option
and their properly selected parameters which helps to prevent loosing any further information after existing encoded files.
This is also a proof that you can avoid loosing information If you know what you do. So, loosing information after lossy file conversion is not statutory. But everybody speak about that it is always happen which is not true. Not always.
And do not forget that we are talking about a lot of encodings with the same encoder. In practice you need only one or two encodings. Turning to the original subject you do not have to fear of encoding any mp3 to ogg. The reverse order is problematic (as benq also stated above) but I showed you that mp3 files uses less information and ogg won’t change it after re-encoding with the same parameters.
Sorry guys, but I have to deal with my official project now.:-) But do not forget mp3 to ogg is ok. See again:
https://docs.google.com/fileview?id=0BzG2hFQvTug6NWY3ZGUyMTEtYTA4Yi00NDYzLTgyZDUtZTZiNTJiMGUxOWJj&hl=en
And take care!
Zvaral, you are the most suborn people in the world. Time after time we proved you wrong, gave you reasons, told you to try yo LISTEN to the encodes, etc. You keep telling the same BS.
EVEN THE VORBIS OFFICIAL PAGE SAYS IT IS WRONG TO DO MP3 TO VORBIS (IT IS NOT CALLED OGG).
But you keep insisting!
Yo never replied to my previous post, where i clearly show you the degradation after doing simply 99 encodes (so it is more obvious).
So, if you want to believe MP3->Vorbis is OK, do so, but do not help spread a lie.