2011-12-06 72 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