开发者

How to redirect a live data stream adding to it another header and returning it on demand? (PHP)

开发者 https://www.devze.com 2022-12-31 03:18 出处:网络
I have a url like http://localhost:8020/stream.flv On request to my php sctipt I want to return (be something like a proxy) all data I can get from that URL (so I mean my php code should ge开发者_运维

I have a url like http://localhost:8020/stream.flv

On request to my php sctipt I want to return (be something like a proxy) all data I can get from that URL (so I mean my php code should ge开发者_运维问答t data from that url and give it to user) and my header and my beginning of file.

So I have my header and some data I want to write in the beginning of response like

# content headers
        header("Content-Type: video/x-flv");        
        # FLV file format header
        if($seekPos != 0) 
        {
        print('FLV');
        print(pack('C', 1));
        print(pack('C', 1));
        print(pack('N', 9));
        print(pack('N', 9));
    }

How to do such thing?


Here's the code I used to do something very similar, I also forwarded all headers from the original flv to the end user but you can just remove that section if you want to set your own.

$video = fopen(URL, "rb");

// Forward headers, $http_response_header is populated by fopen call
foreach ($http_response_header AS $header) {
    header($header);
}

// Output contents of flv
while (!feof($video)) {
    print (fgets($video));
}

fclose($video);


See the manual entries for fopen and fread.


I've accomplished this using libcurl,

$url = 'http://localhost:8020/stream.flv';
$ch = curl_init();
curl_exec($ch);
curl_close($ch);
0

精彩评论

暂无评论...
验证码 换一张
取 消