简体   繁体   中英

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. 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. 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.

I HAVE TRIED:

MJPEG_STREAMER has also the option to display a snapshot of the stream. With the following code on the webserver, from the outside I'm able to get a snapshot:

<?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?

With this following code I was able to 'tunnel' the MJEPG from the camera to the webserver, to be viewed from the outside:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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