Convert MP3 to OGG in linux

There has been occasion where I've needed to convert MP3 to OGG. I know, I know, I know, it's never a good idea to convert a lossy format to another lossy format, but sometimes it's unavoidable. I came up with the following command to do just what I needed. I had to include --downmix and -b 32 for what I was doing, but they are likely not required. This just tells mpg321 to write to STDOUT in raw wav format, and oggenc to read the raw wave form from STDIN.

mpg321 input.mp3 -w - | oggenc -o output.ogg -
Leave A Reply - 32 Replies
Replies
September 17th 2005 - Dragan Sipka

Hi there,

First of all, thanks for info. I would like to post what worked on my debian (testing) box:

  1. apt-get install mpg321 vorbis-tools (If you don't have them on your machine) Note: If you get error, check that you have contrib and non-free depositories in your sources list

2.Code: mpg321 input.mp3 -w raw && oggenc raw -o output.ogg Note: raw is just a file name, it could be anything you want...

Regards,

Dragan

February 16th 2006 - Anoop.R.S

Thank you for the information.But I don't feel any diffrence in quality in convering mp3 to ogg

August 2nd 2006 - gbmorrison

Thanks a lot for the erudite work on this--it was relatively easy to implemement, especially for Linux. I noticed that the bitrate typically declines only to about 110-120 kbps from 128 kbps with this conversion, instead of big loss to about 64 kbps. It would be nice if someone would write an automated task for this process for an album (folder) or even a whole collection. Currently, I use a text file with a line for each mpg command for each song in a folder--a sort of template that I select all/copy/paste into the terminal window and punch "Enter." I like oggs because of quality compression and Noatun. I do archive the original source mp3s (from e-music) on both CD and DVD (I'm not totally insane).... I also archive the oggs (and, now the templates) similarly (I really hate re-doing stuff). Thanks a lot!

August 10th 2006 - julian

Hi, This works nicely for me.

For those running Fedora Core 5+ GNU/Linux, mpg321 is available from the Livna repository. Depending on your setup: $ yum --enablerepo=livna install mpg321

September 2nd 2006 - Nagata

Yo! in reply to gbmorrison i was here searching the same thing, and catch this: http://freshmeat.net/projects/dirogg/ About: dirogg is a script to migrate your entire music collection to the Ogg Vorbis format. It's a recursive script, meaning that you run it from the top level of your music directories, and it will automatically recurse and convert all MP3 files to Ogg.

September 19th 2006 - strychnine

mp3 to ogg is VERY useful for Icecast, info saved me from buying more asprin

April 28th 2007 - KNRO

Thanks, I needed to do this. I have a box that can't play MP3s, and it's a huge headache to get MP3 support running as my box is never connected to the net! Btw, I didn't notice any differences in 'quality'.

May 11th 2007 - adsims2001

Converting a compressed format to another compressed format will improve the quality of the sound. The extra quality comes when you encode your new sound in OGG format.

May 30th 2007 - boz

you can't increase the quality by applying another form of compression. There will be a slight loss of quality, but if you can't tell, I guess it doesn't matter.

June 1st 2007 - Trapper

I used dirogg in Fedora 7 to batch convert a multitude of MP3's to OGG. Worked just great.

October 16th 2007 - srikanth

i am trying to use icecast. so had to convert my existing mp3 tracks to ogg. used mp32ogg command line script. needs mpg123, oggenc. 'hope this info useful.

January 3rd 2008 - inseino
February 11th 2008 - Jon

I use mp32ogg and it works great. That script can convert a whole directory tree recursively and it will also transfer the meta information (artist, album, track, song title, etc). It is easy to use and has other nice features. Details here: <a href=http://blog.goodcamel.com/?p=3>http://blog.goodcamel.com/?p=3

March 11th 2008 - nico

"it's never a good idea to convert a lossy format to another lossy format"

OGG is not a lossy format. It can be lossy or lossless, depends what codec you use. It's lossy with Vorbis but lossless if you use FLAC.

April 14th 2008 - pnk

Hi!!! Thanks for the info. Difinitely a must have for a newbee in opensourse. More Power!!!

August 16th 2009 - stybla

helpful command. thx.

April 7th 2010 - Rabbit Jamaica

Brilliant, appreciated.

May 21st 2010 - Chris

try http://www.oggconvert.com

online tool, nothing to download

as long as it's just an mp3... works pretty well

August 16th 2010 - Pawel

! /bin/bash

echo "this script converts all *.mp3 in current directory to new directory 'mp3_outOGG'"

mkdir mp3outOGG for i in *.mp3; do mv "$i" `echo $i | tr ' ' ''` echo $i

lame -m s -h -b 160 $i -o mp3_outOGG/$i

mpg321 $i -w raw && oggenc raw -q 7 -o mp3_outOGG/$i

mplayer $i -ao pcm:file=tmp.wav oggenc tmp.wav -q 7 -o mp3_outOGG/$i.ogg rm -f tmp.wav

done

January 8th 2012 - Bob

^ That works

April 2nd 2012 - taojoannes

"It would be nice if someone would write an automated task for this process for an album (folder) or even a whole collection."

[code] cd mp3dir for FILE in *mp3 do mpg321 ${FILE} -w - | oggenc -o ${FILE%mp3}ogg done [/code]

February 20th 2013 - Anthony Brown

To automate this change to directory where mp3 are:

export SAVEIFS=$IFS IFS=$(echo -en "nb") for file in *.mp3; do mpg321 $file -w raw | oggenc raw -o $file.ogg; done export IFS=$SAVEIFS

February 20th 2013 - Anthony Brown

To automate this if the file name have spaces:

export SAVEIFS=$IFS IFS=$(echo -en "nb") for file in *.mp3; do mpg321 $file -w raw | oggenc raw -o $file.ogg; done export IFS=$SAVEIFS

February 20th 2013 - Anthony Brown

My previous post didn't come out correct. In the IFS=$(echo -en "nb") there should be a backslash before and after n in the "nb".

February 21st 2013 - Anthony Brown

This is a try at correcting my previous post.

export SAVEIFS=$IFS IFS=$(echo -en "\n\b") for file in $file; do mpg321 $file -w raw | oggenc raw -o $file.ogg; done rm raw export IFS=$SAVEIFS

February 21st 2013 - Anthony Brown

Previous post was incorrect:

export SAVEIFS=$IFS export IFS=$(echo -en "\n\b") for file in *.mp3; do mpg321 $file -w raw | oggenc raw -o $file.ogg; done rm raw export IFS=$SAVEIFS

February 21st 2013 - Anthony Brown

To convert every .mp3 in your home directory to a directory in your home directory called "music ogg". My home directory is /home/groundup so we will use that. Change as need.

mkdir ~/music ogg export SAVEIFS=$IFS export IFS=$(echo -en "\n\b") for file in $(find /home/groundup | grep .mp3); do mpg321 $file -w raw | oggenc raw -o ~/music ogg/$file.ogg; done rm raw export IFS=$SAVEIFS

February 21st 2013 - Anthony Brown

Forgot to use html escapes.

mkdir ~/music\ ogg export SAVEIFS=$IFS export IFS=$(echo -en "\n\b) for file in $(find ~/ | grep .mp3); do mpg321 $file -w raw | oggenc raw -o ~/music\ ogg); done rm raw export IFS=$SAVEIFS

February 21st 2013 - Anthony Brown

Final correction hope

mkdir ~/music\ ogg export SAVEIFS=$IFS export IFS=$(echo -en "\n&#92b") for file in $(find ~/ | grep .mp3); do mpg321 $file -w raw | oggenc raw -o ~/music\ ogg/$file.ogg); done rm raw export IFS=$SAVEIFS

February 21st 2013 - Anthony Brown

This is the final correction

mkdir ~/music\ ogg export SAVEIFS=$IFS export IFS=$(echo -en "\n\b") for file in $(find ~/ | grep .mp3); do mpg321 $file -w raw | oggenc raw -o ~/music\ ogg/$file.ogg; done rm raw export IFS=$SAVEIFS

February 21st 2013 - Anthony Brown

My previous final was incorrect

mkdir ~/music\ ogg export SAVEIFS=$IFS export IFS=$(echo -en "\n\b") for file in $(find ~/ | grep ".mp3$"); do mpg321 $file -w raw && oggenc raw -o ~/music\ ogg/$file.ogg; done rm raw export IFS=$SAVEIFS

December 9th 2018 - daveclark966

I use Avdshare Audio Converter to Convert OGG file or any other audio format to MP3, WAV, FLAC, etc as well as convert OGA file.

All content licensed under the Creative Commons License