Bash Script : Batch convert mp3
So today I needed a bash script that will use lame to batch covert mp3 files to a lower bitrate so I can squeeze more onto my mp3 player.
After looking around on the net and taking bits of other peoples code (thanks NoStop and keefaz) I came up with this :
Use at your own risk !
Watch out for lame to generate errors. I had some damaged mp3 files and when lame tried to convert them it generated an error then stop processing.
#!/bin/sh #Be sure to edit as needed ! #Step 1 - Remove the spaces from the names #example : Track 1.mp3 will be renamed to Track_1.mp3 #This is done because step 2 can't hand spaces in file names for f in *; do file=$(echo $f | tr ' ' _) [ ! -f $file ] && mv "$f" $file done #Step 2 #Convert mp3 to a lower quality #All mp3s are converted to 112 bit using "-b 112" #All mp3s given names with _112 at the end #example : Track_1.mp3 will be converted to Track_1_112.mp3 ls -1 *.mp3 | sed "s/(.*).mp3/1.mp3 1_112.mp3/" | xargs -n 2 lame -b 112
Comments(8)