相关疑难解决方法(0)

直接访问时播放MP4,但在iOS上通过PHP读取则不播放

我使用PHP脚本在提供视频请求之前验证它们.此脚本可在桌面上使用Safari和Chrome按预期工作.但是在iOS上,我得到了一个破坏的播放按钮.

我确定该视频已正确编码为iPhone/iPad,因为当我直接访问它时,它按预期工作.

相关的PHP代码:

$file_name = 'test-video.mp4';
$file_size = (string)(filesize($file_name));
header('Content-Type: video/mp4');
header('Content-Length: '.$file_size);
readfile_chunked($file_name);
exit;
Run Code Online (Sandbox Code Playgroud)

(readfile_chunked()类似于readfile()非常大的文件,可以在PHP手册页的注释中找到:http://php.net/manual/en/function.readfile.php.无论如何,test-video.mp4只有~5 MB,这是小于内存限制 - 在这种情况下,我实际上可以在正常情况下替换readfile()并产生完全相同的行为.)

test-video.mp4直接访问时获得的标题是:

Accept-Ranges:bytes
Connection:Keep-Alive
Content-Length:5558749
Content-Type:video/mp4
Date:Sun, 27 Jun 2010 21:02:09 GMT
Etag:"1c04757-54d1dd-489944c5a6400"
Keep-Alive:timeout=10, max=30
Last-Modified:Tue, 22 Jun 2010 01:25:36 GMT
Server:Apache/2.2.15 (CentOS) mod_ssl/2.2.15 0.9.8l DAV/2 mod_auth_passthrough/2.1 FrontPage/5.0.2.2635
Run Code Online (Sandbox Code Playgroud)

PHP脚本的标头是:

Connection:Keep-Alive
Content-Disposition:inline; filename="test-video.mp4"
Content-Length:5558749
Content-Type:video/mp4
Date:Sun, 27 Jun 2010 21:03:32 GMT
Keep-Alive:timeout=10, max=15
Server:Apache/2.2.15 (CentOS) mod_ssl/2.2.15 0.9.8l DAV/2 mod_auth_passthrough/2.1 …
Run Code Online (Sandbox Code Playgroud)

php html5-video ios

18
推荐指数
2
解决办法
2万
查看次数

通过PHP的MP4视频传输在Google Chrome中失败

我目前正在尝试通过PHP脚本提供用于HTML5视频(使用video-js)的MP4视频,以控制视频访问.经过一些研究,我得到了这个工作,借助于此处stackoverflow文章.如果我导航到PHP脚本,我可以在Firefox,Safari和IE中查看视频,就像我通过其绝对路径(例如localhost/myvideo.mp4而不是localhost/myscript.php)查看它一样.我的问题在于谷歌浏览器,它只是显示一个黑屏,中间有一个小型媒体播放器,并且什么也没做.

我尝试使用快速重写,例如localhost/avideo.mp4,它路由到PHP脚本,但不幸的是,这并没有改变任何东西.

这是我的脚本:

if (is_file($uri)) {
    header('Content-Type: video/mp4');
    if (isset($_SERVER['HTTP_RANGE'])) {
        $this->rangeDownload($uri);
        exit;
    } else {
        header("Content-Length: ".filesize($uri));
        $this->readfile_chunked($uri);
        exit;
    }
} else {
    //error
}
Run Code Online (Sandbox Code Playgroud)

rangeDownload方法直接来自此链接的附录A,如上述stackoverflow文章中所建议的那样.

php video html5 mp4 google-chrome

13
推荐指数
1
解决办法
3933
查看次数

用PHP读取mp4文件

我正在尝试用PHP读取mp4文件,我现在正在做的是:

<?php
header("Content-Length: filesize");
readfile('file.mp4');
?>
Run Code Online (Sandbox Code Playgroud)

但这样我就不能跳过甚至回去,直到视频没有100%加载.当然,当我直接从文件中读取时(video.mp4),一切顺利.

谢谢.

php mp4 readfile

5
推荐指数
2
解决办法
3万
查看次数

如何加密URL和解密以访问被拒绝的访问内容?

我创建了一个名为secure的文件夹,在该文件夹中,我有一个文件.htaccess和这些文件.mp4

secure
    |--- trailer.mp4
    |--- .htaccess
Run Code Online (Sandbox Code Playgroud)

我的档案 .htaccess

RewriteEngine on

RewriteRule ^(.*)/(.*)/(.*)$ file.php?h=$1&t=$2&v=$3
RewriteRule ^$ - [F]
RewriteRule ^[^/]+\.(flv|mp4)$ - [F]
Run Code Online (Sandbox Code Playgroud)

通过此表格,我可以毫无问题地访问文件。

$path = "secure/trailer.mp4";
$size=filesize($path);

$fm=@fopen($path,'rb');
if(!$fm) {
  // You can also redirect here
  header ("HTTP/1.0 404 Not Found");
  die();
}

$begin=0;
$end=$size;

if(isset($_SERVER['HTTP_RANGE'])) {
  if(preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches)) {
    $begin=intval($matches[0]);
    if(!empty($matches[1])) {
      $end=intval($matches[1]);
    }
  }
}

if($begin>0||$end<$size)
  header('HTTP/1.0 206 Partial Content');
else
  header('HTTP/1.0 200 OK');

header("Content-Type: video/mp4");
header('Accept-Ranges: bytes');
header('Content-Length:'.($end-$begin));
header("Content-Disposition: inline;");
header("Content-Range: bytes $begin-$end/$size");
header("Content-Transfer-Encoding: …
Run Code Online (Sandbox Code Playgroud)

php encryption

5
推荐指数
0
解决办法
253
查看次数

标签 统计

php ×4

mp4 ×2

encryption ×1

google-chrome ×1

html5 ×1

html5-video ×1

ios ×1

readfile ×1

video ×1