2011-12-06 75 views
3

我試圖實現基於用戶訪問的視頻流媒體解決方案。PHP流媒體視頻處理器

我必須位於連接到服務器(HTTP // 192.168.100.101/MPEG4/1/media.amp)專用網絡上的許多視頻流,我想「代理」該視頻通過網絡服務器流。

我知道如何設置用戶訪問部分,但是如何將視頻流代理給用戶呢?

我試過這樣的事情,但它似乎並沒有工作。

header('Content-type: application/x-rtsp-tunnelled'); 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, "http//192.168.100.101/mpeg4/1/media.amp"); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
$output = curl_exec($ch); 
echo $output; 
curl_close($ch); 

有關最佳方法的任何想法?其他流媒體網站如何做到這一點?

謝謝:)

回答

1

curl_exec()不適合流輸出。它只會在http請求完成時纔會返回。對於流式傳輸請求,這在理論上應該是「從不」,並且您只需要在某處填寫內存緩衝區。

檢查這個答案解決方法:Manipulate a string that is 30 million characters long

0

嘗試的解決方案就像這個頁面:Streaming POST data through PHP cURL我要自己試試吧,看看它的工作原理,但想到我張貼此之前,在這裏我分心,忘掉這個問題:)

+0

Link是死:( –

1

是的,它很容易做到。不需要手動設置這些標題。讓服務器自動執行。

繼承人的工作腳本,我寫了一個視頻流媒體代理 -

ini_set('memory_limit','1024M'); 

set_time_limit(3600); 

ob_start(); 

**// do any user checks here - authentication/ip restriction/max downloads/whatever** 

**// if check fails, return back error message** 

**// if check succeeds, proceed with code below** 

if(isset($_SERVER['HTTP_RANGE'])) 

$opts['http']['header']="Range: ".$_SERVER['HTTP_RANGE']; 

$opts['http']['method']= "HEAD"; 

$conh=stream_context_create($opts); 

$opts['http']['method']= "GET"; 

$cong= stream_context_create($opts); 

$out[]= file_get_contents($real_file_location_path_or_url,false,$conh); 

$out[]= $http_response_header; 

ob_end_clean(); 

array_map("header",$http_response_header); 

readfile($real_file_location_path_or_url,false,$cong); 
+0

任何試圖這個解決方案? – Arijoon