Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

is it possible to convert mp3 to ogg via command line?

I'd like to just in a bulk swoop convert my mp3 files to ogg so i can play them in firefox without any issues.

share|improve this question
firefox should play mp3 files just fine – mchid Oct 12 '15 at 9:39
up vote 28 down vote accepted

Searching for packages matching ogg, I found dir2ogg which seems to be exactly what you want. Just

sudo apt-get install dir2ogg
dir2ogg -r /path/to/mp3s/

And it recursively finds and converts all mp3 files under /path/to/mp3s/ to ogg (assuming I read the manual correctly).

share|improve this answer

Use a combination of FFMPEG and String Manipulation.

Change into the folder where your mp3's are located:

cd mp3folder

One example is to use a simple "for" loop:

for file in *.mp3
  do ffmpeg -i "${file}" "${file/%mp3/ogg}"

The double quotes prevent spaces in the filenames being treated as 'newlines'.

ffmpeg has several options to include in the conversion like codecs, bitrate, sample size, stereo/mono, etc... The above is the most generic conversion with default settings.

share|improve this answer
Excellent. dir2ogg didn't work on wheezy but this answer worked like a charm – Onimusha Dec 18 '13 at 9:03
Excellent! best way – Isvaldo Fernandes Dec 8 '15 at 12:13
dir2ogg didn't work for me either, but I was converting m4a-->ogg. <a href="…; title=">lq</a> but the for loop above did(replacing ffmpeg with avconv). When converting m4a/mp3 to ogg with the above process, the file size increases by 9 times. However, if you first convert m4a to mp3 and then mp3 to ogg, file size only 4x larger. <pre><code>avconv -i "ManjusriMantra.m4a" "ManjusriMantra.mp3" wait avconv -i "ManjusriMantra.mp3" "ManjusriMantra.ogg" <code><pre> – afc888ny Mar 14 at 4:04

Be careful with conversions from MP3, M4A, etc. to OGG because the result may sound poor!

Warning: Both MP3 and OGG are lossy formats, unlike say WAV or FLAC. This means that they achieve their compression in great part by throwing away bits of audio information that are imperceptible to the human ear (called psychoacoustics [wikipedia])

When you encode (transcode) from one lossy format to another, most of those psychoacoustically redundant bits are already gone, so the transcoding quality will suffer and may even be "hearable" in the result. Hence, it isn't recommended to do such conversions unless absolutely necessary.

Minimize the effect if you do so by choosing a higher destination bit-rate than the source bit-rate

If you do this MP3-to-OGG conversion, you can minimize the chance of artifacts (poor quality) by using a higher destination bitrate than the source bitrate, e.g if your MP3s are at 128 kbps, try using Ogg at -q7 (variable bitrate level 7), which is usually around ~200 kbps.

You can pass the -q option to dir2ogg (available in the repos as @geirha mentioned) which should do what you want.

share|improve this answer
worth a Q&A on its own, thank you! – d3vid Feb 19 '14 at 17:37

you can use the avconv a gpl program, I did a shell for exemplify (run it on folder with the .mp3 files):

if hash avconv > /dev/null; then
    for file in *.mp3
        do avconv -i "${file}" "`echo ${file%.mp3}.ogg`";
    echo "avconv not found"

or a more simple version, without validation of avconv installation:

for file in *.mp3
    do avconv -i "${file}" "`echo ${file%.mp3}.ogg`";
share|improve this answer
NOTE: The avconv package is a recent branch/fork of ffmpeg, with similar syntax and features. – david6 Jun 13 '14 at 19:26
NOTE 2: ffmpeg is officially deprecated and explicitly mentions that you should use avconv instead. – ashes999 Dec 18 '14 at 14:06

Here's one using mplayer I think this is faster than avconv. Although, firefox should play mp3 files natively.

for f in *.mp3; do
 newname=`echo $f | tr ' ' '_' `
 mv "$f" $newname
 mplayer $f -novideo -ao pcm:file=tmp.wav
 lame -V 0 -q 0 tmp.wav ${f/.mp3/.ogg}
 rm -f tmp.wav
share|improve this answer

In case you are doing only audio use the below code [else FF doesn't play the .ogg]

for file in *.mp3;
   do ffmpeg -i "${file}" -acodec libvorbis "${file/%mp3/ogg}"; 
share|improve this answer

The parsing/replacing of mp3 by ogg is incorrect. The correct form should be:

for file in *.mp3;

   do ffmpeg -i "${file}" -acodec libvorbis "${file%mp3}ogg";

share|improve this answer

This looks like it might solve your problem

share|improve this answer
Can you elaborate on what "it" is? It would add more context to your answer and enhance its usability if the link you reference were to one day disappear =) – SaultDon Jun 7 '12 at 21:17
Was going to do as you suggest but then saw geirha's answer, which seems much better than mine so I've upvoted it. – Garry Cairns Jun 7 '12 at 21:40

There is also soundconverter. It supports both GUI and CLI and can perform bulk transformations in both modes.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.