
In case you have an ogg vorbis file and need to transform that to a MP3 file (for example for mobile phones or crappy mobile audio players) the following command line will transform all ogg files of the directory to mp3 files. Please keep in mind that you will lose audio quality when you transform one lossy audio format to another.
for file in *.ogg;do oggdec -o - "$file"|lame -h -V 4 –-vbr-new - "$(basename "$file" .ogg).mp3";done
I am aware that there are thousand other methods – you could write entire scripts, GUIs, use other tools, and so on. But this way works for me, and I need some place to remember it. In case you wonder: if you want to increase the qualit, change the “4″ to a “2″. This of course only makes sense if you have a high quality ogg vorbis file.

December 3, 2007 at 16:28
One of the nicer ones of those thousand other methods is KDE app called soundKonverter: http://www.kde-apps.org/content/show.php?content=29024
December 3, 2007 at 16:32
much nicer is oggplayer: it plays your oggs on your not-so-crappy mobile phone
link: http://symbianoggplay.sourceforge.net/
December 3, 2007 at 16:46
Luckily I have a not-so-crappy ogg-supporting mobile audio player
December 3, 2007 at 16:48
Using CBR (constant bitrate), as you did in your script, is generally a bad idea qualitywise. If there is no special need to go CBR, like creating audio with a purpose to mux it into a video stream, it’s always advisable to use default VBR switches such as ‘-V 2 –vbr-new’ which will achieve similar size to CBR 192 but with a higher quality.
I know however, that at these bitrates there’s hardly any chance to spot a difference, but still, as you transcode, it’s better to lose as little quality as possible.
And as I’m a bit anal about “quality”, treat my words with a grain of salt
Cheers
December 3, 2007 at 17:06
“Please keep in mind that you will lose audio quality when you transform one lossy audio format to another.”
Well, that is true. But ogg is not a lousy format, because to start with: it is not a proper format.
It is just a container, just like aví. On an avi file you can have video encoded in a variety of format, mainly mpg derivatives, divx/xvid and the like.
Another example of a container format is matroska.
In an ogg file you can have streams encoded with many formats, like for example theora or flac, even dinamic streams like icecast. And of course, vorbis compresed audio. This /vorbis) was the first format that used ogg as a container, and probably because of that, some people think that ogg and vorbis are the same, when they are not.
Some of the formats used by ogg are lousy, but some others /flac comes to my mind) are loseless.
December 3, 2007 at 17:50
Eike, yes, but I wanted a solution which I could use in a script.
flx: Of course, but the post wasn’t aiming at that particular problem.
Constantin: Mine was stolen, unfortunately
Which one do you have?
sb : Thanks for the comment. I thought about the constant bitrate but then dropped it and wrote the short tip. I added your way, thx.
And: I’m only focussed on quality when it comes to the original ogg files. As long as I have them the rest doesn’t matter.
Jesús: In the post itself I wrote Ogg vorbis, I should have added “vorbis” to the headline, though. But I am very aware of the difference: I wrote most parts of the German Wikipedia entries about Ogg, Vorbis, Theora, flac and so on. I even chatted with the Xiph guys about particular bits of the articles and helped at the xiph web page once.
But thanks for the comment anyway, others might not take that for granted.
December 3, 2007 at 18:13
In KDE you’ve got Amarok, which support converting to ie. mp3 when moving to audio player. It’s a way simpler that scripting
December 3, 2007 at 18:38
@liquidat, you are right, I supposed I read that too fast..
Just to be of any use, I can contribute a mre bash-like way to do it, no need to use basename:
for file in *.ogg;do oggdec -o - "$file"|lame -h -V 4 --vbr-new - "${file/.ogg/.mp3}";done(I hope bbtags work
).
By Liquidat: Nope, they don’t, but I fixed that to wordpress code tags
December 3, 2007 at 18:46
Semi offtopic: anyone looking for a no bullshit, ogg-friendly player should check the Samsung YP-U2.
More ontopic: back when I owned an mp3-only player, it was always Amarok who helpfully converted the oggs before transfer
December 3, 2007 at 19:07
Hey, I have the YP-U2 too!
Sure, it has some quirks and you can’t put Rockbox on it, but otherwise it’s great, and supports Ogg Vorbis too
December 3, 2007 at 19:22
About Amarok: of course that works, but hey, I like my command line
Seriously, I was just looking for a quick and easy way which I could embed in a script. But thanks anyway for the GUI suggestions
And about Ogg-Vorbis players: My girlfriend also has a Samsung player which supports Ogg. I had an iAudio once, and I bought an iRiver for friends of mine. All of them are capable of playing Ogg Vorbis.
December 3, 2007 at 20:34
Yup, I’d have bought an iAudio too, only there was none in my country.
December 3, 2007 at 21:33
In KDE you’ve got Amarok, which support converting to ie. mp3 when moving to audio player. It’s a way simpler that scripting
December 4, 2007 at 0:10
Hi,
If you want more advices on mobile players, specially with ogg (vorbis, flac or speex) support, I’d recommend:
http://www.anythingbutipod.com
They have a compare (that also searchs) tool that’s very useful.
Hope you like.
Laerte.
December 15, 2007 at 21:59
But you’re missing the critical bit: tag conversion! mp3s without tags are fairly useless on portable players.
Here’s an alternative that will copy the tags over (if you have the gstreamer bad and ugly plugins installed):
for file in *.ogg; do gst-launch-0.10 filesrc location="${file}" ! oggdemux ! vorbisdec ! audioconvert ! lame quality=4 ! id3v2mux ! filesink location="${file/.mp3/.ogg}"; doneThe only limitation is that the tags are streamed in and not written in the header, so not all tools will see the tags (for example id3v2 or id3tool won’t, but rhythmbox and mpg321 will)
December 16, 2007 at 12:59
Michael: Thanks for the tip.
December 18, 2007 at 8:29
That should be
for file in *.ogg; do gst-launch-0.10 filesrc location=”${file}” ! oggdemux ! vorbisdec ! audioconvert ! lame quality=4 ! id3v2mux ! filesink location=”${file/.ogg/.mp3}”; doneOtherwise it just overwrites all the .ogg files with empty ones. Youch. Good thing I was working on a copy…
December 18, 2007 at 9:36
Hm, I don’t see the difference right now, can you point it out?
January 22, 2008 at 18:44
Last line – “${file/.mp3/.ogg}” is changed to ”${file/.ogg/.mp3}”….
April 29, 2008 at 7:13
Do you know how to convert ogg to mp3 in VB6
April 29, 2008 at 14:06
Rajat, the first comment to this post mentions a program which can convert almost everything to everything else.
May 5, 2008 at 3:08
I was looking for the same thing but five minutes of googling revealed this:
http://badcomputer.org/unix/code/sneetchalizer/
Would have written one otherwise but why put myself through the pain when this fine gentleman has produced this fine script… (and a peek through the code looks good..)
May 5, 2008 at 21:04
kudos, as written above there are man tools available. I just wanted to write down the quickest way which does not require any further downloads
July 12, 2008 at 8:05
Thanks it works just like I need it
July 18, 2008 at 6:24
Hi,
Two issues.
1. for file in *.ogg;do oggdec -o – “$file”|lame -h -V 4 –-vbr-new – “$(basename “$file” .ogg).mp3″;done
Notice the dash before “-vbr” is not a hyphen, but an n-dash. This will cause a copy/paste to fail. What works:
for file in *.ogg;do oggdec -o – “$file”|lame -h -V 2 –vbr-new – “$(basename “$file” .ogg).mp3″;done
(Note the clean double-hyphen before “vbr”.)
2. The word “quality” has lots its y.
July 18, 2008 at 6:25
The double-hyphen is not a fault of the author. It’s a fault of the comment submission process.
November 29, 2008 at 23:08
Here’s the command I used, which works better than a for/in loop when there are filenames with spaces and other garbage in them. It also works recursively:
find -type f -name ‘*.ogg’ | while read file; do echo “working on $file”; gst-launch-0.10 filesrc location=”${file}” ! oggdemux ! vorbisdec ! audioconvert ! lame quality=4 ! id3v2mux ! filesink location=”${file/.ogg/.mp3}” 2>&1 && rm “$file”; done >> /home/baron/ogg2mp3results.txt
December 4, 2008 at 13:28
Xaprb:
Thanks for that command for conversion. The only thing is that it didn’t handle spaces in the directory names (for example “Trans-Siberian Orchestra”). Here’s my minor modification which did handle them properly. I used /usr/bin/tee so that I could see the output in the terminal window as well as put the output into a file:
/usr/bin/find -type f -name ‘*.ogg’ | while read file; do echo “working on $file”; /usr/bin/gst-launch-0.10 filesrc location=”${file}” ! oggdemux ! vorbisdec ! audioconvert ! lame quality=4 ! id3v2mux ! filesink location=”`/usr/bin/dirname “$file”`/`/usr/bin/basename “$file” .ogg`.mp3″ 2>&1 && /bin/rm “$file”; done | /usr/bin/tee -a $HOME/ogg2mp3results.txt
I use absolute pathnames for the commands that are not shell-builtins for security purposes — in case someone has been able to put a trojan executable on my path. Feel free not to be as paranoid as me . . . .
December 20, 2008 at 12:14
So, I’m flying out of tomorrow and didn’t have time to get my nice beautiful RockBoxed Vorbis player ready to go (I burned up a battery and am waiting for it in the mail) so, had to prep mine, and my wife’s, back-up MP3 players for the trip… the above script came in such handy!!!!
However, the comment about tags is spot on. Well, I was fortunate enough that my file-naming is good ( it goes like “(##)_(album)_(title).ogg” and the artist name is encoded in the folder it is in). Well, I found that on my system, installing gst and ugly was… well, infeasible.
I took a chance on a lesser known app, called Picard (it is from the MusicBrainz project) and ran it on my folder of one single newly-transcoded album, and it automatically detected three of the songs correctly, and placed them in the correct album (it fingerprints the audio data directly and then presents a best-guess at metadata). It incorrectly placed half the album into a foreign release, and the rest into the EP. Well, I just drag/drop’ed the wrongly placed songs onto the correct songs in the album that was correctly identified (by now, I’ve spent 1.5 minutes in tagging) and then clicked “save metadata”.
*POOF* all songs tagged correctly. So, here’s one vote for Picard for automagical tag management. I’m not sure what it would do about a giant soup of random MP3s, though…
January 9, 2009 at 12:36
[...] found out this nice post http://liquidat.wordpress.com/2007/12/03/short-tip-convert-ogg-file-to-mp3/ showing how to convert ogg files to mp3. Had to apply some changes to the command line, so here it [...]
February 24, 2009 at 11:42
Very good script for easy conversions
Thanks a lot!!