PDA

View Full Version : IP Camera snapshot/video html code



zYx
25-12-14, 17:03
Hi there,

I'm trying to work out how to get my IP cam picture diplayed on the LCD.

The following is the code I use with my IP cam to display all my CCTV cameras on my G19 LCD screen thanks to LCDhost. I was wondering if I could make it work with LCD4Linux:





<html>
<head>
<style type="text/css">
<!--
body{
margin: 0;
padding: 0;
}
--></style>
</head>
<body>
<tr>
<td align="center" valign="middle" border="0"><span style="text-align:center;"><img width="320" height="240" src="http://88.77.66.55:4444/snapshot.cgi?user=username&pwd=password&t=" onload='setTimeout(function() {src = src.substring(0, (src.lastIndexOf("t=")+2))+(new Date()).getTime()}, 1000)' onerror='setTimeout(function() {src = src.substring(0, (src.lastIndexOf("t=")+2))+(new Date()).getTime()}, 5000)' alt=''" /></span></td>
</tr>
</body>
</html>

Walt
26-12-14, 01:05
Great idea. Would like to know this myself.

pembo
27-12-14, 22:20
You can put a URL into the show picture config, so it should work if you put in:
http://88.77.66.55:4444/snapshot.cgi?user=username&pwd=password&t=

Not sure if this will refresh though so you'll need to test - I've only checked with a static image. The alternative is the www-internet converter which can be refreshed...

zYx
27-12-14, 22:23
I'm not at home now so I can't check, but do you think if I use a few screens, will the snapshot refresh every time the screen changes?

It would be nice to just be able to use any html code ;)

pembo
27-12-14, 22:24
You can put a URL into the show picture config, so it should work if you put in:
http://88.77.66.55:4444/snapshot.cgi?user=username&pwd=password&t=

Not sure if this will refresh though so you'll need to test - I've only checked with a static image. The alternative is the www-internet convertor

zYx
28-12-14, 19:28
Weird. I thought it wasn't working at first, but it looks like it does. I wonder if I can use a video stream instead :P

pembo
28-12-14, 20:52
excellent - i'm not sure it can stream a video, but a 1 frame a second image would be good enough :)

(not sure what happened with the dupe post!)

zYx
28-12-14, 23:42
I'm not sure how this refreshing supposed to work here, but the screen refreshes every 5 seconds. It's OK for the time being.

Thanks for the tip anyway. Why didn't I try it before? :P

I haven't tried leaving the IP cam screen on for long, but I did manage to view my cams at 2-4 fps with "quick update" option selected.

Rob van der Does
31-12-14, 08:10
You can put a URL into the show picture config, so it should work if you put in:
http://88.77.66.55:4444/snapshot.cgi?user=username&pwd=password&t=
I tried this for my IP-cam, and although this works fine when used in a browser (so address and user/pass are fine), I get no picture at
all in L4L. Any idea?

pembo
31-12-14, 10:54
You'll need a url to provide an image snapshot from the cam and not a stream

Rob van der Does
31-12-14, 11:13
Yeah, as I said: in the webbrowser this works fine, so URL/user/pass are fine. And refreshing browser gives me the next snapshot.
Apparently just L4L doesn't know how to handle this.

pembo
31-12-14, 14:38
It's just an image and not an HTML response with an image inside it?
If you need to do this, the alternative is to use wget and cron to grab the image (say every 10 seconds or so) to save it locally, then link to the local image in LCD4Linux.

Rob van der Does
31-12-14, 15:17
It's just an image and not an HTML response with an image inside it?
Yes, you're right; it's a web page with an image as (the only) contents.


If you need to do this, the alternative is to use wget and cron to grab the image (say every 10 seconds or so) to save it locally, then link to the local image in LCD4Linux.
This sounds like you know exactly how to do this. You care to share some knowledge with a layman?

pembo
31-12-14, 16:00
You could try first just grabbing the image url out of the HTML page, paste this into your browser and see if this refreshes the link. As the browser caches the page, you might need to stick a ?a=1 at the end, then ?a=2, ?a=3, etc just to avoid the cache whilst you test this works.

zYx
31-12-14, 18:11
I tried this for my IP-cam, and although this works fine when used in a browser (so address and user/pass are fine), I get no picture at
all in L4L. Any idea?

The best way to check the url of your IP camera snaphot is to click on the snapshot icon in your IP webif and then check its url.

Did you try that URL in your browser first?

Update: I have four IP cameras, two are the same make and the other two are two different makes. All of them have the very same URL structure.

Update 2: Now I see there's more posts here :P

Update 3: I use this bit of code n cron:


<?
$oldfilename = 'snapshot.cgi?user=user&pwd=password';
$newfilename = date('Ymd_Hi', time() - 3600).".jpg";
$newfilename2 = date('Ymd_Hi', time() - 3600).".jpg";
define('BUFSIZ', 4095);
$url = 'http://55.66.77.88:99999/snapshot.cgi?user=user&pwd=password';
$rfile = fopen($url, 'r');
$lfile = fopen(basename($url), 'w');
while(!feof($rfile))
fwrite($lfile, fread($rfile, BUFSIZ), BUFSIZ);
fclose($rfile);
fclose($lfile);
rename($oldfilename,$newfilename);

$SourceFile = $newfilename;
$DestinationFile = $newfilename;
$WaterMark = date('d.m.Y H:i', time() - 3600)." ";

watermarkImage ($SourceFile, $WaterMark, $DestinationFile);

function watermarkImage ($SourceFile, $WaterMark, $DestinationFile) {
list($width, $height) = getimagesize($SourceFile);
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($SourceFile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height);
$color = imagecolorallocate($image_p, 255, 0, 255);
$font = 'visitor2.ttf';
$font_size = 11;
imagettftext($image_p, $font_size, 0, 10, 470, $color, $font, $WaterMark);
if ($DestinationFile<>'') {
imagejpeg ($image_p, $DestinationFile, 100);
} else {
header('Content-Type: image/jpeg');
imagejpeg($image_p, null, 100);
};
imagedestroy($image);
imagedestroy($image_p);
};
?>



<img src="<?=$newfilename2?>" border="0"></img>

I'm using it for slightly different purposes (time lapse) but you get an idea. The code is downloading a picture from the camera, saves it as "snapshot.cgi?user=user&pwd=password" file name and then renames it according to a date it was taken. Then a water mark with current time and date is applied.