简体   繁体   English

PHP 视频流到 iPad

[英]PHP Video Streaming to iPad

I am trying to stream mp4 video via PHP.我正在尝试通过 PHP 流式传输 mp4 视频。 My application loads video from where it is stored in blocks and serves the appropriate parts.我的应用程序从存储在块中的位置加载视频并提供适当的部分。 Uses these headers:使用这些标题:

header("Content-Type: $contenttype");
header("Content-Length: $filesize");
header('Accept-Ranges: bytes');

It can also serve partial content when requested using the following additional headers and outputing the correct bytes:当请求使用以下附加标头并输出正确的字节时,它还可以提供部分内容:

header('HTTP/1.1 206 Partial Content');
header("Content-Range: bytes $start-$end/$filesize");

Streaming works great in Chrome and via VLC, however will not work on iPad.流媒体在 Chrome 和 VLC 中运行良好,但不适用于 iPad。 The test mp4 file is confirmed working on ipad.测试 mp4 文件已确认可在 ipad 上使用。

Anybody have any luck with this?有人有这方面的运气吗? Any advice would be greatly appreciated!任何建议将不胜感激!

Happened to see this after years, I'll leave my answer anyways.几年后碰巧看到这个,无论如何我都会留下我的答案。

Since Apple Inc. uses H.264 encoding as default for videos, if you use codecs other than H.264 you might find your video playing smoothly on native apps, but not in browser like Safari.由于 Apple Inc. 使用 H.264 编码作为视频的默认编码,如果您使用 H.264 以外的编解码器,您可能会发现您的视频在本机应用程序上播放流畅,但在 Safari 等浏览器中则不然。

In this case you likely should re-encode your video using ffmepg before streaming through php code.在这种情况下,您可能应该在通过 php 代码流式传输之前使用 ffmepg 重新编码您的视频。 Your PHP code looks good to me.你的 PHP 代码看起来不错。

Remember to add --faststart flag to move the fastmoov to the beginning of your video so it starts playing at once.请记住添加--faststart标志以将fastmoov移动到视频的开头,以便它立即开始播放。

Yes, its easy to do.是的,这很容易做到。 No need to set those headers manually.无需手动设置这些标题。 Let the server do it automatically.让服务器自动完成。

Heres a working script -这是一个工作脚本 -

ob_start();

if( isset($_SERVER['HTTP_RANGE']) )
      $opts['http']['header']="Range: ".$_SERVER['HTTP_RANGE']; 

$opts['http']['method']= "HEAD"; 
$conh=stream_context_create($opts); 
$opts['http']['method']= "GET";
$cong= stream_context_create($opts);
$out[]= file_get_contents($real_file_location_path_or_url,false,$conh); 
$out[]= $http_response_header; 
ob_end_clean(); 
array_map("header",$http_response_header); 
readfile($real_file_location_path_or_url,false,$cong); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM