3600) # 1 h // { // unlink($GLOBALS['lock_file']); // } // else // { // exit(1); // } // } // touch($GLOBALS['lock_file']); //} // // //init(); function v_shutdown() { if(file_exists($GLOBALS['lock_file'])) { unlink($GLOBALS['lock_file']); } } // v_shutdown function usage(&$argv) { print "\n\nUsage:\n\t$argv[0] \n"; } // usage $argv[1] = 'data'; $argv[2] = 'data'; if(count($argv) < 2) { usage($argv); exit(1); } register_shutdown_function('v_shutdown'); function v_get_list($in_dir) { if( !($d = opendir($in_dir)) ) { print "Cannot read directory '$in_dir'\n"; exit(1); } $list = array(); $time = time(); while(false !== ($f = readdir($d))) { if( ($f != '.') && ($f != '..') ) { $mtime = filemtime("$in_dir/$f"); if($time - $mtime > 120) # 2min { $list[] = $f; } } } return $list; } // v_get_list $video_in = $argv[1]; $video_out = $argv[2]; $list[0] = $new_file_name;//v_get_list($video_in); $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("file", $log_file, "a") ); foreach($list as $item) { $f_in = "$video_in/$item"; $f_out = "$video_out/$item.flv"; $stat = is_file($f_out) ? stat($f_out) : false; if(!$stat || !$stat[7]) { $pipes = array(); if($r = proc_open( "nohup $ffmpeg -i \"$f_in\" -y -ar 22050 -s 320x240 \"$f_out\"", $descriptorspec, $pipes ) ) { $i = proc_close($r); //fwrite($pipes[2], "[%s]\n", date('c')); } } } @unlink($f_in); ?>