简体   繁体   English

从远程位置到可访问Web服务器的PHP MJPEG流

[英]PHP MJPEG stream from remote location to accessibly webserver

I'm currently using MJPEG_STREAMER, which turns my camera into a stream, to be viewed on the web. 我目前正在使用MJPEG_STREAMER,它将我的相机转换为流,以便在网络上查看。 This works flawlessly. 这可以完美地工作。

The problem is, I have a closed network, so that it is only accessible from one location, depictured here as the webserver: 问题是,我有一个封闭的网络,因此只能从一个位置进行访问,这里描述为网络服务器:

[INTERNET] --- [NETWORK/ROUTER] + --- [WEBSERVER]
                                + ----------------- [CAMERA]
                                + ----------------- [LAPTOP]
                                + ----------------- [PC]

This means that internally, from within my own network, I am able to reach all devices, including the camera, but from the outside, only the webserver is reachable. 这意味着在内部,我可以通过自己的网络访问包括摄像头在内的所有设备,但从外部只能访问Web服务器。 And I want to keep it this way. 我想保持这种方式。

QUESTION: 题:

I want to be able to show the MJPEG stream from the camera, on the webserver. 我希望能够在网络服务器上显示来自摄像机的MJPEG流。

I HAVE TRIED: 我努力了:

MJPEG_STREAMER has also the option to display a snapshot of the stream. MJPEG_STREAMER还可以选择显示流的快照。 With the following code on the webserver, from the outside I'm able to get a snapshot: 使用Web服务器上的以下代码,可以从外部获取快照:

<?php
header("Content-Type: image/jpeg");
$url = "http://192.168.2.145:8080/?action=snapshot.jpg";
$imgContents = file_get_contents($url);
$image = @imagecreatefromstring($imgContents);
imagejpeg($image);
?>

As I now know I'm able with PHP to fetch data from my internal network to be displayed on the webserver, does anyone know instead of this static image, I'm able to show the MJPEG stream? 现在我知道我可以使用PHP从内部网络中获取数据以显示在Web服务器上,有人知道除了该静态图像之外,我还可以显示MJPEG流吗?

With this following code I was able to 'tunnel' the MJEPG from the camera to the webserver, to be viewed from the outside: 通过以下代码,我可以将MJEPG从摄像机“隧道”到Web服务器,以便从外部进行查看:

<?php
$server = "192.168.2.145";
$port = 8080;
$url = "/?action=stream";
set_time_limit(0); 
$fp = fsockopen($server, $port, $errno, $errstr, 30);
if (!$fp) {
        echo "$errstr ($errno)<br>\n";
} else {
        $urlstring = "GET ".$url." HTTP/1.0\r\n\r\n";
        fputs ($fp, $urlstring);
        while ($str = trim(fgets($fp, 4096)))
        header($str);
        fpassthru($fp);
        fclose($fp);
}
?>

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

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