Operating Systems > Linux and UNIX
Converting multiple files to mp3
voidmain:
quote:Originally posted by void main:
Actually the spaces are a problem in the lame command, not the "for" loop. This works for me:
$ for i in *.[Ww][Aa][Vv]; do lame --preset extreme "$i" "${i%%.[Ww][Aa][Vv]}.mp3"; done
Which also accounts for case. The quotes should fix the problem with spaces in the parameters for lame.
--- End quote ---
Or to do everything in the current directory and all subdirectories:
$ for i in `find -iname '*.wav'`; do lame --preset extreme "$i" "${i%%.[Ww][Aa][Vv]}.mp3"; done
[edit]
This last example doesn't work. Sorry about that!
[/edit]
[ January 28, 2003: Message edited by: void main ]
flap:
I don't think that last one works with spaces.
You're right though that "for i in *.wav" will work if you enclose the "$i" in quotes, but that won't work if you're using "for i in `find..."
voidmain:
You are right, and the bad part is I actually knew that wouldn't work, and I actually tested it and proved that it didn't work, and then I posted it anyway as I was distracted on another forum...
[ January 28, 2003: Message edited by: void main ]
Agent007:
hi all,
Thanks a tonne to beltorak, the following syntax works superbly!! Encoding wav files to mp3 is just a breeze!
quote:
find -name "*.wav" | while read item; do lame --preset extreme "$item" "${item/.wav/}.mp3";done
--- End quote ---
Could someone pls explain as to what this portion of the syntax means? Whats the dollar sign for?
"$item" "${item/.wav/}.mp3"
thanks,
007
PS:- I try to stay away from sed, since its a bit complicated to remember the characters and stuff.....
[ January 30, 2003: Message edited by: Agent007 ]
flap:
$ is used to identify a variable. In this case $item will refer to each wav file returned by the 'find' command.
The "${item/.wav/}.mp3" bit is used to specify the output filename. This removes ".wav" from the filename and then adds ".mp3" onto the end.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version