Note for English Readers

If I write the articles in Indonesian, I will write a summary in English so that you can read my articles too. After you read the summary and you feel that you need more information about that, please do not hesitate to contact me via e-mail that can be found in my profile.

Thank you for reading my blogs.

Saturday, January 29, 2011

Converting wma to mp3

Hi Readers,

This week, I got a bunch of wma files from my friend and I want to convert all into mp3 format for a reason (if you are linux user, you have known what my reason is). After I search on internet, I found a simple script from Linux Questions that can be used for converting wma format to mp3 format. For making this script works in your system, you need mplayer (already in slackware package) and lame (you can find slackbuild scripts for lame on http://slackbuilds.org). In order to make me comfortable when using this script, I make a little modification on this script, that is:

#!/bin/bash

current_directory=$( pwd )

#remove spaces
for i in *.wma; do mv "$i" `echo $i | tr ' ' '_'`; done

#Rip with Mplayer / encode with LAME
for i in *.wma ; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader $i && lame -m s audiodump.wav -o $i; done

#convert file names
for i in *.wma; do mv "$i" "`basename "$i" .wma`.mp3"; done

#add spaces as origins (if there are spaces)
for i in *.mp3; do mv "$i" "`echo "$i" | tr '_' ' '`"; done

rm audiodump.wav



Just put this script on the same directory of your wma files then run it. All of your wma files will be converted to mp3 files.
I hope this script and my little modifications can help you converting your wma files to mp3 files.

7 comments:

georgelappies said...

Thanks so much, this works great!

wma to mp3 said...

Thanks a lot!! This would be a nice tutorial:)

Anonymous said...

I made a few modifications for changing files in nested directories:

#!/bin/bash

musicDir="/storage/music"
backupDir="/storage/backupWMA/"

for f in $(find "$musicDir" -name '*.wma' | tr ' ' '@' );
do

filename=`echo $f | tr '@' ' '`
cp "$filename" "$backupDir""`basename $filename .wma`"

#mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader "$filename" && lame -m s audiodump.wav -o "`echo $filename | sed 's|wma|mp3|'`";
rm "$filename"

echo "`echo $filename | sed 's|wma|mp3|'`";

done

rm audiodump.wav

it will search in $musicDir and backup the wma's to $backupDir

Thanks

Unknown said...

Wow .. thank's for sharing your modification.

Rick said...

is the mplayer supposed to be commented out there?

also if you replace musicDir="/storage"/storage/backupWMA/""/storage/backupWMA/"

/music" with musicDir=$1 you can pick the starting dir. Prolly be best to replace "/storage/backupWMA/" with $2 as well so you can pick the backup dir as well

bacq said...

lol, your modification just tries to backup atm. If the backup folder does not exist it just deletes every file without backup.

You commented out the conversion line, so nothing will be converted.

It's a script to lose all your files lol.

Unknown said...

Thank you for sharing this useful code.