You are not logged in.
Conceptually, I don't see why a bash script couldn't run x simultaneous lame mp3 encodes where x is the number of cores the user selects. I just don't know how to go about doing it. Would it make sense to read in all the .wav files to an array, then divide the array into x sub arrays and feed the work out or is there a more simplistic method?
EDIT: I found this blog entry but I don't fully understand it.
Here is my adaptation of his code:
#!/bin/bash
# the number of cores you have on your system
cores=4
encode() {
for file; do
fileout=$(echo "$file" | sed s'/.wav//')
lame -V 2 "$file" "$fileout".mp3; done
}
export -f encode
find . -name '*.wav' -print0 | xargs -0 -n 1 -P $cores bash -c 'encode "$@"' --
Can someone explain to me what the last bit does: 'encode"$@"' --
Last edited by graysky (2010-03-01 22:17:13)
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
double post
Last edited by graysky (2010-03-01 21:47:43)
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
The last bit calls the encoide function, passing in all the arguments as past to it on stdin.
'encode "$@"' calls encode and passes it its arguments (as passed to it from the find command).
-- tells xargs that there are no more command line options, and to interpret anything "-" as part of the file names.
man find and man xargs for more info.
The "--" I'm not sure which man page it'll be in but I think it's a GNU thing?
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
Thanks for the info, skanky.
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline