Friday, January 9, 2009

Zoneminder, Debian and a USB webcam

So here at the home front (our office), we've been having some strange goings on. Apparently students hold grudges against teachers that award grades fairly (that is, you get the grade you earn). So someone has been doing heinous things to teachers belongings and helping those things to go periodically missing, forcefully adjusted, etc.

Knowing that we can video record here in the USA without a warrant or legal cause to do so, we decided to setup a zoneminder system. For those of you who do not know, Zoneminder is a Linux based, open source CCTV system. One can setup a camera on the computer, set up Zoneminder, setup the camera in Zoneminder and VOILA! A Closed-Circuit TV system is up and running at a whim!

Unfortunately, ZoneMinder (ZM) doesn't really have all that cohesive of a tutorial system. People have just assumed several steps in what needs to happen, which causes problems. I'm going to put up a quick tutorial here that shows you some things that you need to know to be able to run ZM with little difficulty.

First, you need linux. I highly recommend debian for this install as you can run a debian netinst and really parse down your install. I don't like having too much more than I need on an install, so there is less to go wrong.

Download debian netinst from here. Burn it to a Disc, and boot from that disk. (I am, of course, assuming that you're building a computer purely for zoneminder.)

When you install, install only the core system and web server. To do this you'll need to unselect the desktop environment, you won't need it anyway, and select the web server. You can do this step later if you forget.

After that's done running, you'll need to do some fun stuff.

First, log in as root and run:

apt-get install sudo

(this will install sudo on your system.)
Then you'll need to run:


edit your sudoers file to add in your primary user name.

(usernamer) ALL = (ALL) ALL

CRTL-X will get you out of this, save it without the .old or .tmp extension

This will allow you as the primary user to run commands through SUDO. This is preferred over running everything as root. A Little harder to totally mess things up, and a little more secure.

Great, now that your primary user is a SUDOER, log out of root (CRTL-D) and log back in as your primary user.

Ok, you're going to edit your sources.list like this:

sudo vim /etc/apt/sources.list
if you're not familiar with vim, you need to hit 'i' in order to edit the text.

change every "etch" reference to "lenny" and add "contrib non-free" to the end of every line that you edit.

hit ESC, then the colon key (:) then type "wq" at the prompt and hit enter. This will close you out of vim, and get you going.

now type:

sudo apt-get update

This will take a little bit, so hit ALT-F2 to go to a different terminal "window," and log in there.

In this window, you'll want to download the .deb file for zoneminder. Unfortunately zoneminder is not supported in lenny, so you'll have to get the sid version. This worked just fine when I did it and turned out a fairly stable system.

Here's how to download from the command prompt.

First, on another computer (easiest) go to the zoneminder package mirror page which can be found here.

Select a mirror that you want to use and type:


That's just an example, you can use any of the mirrors from the main debian page.

Back to terminal 1 while that's downloading (ALT-F1)

If it's done downloading the repository indicies, good, otherwise just wait a moment. Then type:

sudo apt-get upgrade

wait a while

sudo apt-get dist-upgrade

It's annoying and time consuming, but really worth your while. While that's running, go have a cup of tea, or something. Come back and reboot your computer. It'll be stable and ready to go!

Next, you'll need to install a lot of stuff, so hold on to your shorts and get ready to apt-get your way into bliss!

Run the following commands:

sudo apt-get install mysql-client mysql-server php5

sudo apt-get install php5-mysql libapache2-mod-php5 libapache2-mod-auth-mysql

sudo apt-get install ffmpeg

Running those commands will get you on your way. Most of what you need would be picked up by dependencies in the zoneminder package, but that's no big deal for now. Just let it run.

Now, while that's running, check on your second terminal. ALT-F2!

If your zoneminder package has successfully downloaded, just go have another cup of tea. Otherwise try re-typing the url or try a different mirror.

When it's downloaded, exit out of that terminal, you'll not need it anymore.

When apt-get has finished it's jovial run through the trenches, you'll need to run:

sudo dpkg -i zoneminder_1.23.3-3_i386.deb

It will complain about being broken, but just tell it to stop complaining in your favorite vernacular and run:

sudo apt-get install -f

It'll install a whole pile more of packages, and you'll get to watch apt-get do its magic one more time.

Now, make sure apache knows what it's suppose to be doing by typing the commands:

sudo ln -s /etc/zm/apache.conf /etc/apache2/conf.d/zoneminder.conf

this will let your web server know where to find the information about zoneminder.

Relax, you're almost done! (Doesn't it feel great?)


sudo apt-get install module-assisstant

That'll install the Kernel module assistant, which is a really snazzy piece of work!

Next run:

sudo m-a prepare
sudo m-a update

It'll download and install some stuff to get you rolling. Rolling downhill that is!

sudo m-a a-i gspca
sudo modprobe gspca

That will install the drivers (most likely) for your webcam. If your webcam is not supported by these drivers... uhm... get a different webcam. (sorry!)

Reboot your computer. You can restart all the services manually, but rebooting is easier.

Ok, the moment of truth. Run:

sudo zmu -d /dev/video0 -q -v |less

What this will do is let you know what the statistics are for your webcam. This is probably one of the most important steps of getting all things running. You'll need some of these numbers, or you'll have a hard time getting that camera to show up. Piping this through "less" will allow you to scroll up or down while you're reading the info.

Now, log into zoneminder with your other computer. Type in the ip address of the zm machine and type /zm.


This will bring up (hopefully) the zm console for you. Click "add monitor"

Using the information you gathered from zmu -d, tell zoneminder what your camera is expecting to send out to the world. If you don't tell zoneminder what the camera is expecting, it will not work.

Make sure you set the camera to monitor and make sure it's activated.

I'm sorry not to have gone into more detail after you have zm up, but I think that the final stages are probably the most documented of all the steps. If you need any help with this, post a comment and I'll try to help you out if I can!


Anonymous said...

Or you could just find a copy of BlueCherry Linux ( find out about it by googling "bluecherry" they sell cameras and such and tell wether hardware is zoneminder tested etc which is a plus ) which is them etc bfrom bacsed on Xubuntu and has zoneminder and all its dependencies preinstalled. I know its free if you buy something but it probably can be found easily regardless.

Anonymous said...

One small typo:

sudo apt-get install module-asisstant

should be:

sudo apt-get install module-assistant

quiliro said...

Thank you for your great manual. I have a problem when I get to compiling the module gspca with the command:

sudo m-a a-i gspca

This is the compilation log (sorry it is in spanish):

/usr/bin/make -C /usr/src/modules/gspca clean
make[1]: se ingresa al directorio `/usr/src/modules/gspca'
rm -r -f *.o decoder/.gspcadecoder.o.cmd decoder/*.o \
.gspca.o.cmd *.o *.ko *.mod.* .[a-z]* core *.i \
*.symvers *.err
make[1]: se sale del directorio `/usr/src/modules/gspca'
/usr/bin/make -f debian/rules kdist_clean kdist_config binary-modules
make[1]: se ingresa al directorio `/usr/src/modules/gspca'
/usr/bin/make -C /usr/src/modules/gspca clean
make[2]: se ingresa al directorio `/usr/src/modules/gspca'
rm -r -f *.o decoder/.gspcadecoder.o.cmd decoder/*.o \
.gspca.o.cmd *.o *.ko *.mod.* .[a-z]* core *.i \
*.symvers *.err
make[2]: se sale del directorio `/usr/src/modules/gspca'
for templ in ; do \
cp $templ `echo $templ | sed -e 's/_KVERS_/2.6.28-14-generic/g'` ; \
for templ in `ls debian/*` ; do \
test -e ${}.backup || cp ${} ${}.backup 2>/dev/null || true; \
sed -e 's/##KVERS##/2.6.28-14-generic/g ;s/#KVERS#/2.6.28-14-generic/g ; s/_KVERS_/2.6.28-14-generic/g ; s/##KDREV##/2.6.28-14.47trisquel1/g ; s/#KDREV#/2.6.28-14.47trisquel1/g ; s/_KDREV_/2.6.28-14.47trisquel1/g ' < $templ > ${}; \
dh_clean -k
# Build the module
/usr/bin/make -C /usr/src/modules/gspca KERNEL_VERSION=2.6.28-14-generic KERNELDIR=/usr/src/linux
make[2]: se ingresa al directorio `/usr/src/modules/gspca'
/usr/bin/make -C /usr/src/linux SUBDIRS=/usr/src/modules/gspca CC=gcc modules
make[3]: se ingresa al directorio `/usr/src/linux-headers-2.6.28-14-generic'
CC [M] /usr/src/modules/gspca/gspca_core.o
/usr/src/modules/gspca/gspca_core.c:54:27: error: asm/semaphore.h: No existe el fichero ó directorio
/usr/src/modules/gspca/gspca_core.c: En la función ‘spca5xx_ioctl’:
/usr/src/modules/gspca/gspca_core.c:2463: error: declaración implícita de la función ‘video_usercopy’
/usr/src/modules/gspca/gspca_core.c: En el nivel principal:
/usr/src/modules/gspca/gspca_core.c:2609: error: se especificó el campo desconocido ‘owner’ en el inicializador
/usr/src/modules/gspca/gspca_core.c:2609: aviso: inicialización desde un tipo de puntero incompatible
/usr/src/modules/gspca/gspca_core.c:2611: error: se especificó el campo desconocido ‘type’ en el inicializador
/usr/src/modules/gspca/gspca_core.c: En la función ‘spca50x_create_sysfs’:
/usr/src/modules/gspca/gspca_core.c:2769: error: declaración implícita de la función ‘video_device_create_file’
/usr/src/modules/gspca/gspca_core.c:2780: error: declaración implícita de la función ‘video_device_remove_file’
/usr/src/modules/gspca/gspca_core.c: En la función ‘spca5xx_probe’:
/usr/src/modules/gspca/gspca_core.c:4301: error: tipos incompatibles en la asignación
make[4]: *** [/usr/src/modules/gspca/gspca_core.o] Error 1
make[3]: *** [_module_/usr/src/modules/gspca] Error 2
make[3]: se sale del directorio `/usr/src/linux-headers-2.6.28-14-generic'
make[2]: *** [default] Error 2
make[2]: se sale del directorio `/usr/src/modules/gspca'
make[1]: *** [binary-modules] Error 2
make[1]: se sale del directorio `/usr/src/modules/gspca'
make: *** [kdist_build] Error 2

I am using IP cameras. ¿Should I omit the errors and continue with the process as the program sugests?

Thank you for your feedback.

Jonathan said...

Looks like your linux headers are not installed. Sorry it took me so long to respond. You might also find that, if you are using 2.6.29+ that gspca is already installed, but without the obscure drivers for the VX-3000 and other MS webcams.

Anonymous said...

Finally getting closer!!!!! I am BRAND new to the whole linux thing (4days on Ubuntu9.1) as I have had it with the M$ Army and their dirty tatics, Screw U Bill.
Anyways I have been going crazy trying to learn how this all works and my 1st task has been to install and run zoneminder so far I have been able to get it installed and run it in "FireFox" simply from cut&paste of about 10 different google responses. I currently have a USB webcam hooked up, and I am able to use it with "Motion"(the program) and see all the data for it with the sudo zmu -d /dev/video0 -q -v |less. The problem is the camera wont show up in zoneminder and I think its because I have the source wrong /dev/video0 (or 1)

Below is my webcam info:
Video Capabilities
Name: Dynex 1.3MP Webcam
Type: 1
Can capture
Video Channels: 1
Audio Channels: 0
Maximum Width: 1280
Maximum Height: 1024
Minimum Width: 48
Minimum Height: 32
Window Attributes
X Offset: 0
Y Offset: 0
Width: 640
Height: 480
Picture Attributes
Palette: 8 - YUYV
Colour Depth: 16
Brightness: 32768
Hue: 32768
Colour :32768
Contrast: 32768
Whiteness: 4287

Thank you for any insight on this

I also have a BNC camera hooked into a Dazzle DVC100 RCA to USB converter but I am not even going to try to make it work until I get a capture card for the BNC because it was a pain in the ass in windows witch I unfortunatly spent 15yrs learning.

Last thing it doesn't really apply to me because zoneminder mostly works for me but the command sudo m-a a-i gspca returned :gspca, what is gspca?:

Thankyou for the best Zoneminder info so far!! also thanks for the patience with a noob lookin for a new start :)

Jonathan said...

Ok, here is what I do to find my cameras when ZM gets dumb:

I install camstream either via apt-get or synaptic. Then I run caminfo, which will search for cameras. and give me a little bit of info about where my camera is, etc. If you run camstream, click file > open viewer and there will be a drop-down menu with some camera information on there.

Then you can take this camera information, and substitute it in for the zmu command. Alternately, you might try adding a new camera through the ZM interface. I have found this to be glitchy at best (sometimes it will find the camera, sometimes not), which is why I put the zmu command in my tutorial.

Also, the command "sudo m-a a-i gspca" is obsolete. I haven't changed it because I just have not gotten around to re-writing this tutorial.

As it stands, I plan on building a new ZM box this spring, probably around the end of May, so look forward to an updated copy of this tutorial.

harry said...

So did you catch the little buggers?