jump to navigation

WMA to OGG file conversion September 29, 2005

Posted by Carthik in snippets, ubuntu.
trackback

Karl Hegbloom was kind enough to post to the ubuntu-users mailing list wanting to share his script to convert .wma files to .ogg files. The conversions needs the mplayer and the oggenc packages to be installed on your system. The script is pasted below:

#!/bin/sh

# Convert a .wma to an .ogg using ‘mplayer’ and ‘oggenc’.

#

# Public Domain

set -e

IN=$1

shift

if [ -z “${IN}” ]; then

IN=-

WAV=audio.wav

else

WAV=$(basename ${IN} .wma).wav

fi

mplayer -vc dummy -vo null -ao pcm:waveheader:file=${WAV} ${IN}

FILEDAT=$(file ${WAV})

BITS=$(echo ${FILEDAT} | sed -e ‘s/.*\(8\|16\|32\) bit.*/\1/’)

if echo ${FILEDAT} | grep -q mono; then

CHANS=1

else

CHANS=2

fi

oggenc -R 44100 -B ${BITS} -C ${CHANS} ${WAV} >/dev/null

rm -f ${WAV}

Comments»

1. Donncha - September 29, 2005

I posted a script that converted from wma to mp3 a while back.
This script looks a lot more complete though! Next time I need to convert files I’ll look back here! 🙂

2. ubuntonista - September 29, 2005

It is nice since you can save it for later as a .sh script, but your method is cool too – it is so short, and simple 🙂

3. Pascal - September 29, 2005

This is extremely usefull to many windows migraters. May I suggest to write a howto on implementing the script for newbies in the Linux world?

Cheers.
Pascal

4. robotgeek - September 30, 2005

For those who may be wondering, the ‘oggenc’ program may be obtained by a ‘sudo apt-get install vorbis-tools’

5. UbuWu - October 4, 2005

For those running breezy, there is a nice gui program called soundconverter that can do this.

6. Art - October 14, 2005

Just a note that wma files with spaces in the name will cause an error with this script.

Is there a script fix or do we just need to rename the files before running the script?

7. Alisdair - November 18, 2005

Just guessing, but I think you need to put quotes around ${IN} and ${WAV}, so that

mplayer -vc dummy -vo null -ao pcm:waveheader:file=${WAV} ${IN}
becomes
mplayer -vc dummy -vo null -ao pcm:waveheader:file=”${WAV}” “${IN}”

and

oggenc -R 44100 -B ${BITS} -C ${CHANS} ${WAV} >/dev/null
becomes
oggenc -R 44100 -B ${BITS} -C ${CHANS} “${WAV}” >/dev/null

and

rm -f ${WAV}
becomes
rm -f “${WAV}”

Personally though, I’d just replace the spaces with underscores.

8. Brad Pitcher - May 3, 2006

If you want to start a whole directory converting and then forget about, use this simple for loop:
for f in *.wma; do “$f”; done;

Of course don’t forget the final step after the converting is done:
rm *.wma
😉

9. Brad Pitcher - May 3, 2006

oops, my “scriptname here” between the “do” and the “$f” got edited out because I used less-than/greater-than signs.

10. Alejandro Salamanca - September 7, 2006

Really a good script!
However, when try with filenames with spaces, the script go down. A few bytes fix it.

#!/bin/sh
# Convert a .wma to an .ogg using mplayer and oggenc.
#
# Public Domain
set -e
IN=$1
echo $IN
shift
if [ -z “${IN}” ]; then
IN=-
WAV=audio.wav
else
WAV=$(basename “${IN}” .wma).wav
fi
mplayer -vc dummy -vo null -ao pcm:waveheader:file=”${WAV}” “${IN}”
FILEDAT=$(file “${WAV}”)
BITS=$(echo ${FILEDAT} | sed -e ‘s/.*\(8\|16\|32\) bit.*/\1/’)
if echo ${FILEDAT} | grep -q mono; then
CHANS=1
else
CHANS=2
fi
oggenc -R 44100 -B ${BITS} -C ${CHANS} “${WAV}” >/dev/null
rm -f “${WAV}”

Thx Karl, thx ubuntonista.

Regards
Alejandro Salamanca
RedCetus

11. blog.teranetworks.de - September 14, 2006

Convert WMA to OGG

Screw those evil M$ formats!
(You’ll need (media-sound/)vorbis-tools for this to work)
#!/bin/sh
# Convert a .wma to an .ogg using mplayer and oggenc.
#
# Public Domain
set -e
IN=$1
echo $IN
shift
if [ -z “${IN}” ]; then
IN=-
WAV=audio.wav
el…

12. Bernhard - August 18, 2007

Here is a similar script I made to encode mp3.
It can recursively look for files in subdirectories by passing -r, as well as it can remove the wma file for you by passing -d. The script does not need to remove any whitespaces, so you can use nice file names! ;D

It is a bit too long to post it here, so plz use this link: http://88.198.16.39/seek/make-mp3

If you want to create .ogg vorbis files, just change the second functions on the top to use oggenc.

I hope somebody will find this script usefull really, since it’s one of the first shellscripts I made. (filenames with whitespaces are cruel if you don’t know how to handle it ^^;)

Please send a mail if you have some improvements and/or better ideas.

Have a lot of fun!
Bernhard

13. chad - September 13, 2008

Bernhard – the top of the script needs to be /bin/bash not /bin/sh or you get an error on the ‘function’ lines.

14. Chris - May 22, 2010

http://www.oggconvert.com

online tool to convert ogg files, no downloads

works better on smaller files because it’s web based

15. Tonya Henson - May 26, 2010

You can also go too http://www.oggconvert.com/ to convert OGG files to MP3, AAC, FLAC, OGG, WMA, M4A, WAV online. I hope its big help.

16. Tonya Henson - May 27, 2010

You can also go to http://www.oggconvert.com/ to convert OGG files to MP3, AAC, FLAC, OGG, WMA, M4A, WAV online. I hope its big help.

17. seks izle - September 29, 2010

I posted a script that converted from wma to mp3 a while back.
This script looks a lot more complete though! Next time I need to convert files I’ll look back here

18. arkadaş - August 6, 2011

teşekkürler paylaşım için çok hoş olmuş


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: