The Little Guy Posted October 19, 2008 Share Posted October 19, 2008 I have a cron job that runs every five minutes, it grabs all the videos in a file, and converts them to an FLV file. It uses FFMpeg to convert the videos, the problem is that the program can only do one file at a time. So, if I have five files waiting to convert, it will do them one at a time, which could take 30+ minutes. So... how could I grab the files, then convert them all at once? The only way I could think would be to have the cron start up FFMpeg more than one time, and pass one file to each open FFMpeg instance... But how? Quote Link to comment https://forums.phpfreaks.com/topic/129039-faster-cron-job-process/ Share on other sites More sharing options...
The Little Guy Posted October 19, 2008 Author Share Posted October 19, 2008 anyone happen to know? Quote Link to comment https://forums.phpfreaks.com/topic/129039-faster-cron-job-process/#findComment-669500 Share on other sites More sharing options...
daydreamer Posted October 19, 2008 Share Posted October 19, 2008 converting videos would take alot of processor + ram. if you run multiple instances you would have to share your resources between each one so u might not benefit from any speed up at all? anyway, just a guess but you could write a shell script to run every minute or so which checks how many instances of FFMpeg u have running (find the command line for task manager and pipe results into ur script) against how many files you have waiting. then if you have 4 instances running and 5 files waiting you could run your cron job and somehow find a way to know which files are already being processed and which ones need processing. Quote Link to comment https://forums.phpfreaks.com/topic/129039-faster-cron-job-process/#findComment-669506 Share on other sites More sharing options...
The Little Guy Posted October 22, 2008 Author Share Posted October 22, 2008 any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/129039-faster-cron-job-process/#findComment-671391 Share on other sites More sharing options...
MadTechie Posted October 22, 2008 Share Posted October 22, 2008 can't you just exec it again! surely that would create another instances ! Quote Link to comment https://forums.phpfreaks.com/topic/129039-faster-cron-job-process/#findComment-671397 Share on other sites More sharing options...
trq Posted October 22, 2008 Share Posted October 22, 2008 You'll need to loop through each file and put it in a background process. eg; #!/bin/bash for file in $(ls /dir/where/files/are/); do ffmpeg "/dir/where/files/are/${file}" & done Quote Link to comment https://forums.phpfreaks.com/topic/129039-faster-cron-job-process/#findComment-671399 Share on other sites More sharing options...
The Little Guy Posted October 22, 2008 Author Share Posted October 22, 2008 1. What type of file is that? 2. in php doing a "shell_exec" will wait for it to execute the first file, then when that one is done, it will execute the next... does this method do that? 3. my php does lots of extra things, such as gets the video height/width, the movie length in time such as 00:03:34, send an email, etc. can I still do this? Quote Link to comment https://forums.phpfreaks.com/topic/129039-faster-cron-job-process/#findComment-671474 Share on other sites More sharing options...
trq Posted October 22, 2008 Share Posted October 22, 2008 my php does lots of extra things, such as gets the video height/width, the movie length in time such as 00:03:34, send an email, etc. can I still do this? Why would you be even using php to execute ffmpeg? Its a Linux command, use the Linux shell. The above script is written in bash, the default shell on most (if not all) Linux distributions. Are you saying you have cron execute a php script? If so, show me the script. Quote Link to comment https://forums.phpfreaks.com/topic/129039-faster-cron-job-process/#findComment-671503 Share on other sites More sharing options...
The Little Guy Posted October 22, 2008 Author Share Posted October 22, 2008 <?php include '../../tzfiles.com/id3/getid3.php'; include '../../dudeel.com/incl/includes.php'; $fileTypes = array('mov','mpg','mpeg','avi','wmv','wma','mp4'); $f = implode(',',$fileTypes); $gl = glob('../../flv.dudeel.com/wait/*.{'.$f.'}',GLOB_BRACE); $bitr = 300; function multiple_round($value, $to){ $opt = $value / $to; $opt = round($opt,0); $opt = $opt * $to; return $opt; } if(count($gl)>0){ foreach($gl as $f){ $getID3 = new getID3; $fileInfo = $getID3->analyze($f); $fileName = fileNameNoExt($f); if(isset($fileInfo['video']['resolution_x'])) $oResX = $fileInfo['video']['resolution_x']; else $oResX = 480; if(isset($fileInfo['video']['resolution_y'])) $oResY = $fileInfo['video']['resolution_y']; else $oResY = 360; // Get X Values $resX = 480; // Get Y Values $resY = 360; // Get a position in the video for an image if(isset($fileInfo['playtime_seconds'])){ $playLen = $fileInfo['playtime_seconds']; $randFPlay = rand(0,$playLen); if($playLen > 59){ $mins = floor($randFPlay/60); }else{ $mins = 0; } $secs = floor($randFPlay%60); if ($secs<10) { $secs = "0".$secs; } if ($mins<10) { $mins = "0".$mins; } $time = $mins.":".$secs; }else{ $time = "00:03"; } $ratio = round(($resX/$oResX)*$oResY); $r = ($resY - $ratio)/2; $padTop = multiple_round($r,2); $padBot = multiple_round($r,2); if($padTop < 0) $padTop = 0; if($padBot < 0) $padBot = 0; // Convert to flv file shell_exec("/usr/bin/ffmpeg -i '$f' -qscale 12 -vcodec flv -f flv -r 29.97 -s {$resX}x{$resY} -aspect 4:3 -padtop {$padTop}px -padbottom {$padBot}px -b {$bitr}k -g 160 -cmp 2 -subcmp 2 -mbd 2 -flags +aic+cbp+mv0+mv4+trell -ac 1 -ar 22050 -ab 56k '../../flv.dudeel.com/flv/$fileName.flv'"); // Create an image shell_exec("/usr/bin/ffmpeg -i '../../flv.dudeel.com/flv/$fileName.flv' -an -ss 00:{$time} -t 00:00:01 -r 1 -y -s 128x96 '{$fileName}%d.jpg'"); // Move the file rename("{$fileName}1.jpg","../../img.dudeel.com/video/{$fileName}.jpg"); $fileSize = filesize('../../flv.dudeel.com/flv/'.$fileName.'.flv'); if($fileSize > 0){ mysql_query(sprintf("UPDATE search_video SET `converted` = 'yes', `fileSize` = '%s' WHERE `id` = '%s'", mysql_real_escape_string($fileSize), mysql_real_escape_string($fileName))); $sql = mysql_query(sprintf("SELECT * FROM users, search_video WHERE search_video.owner = users.id AND search_video.id = '%s'", mysql_real_escape_string($fileName))); if(mysql_num_rows($sql) > 0){ $row = mysql_fetch_array($sql); include 'mail/convertedVideo.php'; } unlink($f); }else{ $sql = mysql_query(sprintf("SELECT * FROM users, search_video WHERE search_video.owner = users.id AND search_video.id = '%s'", mysql_real_escape_string($fileName))); if(mysql_num_rows($sql) > 0){ $row = mysql_fetch_array($sql); include 'mail/convertedVideoBad.php'; } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/129039-faster-cron-job-process/#findComment-671513 Share on other sites More sharing options...
The Little Guy Posted November 4, 2008 Author Share Posted November 4, 2008 Can Bash start up a PHP script, that way, I could have multiple php scripts run, each that converts one file. Quote Link to comment https://forums.phpfreaks.com/topic/129039-faster-cron-job-process/#findComment-682266 Share on other sites More sharing options...
trq Posted November 4, 2008 Share Posted November 4, 2008 Can Bash start up a PHP script, that way, I could have multiple php scripts run, each that converts one file. Indeed it can. $ php /path/to/script.php & Quote Link to comment https://forums.phpfreaks.com/topic/129039-faster-cron-job-process/#findComment-682370 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.