Zomeminder Webcams 2.0

Ok, following on from my post yesterday here’s the database table part of my new scripts.


I place this under the zoneminder database itself, that way it’s all kept together.
A sample entry would be:-

INSERT INTO `WebCams` (`ID`, `Name`, `URL`, `Start`, `Stop`, `Refresh`, `Monitor`, `Enabled`) VALUES (1, 'Aberystwyth Pier', 'http://www.ceredigion.gov.uk/english/visiting/aber_webcam/img/994.jpg', '00:00:00', '23:59:59', 900, 'A', 1);

Pretty straight forward descriptions for Name, URL, Start & Stop. One thing to note is I made the script to interpret the start and stop so you can start at 10pm and finish at 2am and it will happily work (took a bit for my head to get around it though).
The Refresh column is how often it should grab a new image. I slowed the script down to run a refresh every 60 secs for a few reasons, first not to query the database constantly and 2nd as a safeguard that I can’t hammer any webcams trying to pull too often.
The Monitor I use as A,B,C this will be assigned to the name of what’s downloaded and to the rotate file that you reference in Zoneminder.
Enabled is either 0-No or 1-Yes.

That’s pretty much it. Next bit I’ll post up the actual script.

Blog stats

Just checked my blog stats, I’m amazed people are actually reading stuff I’ve posted. Can’t remember if I’ve allowed feedback and questions, so will check the posts tomorrow as I’d love to know what people think and if I’ve missed anything or can help anyone out.
One thing I have to remember to post about tomorrow is my problems with viewing zoneminder cameras remotely via the web browser.
So thanks to anyone who actually reads anything I’ve done.

Raspberry PI

Not sure if anyone reads these at all, but thought I’d make a comment as I go.
I’m waiting on news from Raspberry PI to know when they’re being launched. At first they’re going to have a run of just 1000 units, I have a load of ideas I’d like to try and do on it from some home automation, security system, all the way to maybe getting zoneminder running on it with a webcam.
It looks a fantastic little board and I think the idea of putting them into schools and letting kids play, program and create it a great one. I wish they’d done that kind of thing when I was in school. I wanted to do the computer control part of CDT but the teacher wouldn’t run it, or even let me do it as an extra after school in my own time.

Still I’ve done little bits and pieces as I go, but I’m really looking forward to the Raspberry PI coming out and getting to just play and experiment again. After looking on the forums yesterday I doubt very much that I’d be in with a chance of getting one of the 1st 1k, and it’s looking like a good couple of runs of 1k each are going to shift like hot cakes, but I’ll be looking out hoping the site doesn’t crash as soon as I know they’re out.

Zoneminder rotating Webcam images.

Note: I’ve made an entire new system running from a database that can accommodate multiple rotating outputs, because I liked seeing the webcams so much on my tv along with my own cctv. I leave this here as an idea script. btw, there was an update for 3 monitors based on the below that used this very script, but I’m going to jump straight to the database one as it’s much better.

I had the idea to include some public webcams onto my zoneminder monitor, I’m already running xlib_shm so was considering find a way within that code to pickup some jpegs and display them in one area. However this seemed overly complicated, it seemed a much simpler idea to create a new monitor in zoneminder that picks up from a local file and just add that monitor onto the xlib_shm line in the xinitrc file so it displays on bootup.

So the steps.
1) create a new directory /var/cache/zoneminder/webcams
2) create a text doc to hold the url’s /var/cache/zoneminder/webcams/urls.txt for example “http://www.ceredigion.gov.uk/english/visiting/aber_webcam/img/994.jpg” without “
3) create a text doc ~/webcams.sh with the following :
echo Directory : $DIR
echo Pull Interval : $PULLINTERVAL
echo Rotate Interval : $ROTATEINTERVAL
cd $DIR
for i in `cat $DIR/urls.txt`
   wget -q $i -O $FILENO.jpg
convert $CURRENTIMAGE.jpg -resize 640x480! rotate.jpg
if [ "$CURRENTIMAGE" -eq "$FILENO" ]; then
PGREPXLIB=`pgrep xlib_shm`
 if [ -z $PGREPXLIB ]; then
   startx &
while true; do
DATE=`date +%s`
   if [ "$DATE" -gt "$NEXTPULL" ]; then
   if [ "$DATE" -gt "$NEXTROTATE" ]; then
   if [ "$DATE" -gt "$NEXTXLIBCHECK" ]; then
sleep 2
4) chmod +x ~/webcams.sh
5) Now add a new monitor to Zoneminder pulling from a local file /var/cache/zoneminder/webcams/rotate.jpg with dimensions 640×480.
6) After testing that this script runs while I’m connected via putty, I add the following to /etc/init.d/zoneminder under the startx & ‘/root/webcams.sh &’. That way when the computer starts up and everything is displayed the webcams script is also started and away it rotates.
7) Add the following to /etc/init.d/zoneminder under the stop section where I added kill -9 xlib_shm ‘killall -9 webcams.sh’. Now the script is stopped if zoneminder is stopped.
One thing to note is that restarting zoneminder via the interface is not the same as running /etc/init.d/zoneminder restart. So the script and does not get reset when restarting via the interface.

Zoneminder XLIB_SHM

Ok it’s been a good while since my last post, and it’s not that I haven’t been doing anything, just not writing about it. Which just creates problems when I need to remember how what I did and how.

I needed something to get my monitors back on my similar to my windows setup. That used to rotate around the cameras and would bring to the front specific cameras when motion was detected.

After a bit of searching I found xlib_shm http://www.zoneminder.com/wiki/index.php/Xlib_shm
Although it says it only works with 1.22.3, I’m currently running 1.24.2 on Ubuntu 11.04.

So after installing it and trying to run via the command line “./xlib_shm -m 11 -m 12 -m 3 -m 13 -m 14 -c 2 -k 0x7a6d0000” it complained about not being able to open the display. of course I’m running it from a terminal on the server itself, but gdm is already lauched and I’d alt+ctrl+f1’d out of it. So I stopped gdm with “/etc/init.d/gdm stop” and tried again, hey presto it runs.

So now how do I get this to run on boot?

One option is to have gdm auto login and then auto run xlib_shm. I had a few problems with this approach, First the login counter, it takes a few seconds to auto login and kick in xlib_shm and it’s just a bit untidy. Second xlib_shm launches in a window doesn’t look very pretty and I’d prefer full screen. Third was the mouse pointer happily sat smack in the middle of the screen, not a huge problem for a 4 split, but single screen or 9 and it’s in the way of the main detail on the picture.

So kill that idea, I want it straight in no hassle as quick as it can. So the best thing I could come up with was stop gdm launching and make a new script to startup xlib_shm. unfortunately this approach seemed to hit it’s own problems. killing gdm wasn’t as easy as it should have been because of changes in the way it’s now started in Ubuntu 11.04, and adding xlib_shm into the init.d was proving unreliable sometimes it beat gdm and grabbed the screen othertimes it didn’t.

So I had to find another way, and my answer was to try and figure out how X was started.

I ended up editing ‘/etc/X11/xinit/xinitrc’
commenting out the ‘/etc/X11/Xsession’ line and adding ‘exec /usr/sbin/xlib_shm -m 11 -m 12 -m 3 -m 13 -m 14 -m 15 -m 18 -m 19 -m 20 -c 3 -k 0x7a6d0000’ to the bottom.
now starting X with “startx” fires up xlib_shm full screen with a 9 split.
Problem hit though with the screen turning itself off.
Found out that setting a couple of dpms options then starting x would solve this so added the following into the xinitrc file after the exec line

xset s off &
xset -dpms &

Now to get this starting with the boot. Solution edit the ‘/etc/init.d/zoneminder’
Within the start section add ‘startx &’ and in the stop section add ‘killall -9 xlib_shm’.
Now on each reboot X starts up with xlib_shm and the screen doesn’t shutoff at all.

I’ve no doubt theres bits in here that I’ve missed, I got this all running months ago. When I did the same similar on a 2nd system, it was pretty straight forward and similar but I did hit another issue.
For some reason xlib_shm would occasionally crash out and return to the command prompt. However between this change and installing that I’d setup scripts to pull a few webcams and display them on a zoneminder monitor rotating the image. As that script fires a rotate every 10 seconds, my answer to the crashing was to add a check into this script to see if xlib_shm was running and if not to startx &.

So that’s the brief outline of me getting xlib_shm to work with Zoneminder 1.24.2 on Ubuntu 11.04.

One thing to note, restarting zoneminder via the interface is not the same as running /etc/init.d/zoneminder restart. Because of this via the interface does not restart xlib_shm. This causes problem (mainly when I was testing) because the zoneminder feeds would shutdown and xlib_shm would then crash. I got used to only restarting via the commendline, but the script mentioned above would counter this problem should xlib_shm crash now.