You probably put it in /usr/local/bin. Looking at the script, if you try to use it to convert one mp3 file, and you give it the full path name to the file, it breakes the script. In the example I gave, it would try and write the output to wav/home/mikkel/mp3/test.wav and sox would choke on that as an output file name. If you use a path name as part of the file name, the script breaks.On Tuesday 22 March 2005 08:19 pm, Mikkel L. Ellertson wrote:
I got into this thread a little late, kind of behind on reading, anyway, I use the below script in 9.0, called mp32wav.
#!/bin/bash # mp32wav
mp3file="$*" mkdir wav
for file in "$@" ; do #echo "$file" wavfile=`echo "$file" | sed s/\\.mp3/.wav/` printf "%-50s %-50s\n" "$file" "--> $wavfile"
# to encode wav-->mp3 #lame -h "$file" "$mp3file"
# to encode mp3-->wav mpg123 -b 10000 -s "$file" | sox -t raw -r 44100 -s -w -c2 - "wav/$wavfile" done
Interesting script. But what happens if is did something like: mp32wav /home/mikkel/mp3/test.mp3
You may want to consider using basename to strip off the .mp3, as well as the path to to source file, when creating the output file name. (I don't even want to get into creating an output directory off the current directory without any checking...)
Mikkel
If I remember correctly I put the script someplace like /usr/share or /usr/local and would just run it from the ~/mp3s dir. I'd put all the mp3's I wanted to convert into that dir and run the script after cd'ing to that dir. Or am I missing something in your question. Note: I did not write this script, it was posted to the list a couple of years ago, I can't even begin to recall who the author was, maybe he/she are still on the list.
Chris
The difference between the way the script strips off the .mp3 to create the output file, and the way the basename command does it shows up there. Try this:
echo /home/test/test.mp3 | sed s/\\.mp3/.wav/
basename /home/test/test.mp3 .mp3
In the script, you would use
wavfile='basename "$file" .mp3'
in place of
wavfile=`echo "$file" | sed s/\\.mp3/.wav/`
I would also make a few other changes, but at least that change would handle doing something like:
cd $HOME/tmp mp32wav $HOME/mp3/*.mp3
That way, you would not be limitted to running it in the directory with the mp3 files in it. More error checking would be nicer.
For the way you use it, something like this may work better.
#!/bin/bash # # mp32wav - a script to convert all the mp3 file # in the current directory to wav files, and put # the output file in the wav directory created # in the current directory # if [ ! -d wav ] then if ! mkdir wav ; then echo I could not create the output directory. exit 1 fi fi
for in_file in *.mp3 ; do out_file=$(basename "$i" .mp3).wav echo Converting $in_file to $out_file mpg123 -b 10000 -s "$in_file" | \ sox -t raw -r 44100 -s -w -c2 - "wav/$out_file" done
I used the \ to continue the convert command on the next line so it wouldn't wrap in the email, but it can all be on one line in the script.
The first 6 lines after the comments just take care of creating the wav directory if there isn't one, and aborting the script if it can not create it. There is still room for improvment - the output directory could be defined as a varable in the script, so that you could change it without rewriting the script. You could also test each input file to make sure it is realy a mp3 file. Things of that nature. The echo line that tells what file is being being converted is optional. I like seeing what is going on with this type of script.
Mikkel --
Do not meddle in the affairs of dragons, for you are crunchy and taste good with Ketchup!
____________________________________________________ Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com Join the Club : http://www.mandrakeclub.com ____________________________________________________