Converting Windows Media Audio files into MP3 format is rather easy with mplayer and lame. My car stereo plays MP3s, so WMA is of no use to me!
This code is based on this script but I have to wonder why they overwrote the wma file?
Piping the output of mplayer into lame is left as an easy lesson for the reader!
for i in *.wma ; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm -waveheader "$i" && lame -m j -h --vbr-new -b 160 audiodump.wav -o "`basename "$i" .wma`.mp3"; done; rm -f audiodump.wav

34 Comments
Scott Carlson on August 22, 2005 at 1:04 am.
Thanks. I recently found a similar technique for m4 files. In case you don’t want the big temporary file, you can use a fifo. Here’s my script:
#!/bin/bash
#
# Dump wma to mp3
for i in *.wma
do
if [ -f $i ]; then
rm -f “$i.wav”
mkfifo “$i.wav”
mplayer -vo null -vc dummy -af resample=44100 -ao pcm -waveheader “$i” -aofile “$i.wav” &
dest=`echo “$i”|sed -e ‘s/wma$/mp3/’`
lame -h -b 192 “$i.wav” “$dest”
rm -f “$i.wav”
fi
done
Agilo (1 comments.) on August 22, 2005 at 10:13 pm.
I would just like to thank the above(/below?) person for replying with his method of converting WMA’s to MP3′s.
It helped me.
Petar on September 14, 2005 at 11:06 am.
The latest version of mplayer complains about -ao pcm -waveheader – actually, it just needs to be replaced with -ao pcm:waveheader, and everything works again. Btw, thanks for the instruction, it is both useful and educational
iiiears on October 1, 2005 at 11:30 pm.
Nice tip. – gotta love linux for it’s flexibility.
Yarik on October 3, 2005 at 8:07 pm.
and did anyone bother to make it to choose appropriate bit rate and mono/stereo depending on what was in the original wma??
Thomas on November 16, 2005 at 11:42 am.
Thanks, nice tip
Ranchan on December 1, 2005 at 12:15 am.
For latest versions of mplayer (on Fedora Core 4), you will need the following instead:
for i in *.wma
do
filename=`basename "$i" .wma`
#Rip with Mplayer / encode with LAME
echo "Ripping $i"
mplayer -quiet -vo null -vc dummy -af volume=0,resample=44100:0:1 -ao pcm:waveheader "$i"
echo "Encoding $i to "$filename".mp3"
lame -quiet -m s audiodump.wav -o "$filename".mp3
rm audiodump.wav
done
Peter Ndiku on December 2, 2005 at 12:52 pm.
On SuSE 9.3, (MPlayer 1.0-pre7) got it working (with the FIFO) sweetly with
#!/bin/bash
#
# Dump wma to mp3
for i in *.wma
do
if [ -f "$i" ]; then
rm -f "$i.wav"
mkfifo "$i.wav"
mplayer -quiet -vo null -vc dummy -af volume=0,resample=44100:0:1 -ao pcm:waveheader:file="$i.wav" "$i" &
dest=`echo "$i"|sed -e 's/wma$/mp3/'`
lame -V0 -h -b 160 --vbr-new "$i.wav" "$dest"
rm -f "$i.wav"
fi
done
I like hq VBR, but you can change the lame settings as you like. Note the MPlayer settings have changed.
Hazza on December 29, 2005 at 7:03 am.
I recentlt download a media file with a m4. extension and found that I could’nt open it udwer Windows XP . How do I eliviate this problem ? . If ou have any solutions please email me .
Pingback: Personal Bytes » Blog Archive Convert wma to mp3/ogg »
ding (1 comments.) on January 6, 2006 at 8:25 am.
nice
bl on February 18, 2006 at 6:02 pm.
Hey, *really* use the power of Unix and skip creating the intermediate .wav file by piping mplayer output to a fifo, and having lame read that as its stdin!
e.g:
if [[ -e ./pcm_audio ]]
then
else
mkfifo ./pcm_audio
fi
function wmatomp3 {
lame \
–tt “$title” \
–ty “$year” \
–ta “$artist” \
–tc “$comment” \
–tg “$genre” \
–tl “$album” \
–quiet -h – “$mp3file”
bl on February 18, 2006 at 6:04 pm.
Let’s try that again:
Hey, *really* use the power of Unix and skip creating the intermediate .wav file by piping mplayer output to a fifo, and having lame read that as its stdin!
e.g:
if [[ -e ./pcm_audio ]]
then
else
mkfifo ./pcm_audio
fi
function wmatomp3 {
lame \
--tt "$title" \
--ty "$year" \
--ta "$artist" \
--tc "$comment" \
--tg "$genre" \
--tl "$album" \
--quiet -h - "$mp3file"
bl on February 18, 2006 at 6:05 pm.
OK, one more time, just the function:
function wmatomp3 {
lame \
--tt "$title" \
--ty "$year" \
--ta "$artist" \
--tc "$comment" \
--tg "$genre" \
--tl "$album" \
--quiet -h - "$mp3file"
bl on February 18, 2006 at 6:07 pm.
function wmatomp3 {
lame \
--tt "$title" \
--ty "$year" \
--ta "$artist" \
--tc "$comment" \
--tg "$genre" \
--tl "$album" \
--quiet -h - "$mp3file"
bl on February 18, 2006 at 6:09 pm.
ok. it doesn’t like ampersands.
following the “$mp3file” should be:
[ampersand]
mplayer -quiet -af resample=44100 -ao pcm:waveheader -ao pcm:file=pcm_audio -vc dummy -vo null -playlist $url
}
Jorge Bras on May 17, 2006 at 3:36 pm.
here is what I have done:
remove_spaces=1
tmp_file="pcm_audio"
function rm_spaces() {
mv "$1" `echo $1 | tr ' ' '_'`
}
function tomp3() {
ext=$1
for i in *.$ext
do
if [ -f "$i" ]; then
dest=`basename "$i" .$ext`
if [ "$ext" = "ogg" ]; then
echo "Encoding $i to "$dest".mp3"
transcode -q 0 -i "$i" -o "$dest" -y null,lame 2>/dev/null
else
rm -f "$tmp_file"
mkfifo "$tmp_file"
#echo "Ripping $i"
mplayer -quiet -vo null -vc dummy -af volume=0,resample=44100:0:1 -ao pcm:waveheader:file="$tmp_file" "$i" &>/dev/null &
echo "Encoding $i to "$dest".mp3"
lame --quiet -m s -h -b 192 -V0 --vbr-new "$tmp_file" "$dest".mp3
# remove temp file
rm -f "$tmp_file"
fi
# remove spaces
if [ $remove_spaces = 1 ]; then
rm_spaces "$dest".mp3
fi
fi
done
echo "done."
}
case "$1" in
ogg)
tomp3 ogg
;;
wma)
tomp3 wma
;;
*)
echo "Usage: tomp3.sh wma|ogg"
exit 1
esac
exit 0
Michael on July 25, 2006 at 3:05 pm.
Thanks. I had to burn Audio CDs with 3rd party Windows programs then Rip those in unix to get the MP3 formats. The above bashes help a lot.
Pingback: JEDI » Blog Archive » links for 2006-08-20
Wilson on March 13, 2007 at 10:09 pm.
…um… What if we don’t speak computer? What does all that mean?
Luke on June 5, 2007 at 4:31 pm.
Sorry Wilson, it probably means you are on the completely wrong page because this is how to convert WMA to MP3 files for Linux and if you don’t speak computer then I very much doubt you are a Linux user
Jonny5 on June 26, 2007 at 3:58 am.
Excellent! Anyone want to share how to recursively traverse directories to do this? And maybe removal of the wma file following encoding completion?
-Jonny5
Bernhard on August 18, 2007 at 12:14 pm.
Here is a similar script I made.
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
You can easyly encode other files with it, just change the two functions on the top to do this.
I really hope somebody will find this script usefull, 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
Tomas on February 14, 2008 at 2:33 pm.
#!/bin/bash
if [ $# -eq 0 ]
then
echo “Usage: `basename $0` FILE [FILE]…”
exit 1
fi
for source in “$@”; do
if [ -f "$source" ]; then
base=${source%.*} # remove suffix
base=`echo “$base” | tr ‘[A-Z]‘ ‘[a-z]‘`; #remove uppercase
base=`echo “$base” | tr ‘ ‘ ‘_’`; #remove spaces
tmp=$base.wav
dest=$base.mp3
if [ -e $tmp ]; then
echo “Could not create temporary file $tmp: file exists”;
exit 1;
fi
echo “Encoding $base.mp3″
rm -f $tmp
mkfifo $tmp
#Rip with Mplayer / encode with LAME
mplayer -quiet -vo null -vc null -ao pcm:waveheader:file=$tmp “$source” &>/dev/null \
& lame –quiet -m s $tmp -o $dest;
stat=$?
rm -f $tmp
if [ $stat -ne 0 ]; then
echo “Interupted”
exit $stat
fi
fi
done
thesraid (2 comments.) on February 22, 2008 at 11:08 am.
This is perfect. Thanks Donncha
Touffe on March 10, 2008 at 7:10 pm.
Yep,
Thanks since i”m using a “Peter Ndiku customed” code right now to do… , you guess ?
Sure that’s … Pop Corn.
So thanks “Mesdames, Mesdedoiselles, Messieurs” to share, bloggy style…
AbeTheRabe on June 12, 2008 at 8:04 am.
You guys are a gr8 help. Thanks for the tips. BTW… -ao pcm -waveheader is deprecated… try -ao pcm:waveheader instead.
Pingback: WMA -> MP3 | hilpers
Dave on May 29, 2009 at 7:56 pm.
Hi all,
There is a nautilus script for this in the Ubuntu repo’s.
sudo apt-get install nautilus-script-audio-convert
Right click file then convert, nice n’ easy.
Dave
szymon (1 comments.) on May 20, 2010 at 9:01 am.
Thanks to this forum I managed to adapt the method to Mac OS. I used the script of Bernhard. On macs, the main difficulties are involved in installing mplayer. I described all the steps here: http://www.mimuw.edu.pl/~szymtor/wma2mp3.html. Hope its useful!
Wannabegeek on May 21, 2010 at 9:27 pm.
Awesome page !
Just learning how to script this year and am so glad I switched to Linux.
Been making a playlist for a big party from files of all types and it’s great to do everything from the terminal !
thanks for al the scripts
wbg
Carlox on November 24, 2010 at 9:29 am.
I’ve been struggling to find a way to do this without mplayer.
It’s been a pain the the a** to get it to a reasonably productive state, but this is how it goes:
1-run the command below to generate a script which will convert your files
2-check the script for apostrophes or single quites or double quotes in the names of your files
3-run the script
find -L /path/to/your/mp3/library -iname *.wma -exec echo 'vlc -v "{}" --sout '\'#transcode{acodec=mp3}:standard\{access=file,dst=\"{}.mp3\",mux=ffmpeg\}\''' \; >> batch_wma2mp3.sh; chmod u+x batch_wma2mp3.sh;igor2011 on April 14, 2011 at 8:01 pm.
this works w/latest Ubuntu & mplayer
#!/bin/bash
#
# Dump wma to mp3
for i in *.wma
do
if [ -f $i ]; then
rm -f $i.wav
mkfifo $i.wav
mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader $i -ao pcm:file=$i.wav &
dest=`echo $i|sed -e ‘s/wma$/mp3/’`
lame -h -b 192 $i.wav $dest
rm -f $i.wav
fi
done
Sascha Ziemann on June 26, 2011 at 10:46 am.
You don’t need sed. Bash has all the functionality you need. And use trap to remove temporary files:
#! /bin/bash
set -eu
TMP=tmp.wav
trap 'rm -f "$TMP"' EXIT
mkfifo "$TMP"
for WMA in "$@" ; do
MP3=${WMA%.wma}.mp3
mplayer -quiet -vo null -vc dummy -af resample=44100 -ao "pcm:waveheader:file=$TMP:fast" "$WMA" &
lame -h -b 192 "$TMP" "$MP3"
done