PHP:iPad无法播放PHP提供的MP4视频,但是如果直接访问它,它可以

PHP:iPad无法播放PHP提供的MP4视频,但是如果直接访问它,它可以,第1张

PHP:iPad无法播放PHP提供的MP4视频,但是如果直接访问它,它可以

1.第一个主要问题

事实证明,这不是编码问题,而是
在视频转换过程中设置的mp4容器标头存在问题-iPad显然对
准备进行渐进式流式传输的 MP4视频有问题。

首先,我在
这里的一次对话中发现了这一点。转换视频后,我总是使用工具
MP4快速启动来准备视频文件
以进行逐流播放。这是将视频文件
分段(逐步)传输到Flash Player 所必需的,因此它不会加载整个文件
(用户必须等待)。

对于手刹,有一个类似的设置,
称为Web Optimized。它的作用相同:

Web OptimizedAlso 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

<?php// disable zlib so that progress bar of player shows up correctlyif(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:经过几天的研究,麻烦的是只能播放可以在所有其他设备上运行的视频文件。这再次向我证明,苹果之所以成功是因为出色的市场营销,而不是因为出色的软件。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5101952.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-16
下一篇 2022-11-16

发表评论

登录后才能评论

评论列表(0条)

保存