简体   繁体   English

使用PHP进行视频流传输?

[英]Video streaming using PHP?

Alrighty so since the Class I was looking at isn't for remote files but instead is for local files.. I decided to do some searching and found this cURL code that seems promising to actually play REMOTE URI's 好吧,因为我正在查看的课程不是用于远程文件,而是用于本地文件。.我决定进行一些搜索,发现该cURL代码似乎有望实际播放REMOTE URI。

    $head = array_change_key_case(get_headers($path, TRUE));
    $filesize = $head['content-length'];

    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_URL, $path); 
    curl_setopt($curl, CURLOPT_RANGE, max (0, $filesize - 128) . '-' . max (0, $filesize - 1));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $content = curl_exec($curl);

    header("Content-Type: video/mp4");
    header("Cache-Control: max-age=2592000, public");
    header("Expires: ".gmdate('D, d M Y H:i:s', time()+2592000) . ' GMT');
    header("Last-Modified: ".gmdate('D, d M Y H:i:s', @filemtime($this->path)) . ' GMT' );
    echo $content;

This is what I got so far, I copied most of the headers from the class from before and I also am now using cURL for this.. I do get the same result which is just a black player, playing. 到目前为止,这是我得到的结果,我从以前复制了该类的大多数标头,并且现在我也为此使用cURL。.我确实得到了与黑色播放器相同的结果。

And here is the response I get when I echo $content 这是我echo $content时得到的响应

HTTP/1.1 206 Partial Content
Server: nginx/1.4.6 (Ubuntu)
Date: Fri, 06 May 2016 23:56:18 GMT
Content-Type: video/mp4
Content-Length: 128
Last-Modified: Fri, 06 May 2016 19:07:20 GMT
Connection: keep-alive
ETag: "572ceb68-75445cb"
Expires: Fri, 13 May 2016 23:56:18 GMT
Cache-Control: max-age=604800
Cache-Control: public
Content-Range: bytes 122963275-122963402/122963403

If it is a remote URL, check your server allows fopen to open remote files. 如果它是远程URL,请检查服务器是否允许fopen打开远程文件。 allow_url_fopen needs to be enable in your php.ini 需要在您的php.ini中启用allow_url_fopen

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

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