Script to Convert wav to mp3
I have a Centos5 machine just laying around that I am going to use to convert huge numbers (300 gigs+) of wav files to mp3's. What I need to do is make a perl/bash script that can read in the creation date of the file. We need to maintain the original creation date for our records. So we are just going to take some wav file and make the outputted mp3 filename the created date from the wav.
For example: MSG089348.wav created Jan 5, 2007 at 10:00AM Would become: 01-05-07 10:00:00.mp3 So two things I need some help with are the perl/bash (whatever works better) to loop through a specified directory grabbing each wav file and it's creation date then running through something like mencoder to spit out the mp3 to a specified directory. Any help would be appreciated!! -David |
I've got a couple of things here downloaded, not authored, that may help with some modification. This should handle the conversions provided you have lame.
Code:
for i in *.wav; do lame --preset standard $i `basename $i .wav`.mp3; done Good luck. ;-) |
Can I just suggest you DON'T use spaces in a filename, it always causes issues later. Try underscores.
Also, if you use the format yyyymmdd_hhmmss.mp3 it'll sort properly by default. |
I agree about spaces in file names, however, if you do have problems with spaces in file names you could always do this.
Code:
for i in *.mp3; do mv "$i" `echo $i | tr ' ' '_'`; done Good luck. ;-) |
Thanks for all the suggestions. I'm going to get started on this soon, and thanks for the tip about spaces.
|
Well I think I have a fully functional script. In order to run it you have to be in the directory you want to convert and then you pass as an argument the directory you are in. It will then convert them and place them in a new directory structure.
Code:
#!/bin/bash --David |
Cool, glad you got that sorted. I'll be filing this away in my "scripts that could be useful" collection.
Good luck. ;-) |
what about?
mencoder <filename>.wav -oac mp3lame -o <filename>.mp3 to convert the files. there's an excellent man page btw ;). you need to have mp3lame support compiled in your mplayer. if not, recompile it.
the easiest way to convert all would be you rename the filenames. and do (assuming the wav files are all in the same directory) Code:
$ for i in *wav; do mencoder "$i" -oac mp3lame -o "$i".mp3; done there's surely a much more elegant way but you don't do this for price winning i assume. so if in doubt use brute force...and do it quick and dirty ;) good luck, vadkutya p.s.: peacedog has provided a way to change the ending. haven't seen it. so maybe you should change the script above like this: Code:
$ for i in *wav; do mencoder "$i" -oac mp3lame -o `basename "$i" wav`.mp3; done |
All times are GMT -5. The time now is 02:44 PM. |