video - PHP pseudo streaming -
i have 2 problems php pseudo streaming
- sometimes stuttering bit
- don't work mp4 files
$php_buffer=2; $bitr_min=60; $intv_max=0.6; $bitr_max=300; $intv_min=0.3; $bitr=$bitr+$php_buffer; if ($bitr<=$bitr_min) { $packet_interval=$intv_max; } elseif ($bitr>=$bitr_max) { $packet_interval=$intv_min; } else { $packet_interval=$intv_max-(($intv_max-$intv_min)*($bitr-$bitr_min)/($bitr_max-$bitr_min)); $packet_interval=round($packet_interval*100)/100; } $packet_size=round($bitr*$packet_interval*1024); $limit_bandwidth=$bitr; $fsize = filesize($flv) - (($fseek > 0) ? $fseek + 1 : 0); set_time_limit(30+$fsize/($limit_bandwidth*1024)); if($no_cache) { # prohibit caching (different methods different clients) session_cache_limiter("nocache"); header("expires: thu, 19 nov 1981 08:52:00 gmt"); header("last-modified: " . gmdate("d, d m y h:i:s") . " gmt"); header("cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); header("pragma: no-cache"); } // flash video header if (strpos($fname,'.flv')) header("content-type: video/x-flv"); else header("content-type: video/mp4"); //// video/x-mp4 header("content-disposition: attachment; filename=\"" . $fname . "\""); header("content-length: " . $fsize); $fpr = fopen($flv, 'rb'); // flash video file format header if($fseek != 0) { echo 'flv'.pack('c', 1).pack('c', 1).pack('n', 9).pack('n', 9); } // seek file requested start fseek($fpr, $fseek); // start file output while(!feof($fpr)) { // bandwidth limiting if($packet_interval > 0 && $limit_bandwidth) { // start time list($us, $s) = explode(' ', microtime()); $ts = ((float)$us + (float)$s); // echo packet echo fread($fpr, $packet_size); // end time list($us, $s) = explode(' ', microtime()); $tst = ((float)$us + (float)$s); $tdi = $tst - $ts; // wait, when output slower packet interval if($tdi < (float)$packet_interval){ usleep((float)$packet_interval * 1000000 - (float)$tdi * 1000000); } } else { // output file without bandwidth limiting echo fread($fpr, filesize($flv)); } }
how resources kind of solution? in localhost have same results , not apache/php overloading on contrary take low resources.
please help.
to pseudo stream mp4 file on browser (including ipads/tablets) functionality working (seek forward, seek backwards , displays correct time).
try mp4streaming tuxxin github
also works fine longtail jwplayer 6 , html5 players.
Comments
Post a Comment