PHP 流媒体视频处理程序

发布于 2024-12-19 22:25:02 字数 513 浏览 0 评论 0原文

我正在尝试实现基于用户访问的视频流解决方案。

我有许多视频流位于连接到服务器的专用网络上(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);

关于最好的方法有什么想法吗?其他流媒体网站是如何做到的?

谢谢 :)

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

九公里浅绿 2024-12-26 22:25:02

是的,这很容易做到。无需手动设置这些标头。让服务器自动完成。

这是我为视频流代理编写的工作脚本 -

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

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);
花想c 2024-12-26 22:25:02

curl_exec() 不是为流输出而设计的。仅当 http 请求完成时才会返回。对于流请求,理论上“从不”,您只会在某处填充内存缓冲区。

检查此答案以获取解决方法: 操作一个 3000 万字符长的字符串

curl_exec() isn't designed for streaming output. It'll return only when the http request is completed. 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

执妄 2024-12-26 22:25:02

尝试如下页面中的解决方案: Streaming POST通过 PHP cURL 获取数据 我要亲自尝试一下,看看它是否有效,但我想在我分心并忘记这个问题之前我会将其发布到这里:)

Try a solution like in this page: Streaming POST data through PHP cURL I'm gonna try it myself to see if it works, but thought I post this here before I get distracted and forget about this question :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文