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
Dragan Sipka September 17th 2005

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

Anoop.R.S February 16th 2006

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

gbmorrison August 2nd 2006

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!

julian August 10th 2006

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

Nagata September 2nd 2006

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.

strychnine September 19th 2006

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

KNRO April 28th 2007

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

adsims2001 May 11th 2007

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.

boz May 30th 2007

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.

Trapper June 1st 2007

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

srikanth October 16th 2007

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.

inseino January 3rd 2008
Jon February 11th 2008

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

nico March 11th 2008

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

pnk April 14th 2008

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

stybla August 16th 2009

helpful command. thx.

Rabbit Jamaica April 7th 2010

Brilliant, appreciated.

Chris May 21st 2010

try http://www.oggconvert.com

online tool, nothing to download

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

Pawel August 16th 2010

! /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

Bob January 8th 2012

^ That works

taojoannes April 2nd 2012

"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]

Anthony Brown February 20th 2013

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

Anthony Brown February 20th 2013

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

Anthony Brown February 20th 2013

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

Anthony Brown February 21st 2013

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

Anthony Brown February 21st 2013

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

Anthony Brown February 21st 2013

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

Anthony Brown February 21st 2013

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

Anthony Brown February 21st 2013

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

Anthony Brown February 21st 2013

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

Anthony Brown February 21st 2013

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

daveclark966 December 9th 2018

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