[Phphtmllib-devel] SF.net SVN: phphtmllib:[3311] trunk/open2300/lib/core/daemon/ AviProcessorDaemon
Status: Beta
Brought to you by:
hemna
From: <he...@us...> - 2009-12-01 05:49:39
|
Revision: 3311 http://phphtmllib.svn.sourceforge.net/phphtmllib/?rev=3311&view=rev Author: hemna Date: 2009-12-01 05:49:29 +0000 (Tue, 01 Dec 2009) Log Message: ----------- nuked log_message() Modified Paths: -------------- trunk/open2300/lib/core/daemon/AviProcessorDaemon.inc Modified: trunk/open2300/lib/core/daemon/AviProcessorDaemon.inc =================================================================== --- trunk/open2300/lib/core/daemon/AviProcessorDaemon.inc 2009-12-01 05:48:23 UTC (rev 3310) +++ trunk/open2300/lib/core/daemon/AviProcessorDaemon.inc 2009-12-01 05:49:29 UTC (rev 3311) @@ -10,7 +10,7 @@ * @author waboring * */ -class AviProcessorDaemon extends Daemon { +class AviProcessorDaemon extends ScheduleDaemon { /** * User ID @@ -21,121 +21,130 @@ * Group ID */ protected $group_id = 100; - + /** * how long to wait in between * processing. in seconds */ protected $wait_period = 1800; - - + + /** * the log object. */ protected $log; - + protected $imagesdir; - + /** * track the number of images we are * processing. If we have the same number * as last run...no need to process. */ protected $image_count = 0; - - + + /** + * we need to return the logger. + * + */ + protected function get_logger() { + $log = new Log(); + $log->add_writer(FileLogWriter::factory(realpath($GLOBALS["path_base"])."/logs/daemon.log")); + + return $log; + } + + + /** * Do any initialization here. * */ protected function init() { - $this->log = new Log(); - $this->log->add_writer(FileLogWriter::factory(realpath($GLOBALS["path_base"])."/logs/daemon.log")); - - $config = Config::singleton(); + $config = Config::singleton(); $this->imagesdir = $config->get("imagesdir"); } - + /** * any cleanup here */ protected function cleanup() { } - - /** - * This method is used to pause the scheduler so - * we aren't constantly running as fast as we can. - * - */ - protected function wait_state() { - $this->log->debug("::wait_state() sleeping for ".$this->wait_period." seconds"); - sleep($this->wait_period); - } - - - /** - * do the actual work here. - * - */ - protected function do_task() { - //now do a wait state - //so we aren't constantly running. - $this->wait_state(); + protected function can_run() { + //used for directory $ymdDate = date("Ymd"); + + $dirname = $this->imagesdir."/".$ymdDate; - $dirname = $this->imagesdir."/".$ymdDate; //make sure the images dir exists. $this->test_images_dir($dirname); - - $num_images = $this->count_images($dirname); + $num_images = $this->count_images($dirname); + $this->num_images = $num_images; + if ($num_images == 0 || ($num_images == $this->image_count)) { - //we have nothing to do - $this->log->info("::do_task() no images or same count"); + $this->log->info("::can_run() no images or same count"); + return false; } else { + $this->log->info("::do_task() found ".$num_images." to process into a movie."); - $rate = $this->calculate_rate($num_images); - - $this->log->info("::do_task() rate is ".$rate." -> movie length = ".$num_images/$rate."s"); - //generate the avi - $cmd = "/home/waboring/bin/imgs2avi.sh -w 640 -h 480 -r ".$rate; - $this->exec_command($dirname, $cmd); + return true; + } + } + + + /** + * do the actual work here. + * + */ + protected function schedule() { + + //used for directory + $ymdDate = date("Ymd"); + + $dirname = $this->imagesdir."/".$ymdDate; + + $rate = $this->calculate_rate($this->num_images); + + $this->log->info("::do_task() rate is ".$rate." -> movie length = ".$this->num_images/$rate."s"); + //generate the avi + $cmd = "/home/waboring/bin/imgs2avi.sh -w 640 -h 480 -r ".$rate; + $this->exec_command($dirname, $cmd); - //now convert the avi movie to a flash file - $aviname = "timelapse_640x480_".$rate."fps.avi"; - $cmd = "/usr/bin/ffmpeg -y -i ".$aviname." -b 1900k -f flv ".$ymdDate."/timelapse.flv"; - $this->exec_command($dirname, $cmd); + //now convert the avi movie to a flash file + $aviname = "timelapse_640x480_".$rate."fps.avi"; + $cmd = "/usr/bin/ffmpeg -y -i ".$aviname." -b 1900k -f flv ".$ymdDate."/timelapse.flv"; + $this->exec_command($dirname, $cmd); - //move the + //move the - //now send it to the hosting provider - //$cmd = "/usr/bin/scp timelapse.flv wx.hemna.com:wx.hemna.com/htdocs/video/".$ymdDate; - $cmd = "/usr/bin/rsync -av ".$ymdDate." wx.hemna.com:wx.hemna.com/htdocs/video"; - $this->exec_command($dirname, $cmd); + //now send it to the hosting provider + //$cmd = "/usr/bin/scp timelapse.flv wx.hemna.com:wx.hemna.com/htdocs/video/".$ymdDate; + $cmd = "/usr/bin/rsync -av ".$ymdDate." wx.hemna.com:wx.hemna.com/htdocs/video"; + $this->exec_command($dirname, $cmd); - //track the image count - $this->image_count = $num_images; - } + //track the image count + $this->image_count = $num_images; } - + /** * This is used to execute an external command - * + * */ protected function exec_command($dirname, $cmd) { $command = "cd ".$dirname."; ".$cmd." 2>&1 >>".$dirname."/processing.log"; $this->log->info("::exec_command() exec ".$command); $last_line = system($command, $return); - $this->log->debug("::exec_command() done"); + $this->log->debug("::exec_command() done"); } - + /** * calculate the frame rate to use based * on the # of images we have to process. - * + * * @param $numimages * @return rate */ @@ -152,13 +161,13 @@ } else if ($num_images < 1200) { $rate = 25; } - + return $rate; } - - + + /** * Find out how many images are in the dir * @@ -166,11 +175,11 @@ */ protected function count_images($dirname) { $count = 0; - + $this->log->debug("::count_images() : check ".$dirname); if (file_exists($dirname)) { if ($dir = opendir($dirname)) { - while (($file = readdir($dir)) !== false) { + while (($file = readdir($dir)) !== false) { if (strstr($file, '.jpg')) { $count++; } @@ -178,12 +187,12 @@ closedir($dir); } } - + $this->log->debug("::count_images() : found ".$count); return $count; } - - + + /** * make sure the video dir exists. * @@ -193,9 +202,9 @@ $this->create_dir($dirname); $ymdDate = date("Ymd"); $this->create_dir($dirname."/".$ymdDate); - } + } } - + /** * Create the image directory * (this is also done from the camera) @@ -210,24 +219,19 @@ throw $ex; } } - - - - - /** - * Create the process id file on disk - * so that we can store it for later use. - * - * @return string - */ - public function generate_pid_filename() { - return realpath($GLOBALS["path_base"]).'/bin/'.__CLASS__.'.pid'; - } - - protected function log_message($message, - $level=0, - $e=NULL) { - } + + + + + /** + * Create the process id file on disk + * so that we can store it for later use. + * + * @return string + */ + public function generate_pid_filename() { + return realpath($GLOBALS["path_base"]).'/bin/'.__CLASS__.'.pid'; + } } ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |