簡體   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