繁体   English   中英

从一台服务器通过另一台服务器流式传输视频

[英]Streaming video from one server thru another

我的脚本需要帮助,我花了很长时间找出它有什么问题,但我找不到任何东西。

基本上在我的第一台服务器上我包含视频文件,在我的第二台服务器上我流式传输这些文件。 要从第一台服务器获取文件,您必须使用第二台服务器的 IP(基本上我只允许我的服务器与第一台服务器连接)

所以为了获取这些文件,我使用 cURL 函数,因为所有视频都将通过服务器 2。

我这样做了:

$url = "111.111.111.111/example.flv";

                                    $ch = curl_init();
                                    $timeout = 0;
                                    curl_setopt ($ch, CURLOPT_URL, $url);
                                    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

                                    $video = curl_exec($ch);
                                    curl_close($ch);
                                    // output to browser
                                    header("Content-type: video/x-flv");

                                   echo ' <a href="'.$video.'" style="display:block;width:920px;height:600px" id="player"> 
    </a> 
    <script>
        flowplayer("player", "flowplayer-3.2.16.swf");
    </script>';

所以我所做的是: 1. 我在 $url 中有一个视频链接 2. 我使用 cURL 打开新连接 3. 我从链接中获取数据。 4. 然后我把这个视频保存在 $video 5. 我试着打开它。

但它不起作用......当我打开这个网站时,向我展示这个:

FLV���  �����ÖY��������
onMetaData����metadatacreator�3Yet Another Metadata Injector for FLV - Version 1.8�hasKeyframes�hasVideo�hasAudio�hasMetadata�canSeekToEnd�duration�@Ļj◊
=p§�datasize�AĽ≥i����   videosize�A∂ąęZ���� framerate�@9�70Ō'�
videodatarate�@|<GłÕŰĢ�videocodecid�@�������width�@Ą�������height�@v@������ audiosize�AĒ8»,����
audiodatarate�@Xsöł¶@ű�audiocodecid�@$�������audiosamplerate�@�������audiosamplesize�?ū�������stereo�filesize�AĽ≥Óv����
lasttimestamp�@Ļj◊
=p§�lastkeyframetimestamp�@Ļj◊
=p§�lastkeyframelocation�AĽ≥Ób����  keyframes�
filepositions

所以我得到字符串中的数据...

你知道我必须做什么,才能流式传输这个文件吗??

您不能同时输出 HTML 和 FLV 数据。 我建议使用以下代码创建一个单独的 PHP 文件:

$url = "111.111.111.111/example.flv";

header("Content-type: video/x-flv");
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_exec($ch);
curl_close($ch);

然后你可以把你的播放器代码放在其他地方,比如:

<a href="/path/to/first/file.php" style="display:block;width:920px;height:600px" id="player">

暂无
暂无

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

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