You are not logged in.

#1 2010-03-01 21:19:32

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

bash script to pseudo multithread a encode job lame

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 packagesZsh and other configs

Offline

#2 2010-03-01 21:45:40

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Re: bash script to pseudo multithread a encode job lame

double post

Last edited by graysky (2010-03-01 21:47:43)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#3 2010-03-01 22:03:32

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: bash script to pseudo multithread a encode job lame

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

#4 2010-03-03 23:31:26

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Re: bash script to pseudo multithread a encode job lame

Thanks for the info, skanky.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

Board footer

Powered by FluxBB