Short Tip: Convert Ogg Vorbis file to MP3

Convert Ogg file to MP3
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. :)

Thanks maha and sb.

23 Responses to “Short Tip: Convert Ogg Vorbis file to MP3”

  1. Eike Hein Says:

    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

  2. flx Says:

    much nicer is oggplayer: it plays your oggs on your not-so-crappy mobile phone

    link: http://symbianoggplay.sourceforge.net/

  3. Constantin Says:

    Luckily I have a not-so-crappy ogg-supporting mobile audio player ;)

  4. sb Says:

    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

  5. Jesús Guerrero Says:

    “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.

  6. liquidat Says:

    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.

  7. albert2004 Says:

    In KDE you’ve got Amarok, which support converting to ie. mp3 when moving to audio player. It’s a way simpler that scripting ;)

  8. Jesús Guerrero Says:

    @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 :P ).

    By Liquidat: Nope, they don’t, but I fixed that to wordpress code tags ;)

  9. logixoul Says:

    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 :)

  10. Constantin Says:

    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 ;)

  11. liquidat Says:

    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.

  12. Constantin Says:

    Yup, I’d have bought an iAudio too, only there was none in my country.

  13. Quackerzz Says:

    In KDE you’ve got Amarok, which support converting to ie. mp3 when moving to audio player. It’s a way simpler that scripting

  14. Laerte Says:

    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.

  15. Michael R. Head Says:

    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}";
    done
    

    The 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)

  16. liquidat Says:

    Michael: Thanks for the tip.

  17. MattW Says:

    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}”;
    done
    

    Otherwise it just overwrites all the .ogg files with empty ones. Youch. Good thing I was working on a copy…

  18. liquidat Says:

    Hm, I don’t see the difference right now, can you point it out?

  19. Bull Says:

    Last line - “${file/.mp3/.ogg}” is changed to ”${file/.ogg/.mp3}”….

  20. Rajat Says:

    Do you know how to convert ogg to mp3 in VB6

  21. liquidat Says:

    Rajat, the first comment to this post mentions a program which can convert almost everything to everything else.

  22. kudos Says:

    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..)

  23. liquidat Says:

    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 :)

Leave a Reply