0) { // Get the curent level $level = ob_get_level(); // End the buffering ob_end_clean(); // If the current level has not changed, abort if (ob_get_level() == $level) break; } // Disable apache output buffering/compression if (function_exists('apache_setenv')) { apache_setenv('no-gzip', '1'); apache_setenv('dont-vary', '1'); } } header("Content-type: text/plain"); // tell php to automatically flush after every output // including lines of output produced by shell commands //disable_ob(); $total_frm =0; $curent_frm =0; $postid = 0; $informProgress =0; function image_pic($string,$save,$font = 15,$ofsetX,$ofsetY){ $im = @imagecreatetruecolor((strlen($string) * $font / 1.5)+$ofsetX, ($font*1.5)+$ofsetY); imagesavealpha($im, true); imagealphablending($im, false); $white = imagecolorallocatealpha($im, 255, 255, 255, 127); imagefill($im, 0, 0, $white); $lime = imagecolorallocate($im, 255, 255, 255); imagettftext($im, $font, 0, $ofsetX, $font + 3, $lime, __DIR__."/IRANSans_Medium.ttf", $string); //header("Content-type: image/png"); imagepng($im,$save); imagedestroy($im); } function my_exec($cmd, $input='',$id) {$proc=proc_open($cmd, array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>array('pipe', 'w')), $pipes); fwrite($pipes[0], $input);fclose($pipes[0]); $stdout = ""; $fin = 0; $postid = $id; $informProgress = 10; if (is_resource($proc)) { while ($s = fgets($pipes[1])) { //print $s; //file_put_contents("alog.txt", $s, FILE_APPEND | LOCK_EX); preg_replace_callback('/PROGRESS: Duration: ([0-9]+?):([0-9]+?):([0-9]+?):([0-9]+?) /si',function($match) use (&$total_frm,&$curent_frm){ //print_r($match); $total_frm = $match[4] + $match[3]*100 + $match[2]*60*100 + $match[1]*60*60*100; print $total_frm."\n"; //file_put_contents("alog.txt", $total_frm."\n", FILE_APPEND | LOCK_EX); },substr(trim($s), 0, -1)." "); preg_replace_callback('/PROGRESS: ([0-9]+?):([0-9]+?):([0-9]+?):([0-9]+?) /si',function($match) use (&$total_frm,&$curent_frm,&$postid,&$informProgress){ //print_r($match); $curent_frm = $match[4] + $match[3]*100 + $match[2]*60*100 + $match[1]*60*60*100; //print $curent_frm."\n"; $perc=0; if( $total_frm > 0){ $perc = ($curent_frm * 100 / $total_frm); if((int)$perc > $informProgress){ print_r($postid."\r\n"); $informProgress += 10; //$post = array('MakePool_id'=>$data_arry[0]->{'MakePool_id'},"ProgressBar"=>(int)$perc); $ch = curl_init(); print_r("http://www.arbaeentv.com/MakePool/Progress/".$postid."/".$perc); $target_url = "http://www.arbaeentv.com/MakePool/Progress/".$postid."/".$perc; curl_setopt($ch, CURLOPT_URL,$target_url); // curl_setopt($ch, CURLOPT_POST,1); // curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result=curl_exec ($ch); print_r($result); print_r("update progress %".$perc."\n"); } print_r("%".$perc."\n"); } //file_put_contents("alog.txt", "%".($curent_frm * 100 / $total_frm)."\n", FILE_APPEND | LOCK_EX); },substr(trim($s), 0, -1)." "); if(strstr($s, 'Finished composition', true) != false){ $fin =1; } $stdout = $stdout.$s; flush(); //ob_flush(); } } $stdout.=stream_get_contents($pipes[1]);fclose($pipes[1]); $stderr=stream_get_contents($pipes[2]);fclose($pipes[2]); $rtn=proc_close($proc); return array('fin'=>$fin, 'stdout'=>$stdout, 'stderr'=>$stderr, 'return'=>$rtn ); } function my_ff_wh_exec($cmd) {$proc=proc_open($cmd, array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>array('pipe', 'w')), $pipes); fwrite($pipes[0], "");fclose($pipes[0]); $stdout = ""; $fin = 0; $informProgress = 10; if (is_resource($proc)) { while ($s = fgets($pipes[2])) { //print_r($s); preg_match('/ ([0-9]+?)x([0-9]+?),/si', $s, $matches); if(isset($matches[0])){ print_r($matches); return array('w'=>$matches[1], 'h'=>$matches[2], ); } //$stdout = $stdout.$s; flush(); //ob_flush(); } } $stdout.=stream_get_contents($pipes[1]);fclose($pipes[1]); $stderr=stream_get_contents($pipes[2]);fclose($pipes[2]); $rtn=proc_close($proc); return array(); } function my_ff_exec($cmd,$path) {$proc=proc_open($cmd, array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>array('pipe', 'w')), $pipes); fwrite($pipes[0], "");fclose($pipes[0]); $stdout = ""; $fin = 0; $informProgress = 10; if (is_resource($proc)) { while ($s = fgets($pipes[2])) { print_r($s); preg_match('/Duration: ([0-9]{2}):([0-9]{2}):([^ ,])+/', $s, $matches); if(isset($matches[0])){ print_r($matches); $time = str_replace("Duration: ", "", $matches[0]); $time_breakdown = explode(":", $time); $total_seconds = round(($time_breakdown[0]*60*60) + ($time_breakdown[1]*60) + $time_breakdown[2]); shell_exec('"C:\xampp\htdocs\ffmpeg\bin\ffmpeg.exe" -y -i '.$path." -f mjpeg -vframes 1 -ss " . ($total_seconds / 2) . " screen1.jpg"); } //$stdout = $stdout.$s; flush(); //ob_flush(); } } $stdout.=stream_get_contents($pipes[1]);fclose($pipes[1]); $stderr=stream_get_contents($pipes[2]);fclose($pipes[2]); $rtn=proc_close($proc); return array('fin'=>$fin, 'stdout'=>$stdout, 'stderr'=>$stderr, 'return'=>$rtn ); } if(isset($data_arry->{'data'}->{'videos'})) { //print_r($data_arry->{'data'}); foreach($data_arry->{'data'}->{'videos'} as $k=>$Video){ //print_r($Video); //echo __DIR__."/".$data_arry[0]->{'Name'}; $path = "screen1.jpg"; $mp4_name = basename($Video->{'video_address'}); $file_name_with_full_path2 = __DIR__.'/temp/'.$mp4_name; @unlink($file_name_with_full_path2); @unlink($path); download("http://www.arbaeentv.com/".$Video->{'video_address'},$file_name_with_full_path2); $uname = "arbaeentv.com"; $WH = my_ff_wh_exec($ffmpeg ." -i ".$file_name_with_full_path2); $width = $WH['w']; $height = $WH['h']; my_ff_exec($ffmpeg.' -i '.$file_name_with_full_path2 ,$file_name_with_full_path2); $type = pathinfo($path, PATHINFO_EXTENSION); $data = file_get_contents($path); if($data != false){ $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'http://arbaeentv.com/api/v1/bot/get-response', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array('video_id' => $Video->{'id'},'cover' => $base64), CURLOPT_HTTPHEADER => array( 'Accept: application/json' ), )); $response = curl_exec($curl); curl_close($curl); print_r($response); } //@unlink($file_name_with_full_path2); // @unlink($path); /* $pic_logo ="temp/logo1.png"; if($width >= 1920){ image_pic($uname." ",$pic_logo,30,5,10); }elseif($width >= 1280){ image_pic($uname." ",$pic_logo,20,5,10); }elseif($width >= 960){ image_pic($uname." ",$pic_logo,18,4,10); }elseif($width >= 640){ image_pic($uname." ",$pic_logo,13,2,7); }elseif($width >= 480){ image_pic($uname." ",$pic_logo,11,2,4); }elseif($width >= 426){ image_pic($uname." ",$pic_logo,11,2,4); }else{ image_pic($uname." ",$pic_logo,8,2,4); } file_put_contents("1.bat",'ffmpeg -loglevel panic -y -i '.$file_name_with_full_path2.' -i '.$pic_logo.' -filter_complex "[0:v]scale='.$width.':'.$height.'[bg];[bg][1:v]overlay=10:(main_h-overlay_h)" '.$file_name_with_full_path ); $retArr = my_exec('C:\xampp\htdocs\1.bat',"",$data_arry[0]->{'MakePool_id'}); $retVal = $retArr["fin"]; // print_r($retArr); // print_r($retVal); //$retVal = "0"; if($retVal == 1 and is_file($file_name_with_full_path2)){ my_ff_exec('"C:\xampp\htdocs\ffmpeg\bin\ffmpeg.exe" -i '.$file_name_with_full_path2 ,$file_name_with_full_path2); //$post = array('Name'=>$data_arry[0]->{'Name'},'Video_id'=>$data_arry[0]->{'Video_id'},'MakePool_id'=>$data_arry[0]->{'MakePool_id'},'download'=>'http://188.253.3.27/1.mp4'); $ch = curl_init(); $target_url = "http://www.arbaeentv.com/MakePool/Receive/".$data_arry[0]->{'Name'}."/".$data_arry[0]->{'Video_id'}."/".$data_arry[0]->{'MakePool_id'}."/188.253.3.27"; print_r($target_url); curl_setopt($ch, CURLOPT_URL,$target_url); // curl_setopt($ch, CURLOPT_POST,1); // curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result=curl_exec ($ch); echo 'do upload!'; print_r($result); curl_close ($ch); }else{ //$post = array('Name'=>$data_arry[0]->{'Name'},'Video_id'=>$data_arry[0]->{'Video_id'},'MakePool_id'=>$data_arry[0]->{'MakePool_id'},'download'=>'http://188.253.3.27/1.mp4'); $ch = curl_init(); $target_url = "http://www.arbaeentv.com/MakePool/Receive/".$data_arry[0]->{'Name'}."/".$data_arry[0]->{'Video_id'}."/".$data_arry[0]->{'MakePool_id'}."/188.253.3.27"; print_r($target_url); curl_setopt($ch, CURLOPT_URL,$target_url); // curl_setopt($ch, CURLOPT_POST,1); // curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result=curl_exec ($ch); echo 'do error!'; print_r($result); } */ echo 'woot!'; //@unlink(__DIR__."/".$data_arry[0]->{'Name'}); } }