我有两个PHP伪流媒体问题
$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 for 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 to the file requested start
fseek($fpr, $fseek);
// Start the 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 is slower than 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));
}
}
有多少资源可以获得这种解决方案?在我的localhost中有相同的结果,而不是apache / php重载相反占用非常低的资源。
请帮忙。
答案 0 :(得分:0)
在任何浏览器(包括iPad /平板电脑)上伪任何MP4文件,所有功能都正常工作(向前搜索,向后搜索并显示正确的时间)。
通过tuxxin github
尝试MP4Streaming也适用于Longtail JWPlayer 6和HTML5播放器。