欢迎光临
我们一直在努力

PHP输出MP4视频流函数

function GetMp4File($file) {

$size = filesize($file);

header(“Content-type: video/mp4”);

header(“Accept-Ranges: bytes”);

if(isset($_SERVER[‘HTTP_RANGE’])){

header(“HTTP/1.1 206 Partial Content”);

list($name, $range) = explode(“=”, $_SERVER[‘HTTP_RANGE’]);

list($begin, $end) =explode(“-“, $range);

if($end == 0){

$end = $size – 1;

}

}else {

$begin = 0; $end = $size – 1;

}

header(“Content-Length: ” . ($end – $begin + 1));

header(“Content-Disposition: filename=”.basename($file));

header(“Content-Range: bytes “.$begin.”-“.$end.”/”.$size);

$fp = fopen($file, ‘rb’);

fseek($fp, $begin);

while(!feof($fp)) {

$p = min(1024, $end – $begin + 1);

$begin += $p;

echo fread($fp, $p);

}

fclose($fp);

}

GetMp4File(“demo.mp4”);

赞(0) 打赏
未经允许不得转载:珊瑚贝 » PHP输出MP4视频流函数
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏