View Full Version : PHP/EXEC & Lame Mp3 Encoder

09-01-2006, 08:20 PM
I've got a site where users can upload music they have writen, i would like to re-encode all the music into a lower bit rate ( all new music once a day ) so that mp3s can be play ondemand via a flash mp3 player.

but I don't want to use that much bandwidth.

so I've built this script:

$d = dir(MEMBER_DIR);
while (false !== ($entry = $d->read())) {
If($entry=="." || $entry==".."){
// do nothing
echo "<b>--->".$entry."</b><br />";
$songpath = dir(MEMBER_DIR.$entry."/");
while (false !== ($song = $songpath->read())) {
$Path = MEMBER_DIR.$entry."/";
$destination = AUDIO_DIR."stream_".$entry."_".$song;
if(file_exists($destination)){ // skip it
echo "->".$songpath->path.$song." ->".$destination." Already Exists<br />";
} Else {
echo "<b>->".$songpath->path.$song." ->".$destination."</b><br />";
exec("lame -b 64 -f -m s '".$Path."' '".$destination."'");

basicly, this just moves though directories and gets the mp3 file names and adds them to the Lame comment line.

this does work if I just do one at a time, however, i would like to run this once a day as new files are always beening added and doing it while they are being uploaded would cause uploaded to take alot longer and could time out.

the problem is that when runnig this in more then one file at a time, it just create an empty .mp3 file and moves on to the next file with out completing the current file.

My question, is there a way to force the script to wait untill the EXEC command has completed before continuing on to the next file?

thanks in advance for your time.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum