简体   繁体   English

PHP流式视频处理程序

[英]PHP Streaming video handler

I'm trying to implement a video streaming solution based on user access. 我正在尝试基于用户访问实现视频流解决方案。

I have many video streams located on a private network connected to the server (http//192.168.100.101/mpeg4/1/media.amp), and I want to "proxy" that video stream through the web server. 我有很多视频流位于连接到服务器的专用网络上(http // 192.168.100.101 / mpeg4 / 1 / media.amp),我想通过Web服务器“代理”该视频流。

I know how to setup the user access part, but how can I proxy the video stream to the user? 我知道如何设置用户访问部分,但如何将视频流代理给用户?

I have tried something like this, but it does not seem to work. 我尝试过类似的东西,但它似乎没有用。

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);

Any ideas on the best way to do this? 有关最佳方法的任何想法吗? How do other streaming sites do it? 其他流媒体网站如何做到这一点?

Thanks :) 谢谢 :)

Yes, its easy to do. 是的,它很容易做到。 No need to set those headers manually. 无需手动设置这些标头。 Let the server do it automatically. 让服务器自动完成。

Heres a working script which I wrote for a video streaming proxy - 下面是我为视频流代理编写的工作脚本 -

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);

curl_exec() isn't designed for streaming output. curl_exec()不是为流输出而设计的。 It'll return only when the http request is completed. 它仅在http请求完成时返回。 For a streaming request, that would theoretically be "never", and you'll just be filling up a memory buffer somewhere. 对于流式传输请求,理论上这将是“从不”,并且您只是在某处填充内存缓冲区。

Check this answer for workarounds: Manipulate a string that is 30 million characters long 检查此答案以获取解决方法: 操作一个长度为3000万个字符的字符串

尝试一下这个页面中的解决方案: 通过PHP cURL流式传输数据我会自己尝试看看它是否有效,但我想在我分散之前发布这个并忘记这个问题:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM