php保存视频,使用php输出mp4视频

好的,基本上我有一个项目,要求对用户隐藏视频,同时仍然能够查看它们(使用php)。这是我到目前为止所得到的:

video.php文件具有以下内容:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'path/to/movie.mp4');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_HEADER, 0);

$out = curl_exec($ch);

curl_close($ch);

header('Content-type: video/mp4');

header('Content-type: video/mpeg');

header('Content-disposition: inline');

header("Content-Transfer-Encoding:­ binary");

header("Content-Length: ".filesize($out));

echo $out;

exit();

?>

并且应该显示此内容的html文件使用的是预期的html5。现在这是东西..当我直接嵌入这个(不是)时,它起作用了。但是它在我的iPhone上不起作用,并且在标签中也不起作用…如果我使用直接文件而不是php包装器,那么一切也可以在我的iPhone上正常工作…

所以我想我的问题是:可以完美复制可通过iPhone和HMTL5流式传输的mp4的正确header()信息是什么?

video.php文件:

$file = 'path/to/videofile.mp4';

$fp = @fopen($file, 'rb');

$size = filesize($file); // File size

$length = $size; // Content length

$start = 0; // Start byte

$end = $size - 1; // End byte

header('Content-type: video/mp4');

header("Accept-Ranges: 0-$length");

if (isset($_SERVER['HTTP_RANGE'])) {

$c_start = $start;

$c_end = $end;

list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);

if (strpos($range, ',') !== false) {

header('HTTP/1.1 416 Requested Range Not Satisfiable');

header("Content-Range: bytes $start-$end/$size");

exit;

}

if ($range == '-') {

$c_start = $size - substr($range, 1);

}else{

$range = explode('-', $range);

$c_start = $range[0];

$c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;

}

$c_end = ($c_end > $end) ? $end : $c_end;

if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {

header('HTTP/1.1 416 Requested Range Not Satisfiable');

header("Content-Range: bytes $start-$end/$size");

exit;

}

$start = $c_start;

$end = $c_end;

$length = $end - $start + 1;

fseek($fp, $start);

header('HTTP/1.1 206 Partial Content');

}

header("Content-Range: bytes $start-$end/$size");

header("Content-Length: ".$length);

$buffer = 1024 * 8;

while(!feof($fp) && ($p = ftell($fp)) <= $end) {

if ($p + $buffer > $end) {

$buffer = $end - $p + 1;

}

set_time_limit(0);

echo fread($fp, $buffer);

flush();

}

fclose($fp);

exit();

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值