Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
Distribution: Slackware, Windows, FreeBSD, OpenBSD, Mac OS X
Posts: 5,296
Rep:
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
This may help with the naming. batren Hope something there helps.
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.
Distribution: Slackware, Windows, FreeBSD, OpenBSD, Mac OS X
Posts: 5,296
Rep:
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
Again, downloaded, not authored. There is also a "space remover" bash script somewhere in this forum that was posted that should be recursive IIRC.
Good luck. ;-)
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
#check for arguments before starting
if [ $# -gt 0 ]; then
#get options from command line
#first option is directory to process we are going to make the output directory match
DIR_TO_PROCESS=$1
#Other variables
ROOT_PATH_TO_OUTPUT="/home/phoneCalls"
FINAL_OUTPUT_PATH="$ROOT_PATH_TO_OUTPUT"'/'"$DIR_TO_PROCESS"
#check if the output directory exists, create if necessary
if [ -d "$FINAL_OUTPUT_PATH" ]; then
echo ""
else
`mkdir "$FINAL_OUTPUT_PATH"`
fi
#This puts it in this format 2008-05-15_17.33.46
#date -r $filename +%F_%H.%M.%S
#This is a loop for conversion
for filename in *.WAV
do
OUTPUT_NAME=`date -r "$filename" +%F_%H.%M.%S`
lame -S --preset 24 "$filename" "$FINAL_OUTPUT_PATH"'/'"$OUTPUT_NAME"'.mp3'
done
#end if no command line args was given
else
echo "Please enter directory to process. Ex: ./convert \"personal calls\""
exit 1
fi
It's still a little messy but it works. Thanks for the pointers.
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
this is not elegant because you end up having files named .wav.mp3 instead of plain mp3 but should work. i put the doublequotes because i do't know if the filenames will have whitespaces or not so this works either way. btw: you can script the renaming as well so this should be no big problem.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.