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 2005-09-17 07:24pm - No Email - Logged IP: 69.193.40.107

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 2006-02-16 08:09pm - No Email - Logged IP: 202.83.58.137

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

gbmorrison 2006-08-02 03:00am - No Email - Logged IP: 68.12.132.40

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 2006-08-10 01:10am - No Email - Logged IP: 66.91.90.58

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 2006-09-02 05:57am - No Email - Logged IP: 124.100.72.40

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 2006-09-19 05:21pm - No Email - Logged IP: 68.205.18.22

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

KNRO 2007-04-28 02:41pm - No Email - Logged IP: 62.150.44.180

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 2007-05-11 07:06pm - No Email - Logged IP: 67.167.105.191

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 2007-05-30 10:24am - No Email - Logged IP: 67.50.43.86

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 2007-06-01 11:35am - No Email - Logged IP: 71.100.181.200

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

srikanth 2007-10-16 03:01am - srikanth@... - Logged IP: 122.164.84.100

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 2008-01-03 01:10am - No Email - Logged IP: 122.104.239.113
Jon 2008-02-11 03:19pm - No Email - Logged IP: 72.0.207.238

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: http://blog.goodcamel.com/?p=3

nico 2008-03-11 06:52pm - No Email - Logged IP: 139.80.121.189

"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 2008-04-14 06:08pm - No Email - Logged IP: 222.127.171.187

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

stybla 2009-08-16 12:36pm - ltjackal@... - Logged IP: 78.110.208.218

helpful command. thx.

Rabbit Jamaica 2010-04-07 12:31pm - No Email - Logged IP: 208.131.189.220

Brilliant, appreciated.

Chris 2010-05-21 08:53pm - No Email - Logged IP: 70.126.119.201

try http://www.oggconvert.com

online tool, nothing to download

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

Pawel 2010-08-16 11:39pm - No Email - Logged IP: 83.69.67.18

! /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 2012-01-08 02:21am - No Email - Logged IP: 67.251.12.65

^ That works

taojoannes 2012-04-02 10:46am - No Email - Logged IP: 71.43.26.34

"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 2013-02-20 08:45am - No Email - Logged IP: 74.72.164.85

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 2013-02-20 08:51am - No Email - Logged IP: 74.72.164.85

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 2013-02-20 08:55am - No Email - Logged IP: 74.72.164.85

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 2013-02-21 10:02am - No Email - Logged IP: 74.72.164.85

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 2013-02-21 10:05am - No Email - Logged IP: 74.72.164.85

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 2013-02-21 10:41am - No Email - Logged IP: 74.72.164.85

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 2013-02-21 10:46am - No Email - Logged IP: 74.72.164.85

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 2013-02-21 10:50am - No Email - Logged IP: 74.72.164.85

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 2013-02-21 10:57am - No Email - Logged IP: 74.72.164.85

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 2013-02-21 12:02pm - No Email - Logged IP: 74.72.164.85

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 2018-12-09 10:31pm - No Email - Logged IP: 69.163.33.50

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