August 16th, 2005

How to convert from WMA to MP3

Linux, Music, by Donncha.

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

You might also like

If you like this post then please subscribe to my full RSS feed. You can also click here to subscribe by email. There are also my fabulous photos and funny videos to explore too!

Back Top

Responses to “How to convert from WMA to MP3”

  1. 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

    Scott Carlson at August 22, 2005 1:04 am
  2. 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. :)

  3. 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 ;)

  4. Nice tip. – gotta love linux for it’s flexibility. :)

  5. and did anyone bother to make it to choose appropriate bit rate and mono/stereo depending on what was in the original wma??

  6. Thanks, nice tip

  7. 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

  8. 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.

  9. 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 .

  10. 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”

  11. 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"

  12. 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"


  13. function wmatomp3 {
    lame \
    --tt "$title" \
    --ty "$year" \
    --ta "$artist" \
    --tc "$comment" \
    --tg "$genre" \
    --tl "$album" \
    --quiet -h - "$mp3file"

  14. 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
    }

  15. 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

    Jorge Bras at May 17, 2006 3:36 pm
  16. 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.

  17. …um… What if we don’t speak computer? What does all that mean?

  18. 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

  19. Excellent! Anyone want to share how to recursively traverse directories to do this? And maybe removal of the wma file following encoding completion?

    -Jonny5

  20. 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

  21. #!/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

  22. This is perfect. Thanks Donncha

  23. 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…

  24. You guys are a gr8 help. Thanks for the tips. BTW… -ao pcm -waveheader is deprecated… try -ao pcm:waveheader instead.

  25. 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

  1. Personal Bytes » Blog Archive Convert wma to mp3/ogg » (,December 31, 2005)

    [...] May the power of *nix be with you :-) Thanks to Donncha for sharing with us an easy way to convert to mp3. [...]

  2. JEDI » Blog Archive » links for 2006-08-20 (,August 20, 2006)

    [...] How to convert from WMA to MP3 at Holy Shmoly! (tags: wma) [...]

  3. WMA -> MP3 | hilpers (,January 18, 2009)

    [...] mplayer to de-WMA WMA files into PCM format and pipe the output straight into LAME, apparently: http://ocaoimh.ie/2005/08/16/how-to-…om-wma-to-mp3/ > > >Or are there proggies that’ll reconstitute WMA to wav, or something else >that [...]

Leave a Reply

Back Top


Holy Shmoly! is Digg proof thanks to caching by WP Super Cache