php格式视频ipad打开方式,PHP:iPad无法播放PHP提供的MP4视频,但是如果直接访问它,它可以...

小编典典

1.第一个主要问题

事实证明,这不是编码问题,而是

在视频转换过程中设置的mp4容器标头存在问题-iPad显然对

准备进行渐进式流式传输的 MP4视频有问题。

首先,我在

这里的一次对话中发现了这一点。转换视频后,我总是使用工具

MP4快速启动来准备视频文件

以进行逐流播放。这是将视频文件

分段(逐步)传输到Flash Player 所必需的,因此它不会加载整个文件

(用户必须等待)。

对于手刹,有一个类似的设置,

称为Web Optimized。它的作用相同:

Web Optimized

Also known as "Fast Start"

This places the container header at the start of the file, optimizing it for streaming across the web.

如果启用此选项并转换视频,iPad将不会播放视频

文件!而是显示错误“操作无法完成”。

iPad删除线播放按钮

自己检查一下并进行测试:视频测试

资源。

2.第二个问题

在生产环境中,我始终使用PHP来检查引荐来源。我发现

,iPad不会发送引荐来源信息。这也可以防止

流式传输,并且您还将看到“不能播放”符号(“击中播放”

图标)。

3.第三个问题

我不知道为什么,但是iPad只接受来自

此脚本的视频流http://ideone.com/NPSlw5

// disable zlib so that progress bar of player shows up correctly

if(ini_get('zlib.output_compression')) {

ini_set('zlib.output_compression', 'Off');

}

$folder = '.';

$filename = 'video.mp4';

$path = $folder.'/'.$filename;

// from: http://licson.net/post/stream-videos-php/

if (file_exists($path)) {

// Clears the cache and prevent unwanted output

ob_clean();

$mime = "video/mp4"; // The MIME type of the file, this should be replaced with your own.

$size = filesize($path); // The size of the file

// Send the content type header

header('Content-type: ' . $mime);

// Check if it's a HTTP range request

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

// Parse the range header to get the byte offset

$ranges = array_map(

'intval', // Parse the parts into integer

explode(

'-', // The range separator

substr($_SERVER['HTTP_RANGE'], 6) // Skip the `bytes=` part of the header

)

);

// If the last range param is empty, it means the EOF (End of File)

if(!$ranges[1]){

$ranges[1] = $size - 1;

}

// Send the appropriate headers

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

header('Accept-Ranges: bytes');

header('Content-Length: ' . ($ranges[1] - $ranges[0])); // The size of the range

// Send the ranges we offered

header(

sprintf(

'Content-Range: bytes %d-%d/%d', // The header format

$ranges[0], // The start range

$ranges[1], // The end range

$size // Total size of the file

)

);

// It's time to output the file

$f = fopen($path, 'rb'); // Open the file in binary mode

$chunkSize = 8192; // The size of each chunk to output

// Seek to the requested start range

fseek($f, $ranges[0]);

// Start outputting the data

while(true){

// Check if we have outputted all the data requested

if(ftell($f) >= $ranges[1]){

break;

}

// Output the data

echo fread($f, $chunkSize);

// Flush the buffer immediately

@ob_flush();

flush();

}

}

else {

// It's not a range request, output the file anyway

header('Content-Length: ' . $size);

// Read the file

@readfile($path);

// and flush the buffer

@ob_flush();

flush();

}

}

die();

?>

我希望这些信息可以帮助其他人解决这个问题。

更新:三个月后,在生产环境中,我的一些用户仍然报告了播放问题。Safari似乎还有另一个问题。我建议他们使用Chrome foriPad(已修复)。

PS:经过几天的研究,麻烦的是只能播放可以在所有其他设备上运行的视频文件。这再次向我证明,苹果之所以成功是因为出色的市场营销,而不是因为出色的软件。

2020-05-29

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值