#! /usr/bin/perl ### Calculate the number of CPUs we want to keep busy open IN, "/proc/cpuinfo"; $cpus = grep /processor.*:/, ; close IN; ### This is a list of files to encode @names = @ARGV; $dira = shift @names; $dirb = shift @names; ### This is the name of the encoder to use. $coder = "/usr/local/bin/mplex "; ### ### ### ### # Encode a single file sub do_one { my($m2v) = shift; # Make mp3 from wav $m2v =~ s/\.m2v$//; # In a subprocess, encode the file printf "Multiplexing ${m2v}\n"; unless($pid = fork) { system ("$coder ${dira}/${m2v}.m2v ${dira}/${m2v}.mp2 ${dirb}/${m2v}.mpg"); exit; } } # Go ahead and prefork $cpus encoders foreach $i (0 .. $cpus-1) { &do_one($names[0]) if ($names[0] ne ""); shift @names; } # Wait for the end of each encoder, start a new one... foreach $i (@names) { wait; &do_one($i); } # Wait for everything to close down. while(wait > 0) { ; }