[英]How to redirect a live data stream adding to it another header and returning it on demand? (PHP)
我有一個類似http:// localhost:8020 / stream.flv的網址
應我的PHP sctipt的要求,我想返回(像代理一樣)我可以從該URL獲得的所有數據(所以我的意思是我的php代碼應該從該URL獲取數據並將其提供給用戶)以及標頭和開頭文件。
所以我有我的標題和一些我想在響應開始時寫的數據,例如
# 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));
}
怎么做這樣的事情?
這是我以前執行類似操作的代碼,我還將所有標題從原始flv轉發給了最終用戶,但是如果您要設置自己的內容,則可以刪除該部分。
$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);
我已經用libcurl完成了
$url = 'http://localhost:8020/stream.flv';
$ch = curl_init();
curl_exec($ch);
curl_close($ch);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.