'Is there a simple way to stream a non-public IP camera into a website?

I'm trying to embed a non-public rtsp camera into a website without third-party software or plugins and capable for all browsers and devices.

I found a workaround that works but it is not elegant. It consists in taking continuous snapshots of the camera from a jpeg camera access url and copy that to a file with a running php script on the server:

 <?php
 while (True) {
    copy('http://192.168.x.x/snap.jpg?JpegSize=M&JpegCam=1', './webcam/frame.jpg'); // local URL from my camera to obtain jpg snapshot
    usleep (150000); // microseconds!!
 }
 ?>

Then, on the client browser, this served page contains a javascript function that is responsible with refreshing this snapshot and produce a webcam effect:

<script>
function reloadWebcam() {
   var now = new Date();
   document.images['webcam'].src = './webcam/frame.jpg?' + now.getTime();
}
</script>

...

<img name="webcam" align="center" width="640" height="480" scrolling="no">
<script>
setInterval('reloadWebcam()', 300); // 300 miliseconds
</script>

So, it works but I'm looking for:

a) an easy solution but more elegant than this.

b) an improvement to this solution with a way to avoid subprocess of copy on server and/or avoid javascript refresh in client browser.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source