Thursday, April 30, 2009

How to convert wma to ogg

How can I convert all *.wma to *.ogg in one directory?
I first tried the approved ffmeg. That one helped me many times with good results.

Version 1:
find -name '*wma' -exec ffmpeg -i {} -acodec vorbis -ab 128k {}.ogg \;
rename 's/\.wma//' *\.wma\.ogg
(Test the renameing: rename --no-act --verbose 's/\.wma//' *\.wma\.ogg)
or

Version 2:
for i in *.wma; do ffmpeg -i "$i" -vn -acodec vorbis -ab 128k "${i/.wma}".ogg; done
# ffmpeg: -vn => novideo, -acodec vorbis => ogg-encoder, -ab set audio bitrate to 128k (64 is standard. That option doesn't seem to work with ogg :-(
# ${i/.wma} is cutting the filename $i from ".wma"

The quality gets really worse.

Best quality with version 3:

1. Step: Convert wma to flac with ffmeg
ffmpeg -i input.wma -vn -acodec flac output.flac

2. Step: Convert flac to ogg with oggenc
oggenc input.flac -q2 -o output.ogg
# -q quality 2 (1 bad .. 10 excellent)
# -o output-file

Or all in one line to convert the whole directory:
for i in *.wma; do ffmpeg -i "$i" -vn -acodec flac -y tmp.flac; oggenc tmp.flac -q2 -o "${i/.wma}".ogg; done; rm -f tmp.flac
# -y Overwrite output files.
# rm -f delete without further questions

8 comments:

Gregory said...

You really don't want to use "-acodec vorbis", instead you should use "-acodec libvorbis". The first uses the ffmpeg internal vorbis encoder, which currently delivers very poor quality.

If you're converting video I recommend ffmpeg2theora instead of ffmpeg.

Thomas Thym said...

Thanks, Gregory, for that useful hint. I will try it.

Rajesh said...
This comment has been removed by a blog administrator.
Wade said...
This comment has been removed by the author.
Wade said...
This comment has been removed by the author.
Muadib said...

Thanks! It's work great with .aac too :)

C said...

try http://www.oggconvert.com

it's an online tool, nothing to download

C said...

oops, i think that's
www.oggconvert.com