将图像/视频流嵌入网页 [英] Embedding Image/Video Stream into webpage

查看:169
本文介绍了将图像/视频流嵌入网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 PHP网页,允许访问者看到来自网络摄像头的视频流图像 不允许访问者获取原始网址/ URI
换句话说,我有一个在给定地址操作的ip camera:port我可以看到嵌入HTML体内的流类似于:

I'm trying to create a PHP webpage that allow the visitor to see a video stream or an image coming from a webcam without allowing the visitors to grab it's original URL/URI. In other words, I have an ip camera operating at a given address:port and I can see the stream embedding in a HTML body something like this:

    <img src="http://5.246.77.89:8080/videostream.cgi?user=myusername&amp;pwd=mypass&amp;resolution=32&amp;rate=15" alt="">

或者如果我们想要静态图片:

or alternatively if we want a static image:

    <img src="http://5.246.77.89:8080/snapshot.cgi?user=myusername&amp;pwd=mypass&amp" alt="">

现在的问题是如果有人看到页面后面的HTML代码会看到显然,相机的URL及其用户/密码凭据。这允许访问者随时连接到摄像机,即使不必访问托管此服务的页面,他们只需要在任何浏览器中键入URL

Now the problem is that if anyone look at the HTML code behind the page will see the URL of the camera along with its user/password credentials, obviously. This allow the visitor to connect to the camera at any time even without having to go on the page that is hosting this service, they just need to type into any browser to the URL

http://myip:myport/videostream.cgi?user=admin&amp;pwd=fewf2d53BVH&amp;resolution=32&amp;rate=15

我不希望用户能够这样做。所以我有一个想法:如果我能够将流包装到一个充当中间人的php网页中,我可以给访问者提供视频而不让他们知道原始来源。原始IP:PORT只能从我的服务器上看到。显然,他们总是可以使用我的网页的URL,但他们永远不会看到相机的用户/密码,我可以随时锁定服务。
此外,为了提高安全性,我可以设置托管网络摄像头的路由器,以接受来自我的网络服务器的连接。这将对尝试直接连接到webcabm的恶意用户起隐秘作用。
我可以在服务器端做什么来获得这种行为?

I don't want that the user is able to do that. So I had an idea: If I'm able to wrap the stream into a php webpage acting as a 'man-in-the-middle' I can give the visitor the video without letting them know the original source. The original IP:PORT will be visible only from my server. Obviously they will always be able to use the URL of my webpage but they will never see the user/password of the camera and I can lock the service out at any time. Furthermore to improve security I can setup the router hosting the webcam to accept connections coming from my webserver only. This will act as a stealth against malicious users attempting to connect directly to the webcabm. What can I do on the server-side to obtain this behaviour?

推荐答案

好吧,至少对于图像你可以使用curl ...
正如我在评论中指出的那样,你可以创建一个包含以下内容的php文件(例如,my.php):

Well, at least for images you could use curl... As I've pointed out in the comments, you may create a php file (say, my.php) containing something like the following:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/?password=4444&login=1111');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$picture = curl_exec($ch);
curl_close($ch);
//Display the image in the browser
header('Content-type: image/jpeg');
echo $picture;

而不只是写:

 <img src='my.php'>

P.S。虽然我认为它不是最好的做事方式,但看起来它解决了这个问题。 img src中没有更多私人数据。我对视频格式一无所知,但对于图像来说,它似乎很容易。
您可以在这里阅读更多关于卷曲的信息: http://php.net/manual /en/book.curl.php

P.S. Although I believe it is NOT the best way to do things, it looks like it solves the problem. No more private data in img src. I have never anything alike with video formats, but as for images it seems quite easy. You can read more about curl here: http://php.net/manual/en/book.curl.php

这篇关于将图像/视频流嵌入网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆