Difference between revisions of "Main Documentation"

From ZoneMinder Wiki
Jump to navigationJump to search
(No difference)

Revision as of 11:03, 6 September 2007

Please Note: The documentation for ZoneMinder is currently in the process of being migrated to this Wiki. The documents present in the distribution and available from the Documentation page on the main site should be used until such time as this notice is removed.

Introduction

Welcome to ZoneMinder, the all-in-one Linux GPL'd security camera solution.

A while back my garage was burgled and all my power tools were stolen! I realised shortly after that if I'd just had a camera overlooking the door then at least I'd have know exactly when and who did the dirty deed. And so ZoneMinder was born. It's still relatively new but hopefully it has developed to be something that can be genuinely useful and prevent similar incidents or even perhaps bring some perpetrators to justice.

ZoneMinder is designed around a series of independent components that only function when necessary limiting any wasted resource and maximising the efficiency of your machine. A fairly ancient Pentium II PC should be able to track one camera per device at up to 25 frames per second with this dropping by half approximately for each additional camera on the same device. Additional cameras on other devices do not interact so can maintain this frame rate. Even monitoring several cameras still will not overload the CPU as frame processing is designed to synchronise with capture and not stall it.

As well as being fast ZoneMinder is designed to be friendly and even more than that, actually useful. As well as the fast video interface core it also comes with a user friendly and comprehensive PHP based web interface allowing you to control and monitor your cameras from home or even at work or on the road. It supports variable web capabilities based on available bandwidth. The web interface also allows you to view events that your cameras have captured and archive them or review them time and again, or delete the ones you no longer wish to keep. The web pages directly interact with the core daemons ensuring full co-operation at all times. ZoneMinder can even be installed as a system service ensuring it is right there if your computer has to reboot for any reason.

The core of ZoneMinder is the capture and analysis of images and there is a highly configurable set of parameters that allow you to ensure that you can eliminate false positives whilst ensuring that anything you don't want to miss will be captured and saved. ZoneMinder allows you to define a set of 'zones' for each camera of varying sensitivity and functionality. This allows you to eliminate regions that you don't wish to track or define areas that will alarm if various thresholds are exceeded in conjunction with other zones.

ZoneMinder is fresh off the keyboard and so comes with no warranty whatsoever, please try it, send your feedback and if you get anything useful out of it let me know.

ZoneMinder is free but if you do get ZoneMinder up and running and find it useful then please feel free to visit http://www.zoneminder.com/donate.html where any donations will be appreciated and will help to fund future improvements to ZoneMinder. This would be especially relevant if you use ZoneMinder as part of your business, or to protect your property.

Requirements

ZoneMinder needs a couple of things to work. Ordinarily the ‘configure’ script will check for the presence of required (and optional) components but it is useful to be prepared beforehand.

Firstly, it uses MySQL so you'll need that. In order to compile you need to make sure you have a development installation and not just a runtime; this is because it needs to use the MySQL header files. If you are running an RPM based distribution then it’s probably worth installing all the pure mysql rpm files to be sure you have the right ones.

Next it does things with JPEGs so you'll need at least libjpeg.a which I think come as standard nowadays with most distributions. Users have reported varying degrees of success with other jpeg libraries such as jpeg-mmx but these are not officially supported. If you plan to use network cameras then the Perl Compatible Regular Expression library (libpcre.a) can prove useful but is not always essential. ZoneMinder also uses the netpbm utilities in a very limited way to generate thumbnails under certain circumstances though this can be modified.

ZoneMinder can generate MPEG videos if necessary, for this you'll need either ffmpeg (recommended) or the Berkeley MPEG encoder (mpeg_encode). If you don't have either, don't worry, as the options will be hidden and you'll not really miss too much. Some of the authentication uses openssl MD5 functions, if you get a grumble about these during configuration all it will mean is that authentication won’t be used for streaming. The web interface uses PHP and so you need that in your apache or other web server as well, make sure MySQL support is available either statically or as a module. There are also various perl modules that you may need that vary depending on which options you choose on installation, for more details see later in this document.

Finally, there is quite a bit of image streaming in the package. So if you don't have FireFox or another browser that supports image streaming natively I recommend you get the excellent Cambozola java applet from http://www.charliemouse.com/code/cambozola/ which will let you view the image stream in Internet Explorer and others. Otherwise you're limited to just refreshing still images or mpeg based streams, if you have compatible plugins.

Hardware-wise, ZoneMinder has been used with various video and USB cameras with the V4L interface. It will also work with most Network or IP cameras. I don't have a lot of cameras myself so I've not had change to test it with a huge range personally however there is a list of devices that are definitely known to work on the web site. Please enter you camera on the Wiki list on zoneminder.com if your camera works and is not listed. You do need to have Video4Linux installed. In terms of computer hardware, there are no hard and fast requirements. You may get a system that works with one or two cameras going on an old P200 but you will be able to support more cameras, at a higher frame rate, with faster machines with more RAM. More guidance is available on the web forums.

Components

ZoneMinder is not a single monolithic application but is formed from several components. These components primarily include executable compiled binaries which do the main video processing work, perl scripts which usually perform helper and/or external interface tasks and php web scripts which are used for the web interface.

A brief description of each of the principle components follows.

zmc
This is the ZoneMinder Capture daemon. This binary's job is to sit on a video device and suck frames off it as fast as possible, this should run at more or less constant speed.
zma
This is the ZoneMinder Analysis daemon. This is the component that goes through the captured frames and checks them for motion which might generate an alarm or event. It generally keeps up with the Capture daemon but if very busy may skip some frames to prevent it falling behind.
zmf
This is the ZoneMinder Frame daemon. This is an optional daemon that can run in concert with the Analysis daemon and whose function it is to actually write captured frames to disk. This frees up the Analysis daemon to do more analysis (!) and so keep up with the Capture daemon better. If it isn’t running or dies then the Analysis daemon just writes them itself.
zms
This is the ZoneMinder Streaming server. The web interface connects with this to get real-time or historical streamed images. It runs only when a live monitor stream or event stream is actually being viewed and dies when the event finishes or the associate web page is closed. If you find you have several zms processes running when nothing is being viewed then it is likely you need a patch for apache (see the Troubleshooting section). A non-parsed header version of zms, called nph-zms, is also installed and may be used instead depending on your web server configuration.
zmu
This is the ZoneMinder Utility. It's basically a handy command line interface to several useful functions. It’s not really meant to be used by anyone except the web page (there's only limited 'help' in it so far) but can be if necessary, especially for debugging video problems.
zmfix
This is a small binary that exists only to ensure that the video device files can be read by the main capture daemons. It is often the case that these device files are set to be accessible by root only on boot. This binary runs setuid and ensures that they have appropriate permissions. This is not a daemon and runs only on system start and then exits.

As well as this there are the web PHP files in the web directory and some perl scripts in the scripts directory. These scripts all have some configuration at the top of the files which should be viewed and amended if necessary and are as follows.

zmpkg.pl
This is the ZoneMinder Package Control script. This is used by the web interface and service scripts to control the execution of the system as a whole.
zmdc.pl
This is the ZoneMinder Daemon Control script. This is used by the web interface and the zmpkg.pl script to control and maintain the execution of the capture and analysis daemons, amongst others. You should not need to run this script yourself.
zmfilter.pl
This script controls the execution of saved filters and will be started and stopped by the web interface based on whether there are filters that have been defined to be autonomous. This script is also responsible for the automatic uploading of events to a 3rd party server.
zmaudit.pl
This script is used to check the consistency of the event file system and database. It can delete orphaned events, i.e. ones that appear in one location and not the other as well as checking that all the various event related tables are in line. It can be run interactively or in batch mode either from the command line or a cron job or similar. In the zmconfig.pl there is an option to specify fast event deletes where the web interface only deletes the event entry from the database itself. If this is set then it is this script that tidies up the rest.
zmwatch.pl
This is a simple script purely designed to keep an eye on the capture daemons and restart them if they lockup. It has been known for sync problems in the video drivers to cause this so this script makes sure that nothing important gets missed.
zmupdate.pl
Currently this script is responsible for checking whether a new version of ZoneMinder is available and other miscellaneous actions related to upgrades and migrations. It is also intended to be a ‘one stop shop’ for any upgrades and will execute everything necessary to update your installation to a new version.
zmvideo.pl
This script is used from the web interface to generate video files in various formats in a common way. You can also use it from the command line in certain circumstances but this is not usually necessary.
zmx10.pl
This is an optional script that can be used to initiate and monitor X10 Home Automation style events and interface with an alarm system either by the generation of X10 signals on ZoneMinder events or by initiating ZoneMinder monitoring and capture on receipt of X10 signals from elsewhere, for instance the triggering of an X10 PIR. For example I have several cameras that don’t do motion detection until I arm my alarm system whereupon they switch to active mode when an X10 signal is generated by the alarm system and received by ZoneMinder.
zmtrigger.pl
This is an optional script that is a more generic solution to external triggering of alarms. It can handle external connections via either internet socket, unix socket or file/device interfaces. You can either use it ‘as is’ if you can interface with the existing format, or override connections and channels to customise it to your needs. The format of triggers used by zmtrigger.pl is as follows "<id>|<action>|<score>|<cause>|<text>|<showtext>" where
  • 'id' is the id number or name of the ZM monitor
  • 'action' is 'on', 'off', 'cancel' or ‘show’ where 'on' forces an alarm condition on, 'off' forces an alarm condition off and 'cancel' negates the previous 'on' or 'off'. The ‘show’ action merely updates some auxiliary text which can optionally be displayed in the images captured by the monitor. Ordinarily you would use 'on' and 'cancel', 'off' would tend to be used to suppress motion based events. Additionally 'on' and 'off' can take an additional time offset, e.g. on+20 which automatically 'cancel's the previous action after that number of seconds.
  • 'score' is the score given to the alarm, usually to indicate it's importance. For 'on' triggers it should be non-zero, otherwise it should be zero.
  • 'cause' is a 32 char max string indicating the reason for, or source of the alarm e.g. 'Relay 1 open'. This is saved in the ‘Cause’ field of the event. Ignored for 'off' or 'cancel' messages
  • 'text' is a 256 char max additional info field, which is saved in the ‘Description’ field of an event. Ignored for 'off' or 'cancel' messages.
  • 'showtext' is up to 32 characters of text that can be displayed in the timestamp that is added to images. The ‘show’ action is designed to update this text without affecting alarms but the text is updated, if present, for any of the actions. This is designed to allow external input to appear on the images captured, for instance temperature or personnel identity etc.
Note that multiple messages can be sent at once and should be LF or CRLF delimited. This script is not necessarily intended to be a solution in itself, but is intended to be used as ‘glue’ to help ZoneMinder interface with other systems. It will almost certainly require some customisation before you can make any use of it. If all you want to do is generate alarms from external sources then using the ZoneMinder::SharedMem perl module is likely to be easier.
zmcontrol-*.pl
These are a set of example scripts which can be used to control Pan/Tilt/Zoom class cameras. Each script converts a set of standard parameters used for camera control into the actual protocol commands sent to the camera. If you are using a camera control protocol that is not in the shipped list then you will have to create a similar script though it can be created entirely separately from ZoneMinder and does not need to named as these scripts are. Although the scripts are used to action commands originated from the web interface they can also be used directly or from other programs or scripts, for instance to implement periodic scanning to different presets.
zmtrack.pl
This script is used to manage the experimental motion tracking feature. It is responsible for detecting that an alarm is taking place and moving the camera to point to the alarmed location, and then subsequently returning it to a defined standby location. As well as moving the camera it also controls when motion detection is suspended and restored so that the action of the camera tracking does not trigger endless further alarms which are not justified.
zm
This is the (optional) ZoneMinder init script, see below for details.

Finally, there are also a number of ZoneMinder perl modules included. These are used by the scripts above, but can also be used by your own or 3rd party scripts. Full documentation for most modules is available in ‘pod’ form via ‘perldoc’ but the general purpose of each module is as follows.

ZoneMinder.pm
This is a general ZoneMinder container module. It includes the Base.pm, Config.pm Debug.pm, Database.pm, and SharedMem.pm modules described below. It also exports all of their symbols by default. If you use the other modules directly you have request which symbol tags to import.
ZoneMinder/Base.pm
This is the base ZoneMinder perl module. It contains only simple data such as version information. It is included by all other ZoneMinder perl modules
ZoneMinder/Config.pm
This module imports the ZoneMinder configuration from the database.
ZoneMinder/Debug. pm
This module contains the defined Debug and Error functions etc, that are used by scripts to produce diagnostic information in a standard format.
ZoneMinder/Database.pm
This module contains database access definitions and functions. Currently not a lot is in this module but it is included as a placeholder for future development.
ZoneMinder/SharedMem.pm
This module contains standard shared memory access functions. These can be used to access the current state of monitors etc as well as issuing commands to the monitors to switch things on and off. This module effectively provides a ZoneMinder API.
ZoneMinder/ConfigAdmin.pm
This module is a specialised module that contains the definition, and other information, about the various configuration options. It is not intended for use by 3rd parties.
ZoneMinder/Trigger/*.pm
These modules contain definitions of trigger channels and connections used by the zmtrigger.pl script. Although they can be used ‘as is’, they are really intended as examples that can be customised or specialised for different interfaces. Contributed modules for new channels or connections will be welcomed and included in future versions of ZoneMinder.

Building

To build ZoneMinder the first thing you need to do is run the included configure script to define some initial configuration. If you are happy with the default settings for the database host (‘localhost’), name (‘zm’), user (‘zmuser’) and password (‘zmpass’) then you can just type

./configure --with-webdir=<your web directory> --with-cgidir=<your cgi directory>

where --with-webdir is the directory to which you want to install the PHP files, and --with-cgidir is the directory to which you want to install CGI files. These directories could be /var/www/html/zm and /var/www/cgi-bin for example.

If you want to override any of the default database values then you can append them to the configure command, for example to use a database password of ‘zmnewpass’ do

./configure --with-webdir=<your web directory> --with-cgidir=<your cgi directory> ZM_DB_PASS=zmnewpass

and so on. The values you can use are ZM_DB_HOST, ZM_DB_NAME, ZM_DB_USER and ZM_DB_PASS. Other than the database name, which is substituted into the database creation script, these values can easily be changed after this step.

If the script cannot find your MySQL installation, for instance if it is installed in an unusual location, then --with-mysql identifies the root directory where you have installed it, usually /usr.

If you want to use real MPEG based streaming you will need to have built and installed the ffmpeg tools. You can then also use --with-ffmpeg=<path to ffmpeg root> to help configure find it if it’s not installed in a default location. Note, you have to make sure you have installed the ffmpeg headers and libraries (make installlib) as well as the binaries (make install), or a development package with them in.

If you have built ffmpeg with any additional options which require extra libraries in the link stage then you can use --with-extralibs to pass these libraries to the configure script, to prevent unresolved dependencies. Otherwise ignore this option.

If you are on a 64 bit system you may find that the --with-libarch option helps you correctly define your library paths.

There are also two further parameters you can add if your web user and group are not both 'apache'. These are --with-webuser and --with-webgroup.

This is also when you have the opportunity to pass any additional flags to the compiler to modify how the application is built. To do this append CFLAGS=”<options>” and CXXFLAGS=”<options>” to pass in compiler flags for ‘c’ and ‘c++’ compilation respectively. For instance the default compiler flags are usually –O2 and –g to create binaries with moderate optimisation and debugging symbols. If you wanted to optimise further, including processor specific tweaks but still keep debugging symbols then could use CFLAGS="-g -O3 -march=pentium4" and CXXFLAGS="-g -O3 -march=pentium4" for instance. Consult the gcc/g++ documentation for help on these and other options. Also be aware that even if you optimise your ZoneMinder build, any libraries that get linked in will only perform as well as the options used when they were built allows. Thus to get full benefit you would usually need to rebuild libjpeg.a and/or other libraries with similar options.

Type

./configure –help

for details on these, and other, options.

Now you can just type make to do the build. The first time you run this you may get a warning about a Makefile being rebuilt in the scripts directory, and make will terminate. This is normal and you can just rerun make to complete the build.

Installation

Installation from Source

For a new installation the next thing you will need to do is create your database and database users. So type the commands as follows,

mysql mysql < db/zm_create.sql

mysql mysql

grant select,insert,update,delete on <database name>.* to '<database user>'@localhost identified by '<database password>';

quit

mysqladmin reload

You may need to supply a username and password to the mysql commands in the first place to give yourself sufficient privileges to perform the required commands. If you want to host your database on a different machine than that which ZoneMinder is running on then you will need to perform this step on the remote machine and reference the ZoneMinder machine instead of localhost. If you are running remote databases you probably already know all this, if you are not then don’t worry about it!

At this stage typing

make install

will install everything to the desired locations, you may need to su to root first though to give yourself adequate permissions. The installation routine will copy the binaries and scripts to your chosen install location, usually /usr/local/bin and then move zms (and nph-zms) to your cgi-bin area. It will then copy the web files to your chosen directory and ensure they have the right permissions, and install the ZoneMinder perl modules in the standard perl locations. It will also install a copy of the zm.conf file (generated by configure) to your system configuration area (e.g. /usr/local/etc). Finally it tries to link zm.php to index.php but will not overwrite an existing file if it already exists.

The 'zm' script does not get installed automatically as it is not necessary for the operation of the ZoneMinder setup per se and is not necessarily likely to work correctly for distributions other than those from the RedHat or Fedora families. However if you want to ensure that ZoneMinder is started on reboot etc copy it to your init.d directory, usually something like /etc/rc.d/init.d or /etc/inid.d and then add it by doing

chkconfig --add zm

or similar command for your distribution. ZoneMinder will then start up when your machine reboots and can be controlled (by the root user) by doing 'service zm start' or 'service zm stop' etc. You may need to use the ‘—levels’ parameter to chkconfig to ensure that ZoneMinder is started when you need it to.

If you do this you should find that you have files named S99zm in some of the /etc/rcX.d directories and K99zm in some of the others. The S99zm files are used for starting up ZoneMinder on system boot and the K99zm ones are used to close it on system shutdown. The 99 part is a priority, which may run from 0 to 99 and indicates where in the startup and shutdown sequences that ZoneMinder should start or stop. So S99zm means that ZoneMinder should be one of the last things to startup, which is good as it needs things like the database to be running first.

By the same token, the K00zm scripts indicate that ZoneMinder should be one of the first things to shut down. This prevents any nasty messages on your console about the database having gone away first and also will give ZoneMinder chance to shutdown in a controlled manner without introducing any corruption into the database or filesystem.

As mentioned above, this script is for Redhat, and related, distributions only. I would be grateful for any similar scripts for other distributions so if you know of one, or create one, then please send it to me.

If you are running a distribution which doesn’t support the zm script, or if you just prefer more direct control, you can now start ZoneMinder by typing

zmpkg.pl start

which, after a few seconds, should return without error. You can subsequently stop and restart everything by changing the ‘start’ parameter to ‘stop’ or ‘restart’.

Now fire up your web browser, point it at your zm.php and off you go.

Note, if you ever need to uninstall ZoneMinder you can do this by simply typing

make uninstall

though as with installation you may need to change user to have sufficient privileges. This will remove all installed files, however you will need to manually remove any databases you have created.

Installation from RPM

Installing from the RPM is distribution specific so make sure you download the correct RPM for the distribution that you are using.

All documents including this README are installed to the systems default document folder.

Fedora Core: /usr/share/doc/zm-{version number}

Mandrake:

The packaged version of Zone Minder installs all binarys to /usr/lib/zm including the web pages. So don’t worry when you do not see any files installed to the root directory for your web server. The web pages for Apache are aliased by zm.conf in the apache/conf.d directory which vary depending on your distribution:

Fedora Core: /etc/httpd/conf.d/zm.conf

Mandrake:

The Configuration file for setting up the database is located at /etc/zm.conf and will need to be edited to add the user and password that you want Zone Minder to use. After you have installed the Zone Minder package this will be the first thing you want to do. So use your favourite editor and add in the user name and password you want Zone Minder to use. You can also change the database name if you would like.

vi /etc/zm.conf

Start the mysqld service so you can build the database

service mysqld start

Then run zminit to create the database

/usr/lib/zm/bin/zminit

The user and password that zminit asks for are for the database only. For the user enter root and leave the password blank (unless of course you changed the password). You should see some information showing that it has created the database and no errors.

Set the run levels for the services that Zone Minder requires. I like to set the run levels to 3 and 5 with the following command:

chkconfig –levels 35 mysqld on

chkconfig –levels 35 httpd on

Now start the web server and Zone Minder:

service httpd start

service zm start

You should now be able to access the Zone Minder console through the web browser http://localhost/zm

Log files will be located in /var/log/zm

Events are located at /var/lib/zm

Upgrading

If you are upgrading from a previous version of ZoneMinder you should follow the Building instructions above. Before proceeding, ensure that any previous version of ZoneMinder has been stopped, then type

make install

to install the binaries, scripts, modules, web and configuration files.

The next step in an upgrade is to run the zmupgrade.pl script to make any changes to the database or file system required by the new version. Ordinarily you can run this from your ZoneMinder build directory by doing

zmupdate.pl –version=<from version> [--user=<database user> --pass=<database password>]

where ‘from version’ relates to the version of ZM you are upgrading from, 1.21.1 for example, and not the version you are upgrading to. All updates from that version onwards will be applied; however zmupdate.pl will only work with upgrades from 1.19.0 onwards. The ‘user’ and ‘pass’ options allow you to specify a database user and password with sufficient privilege to ‘alter’ the structure of the database. This is not necessarily the database user you use for ZoneMinder.

The update script will offer you the chance to make a database backup before making any changes. You can use this to restore your database if the upgrade fails or if you simply wish to roll back in the future. Be aware that if you have a lot of entries in your database and/or limited disk space doing a backup may not be feasible or even work. Also the backup only applies to the database and will not save any images or other event detail saved on disk. If successful the backup will be saved in the current directory and will be named <database name>-<from version>.dump. Any previous backups of the same name will be overwritten without warning. The backup file is in the form of a simple sql script and can be used to restore the database simply by typing

mysql < zm-1.21.4.dump

for example.

After having done any backup, the database upgrade will be applied. Check that this is successful before continuing.

Once the upgrade process is complete, you can then restart ZoneMinder using the zmpkg.pl script or using the service control commands for your distribution. You should check /var/log/messages and the other ZoneMinder logs for the first few minutes to ensure that everything comes back up successfully.

Tutorial

Defining Monitors

Defining Zones

Viewing Monitors

Controlling Monitors

Filtering Events

Viewing Events

Options and Users

Camera Control

Control Capabilities

Control Scripts

Mobile Devices

Logging

Troubleshooting

Change History

Release 1.22.3

Release 1.22.2

Release 1.22.1

Release 1.22.0

Release 1.21.4

Release 1.21.3

Release 1.21.2

Release 1.21.1

Release 1.21.0

Release 1.20.1

Release 1.20.0

Release 1.19.5

Release 1.19.4

Release 1.19.3

Release 1.19.2

Release 1.19.1

Release 1.19.0

Release 1.18.1

Release 1.18.0

Release 1.17.2

Release 1.17.1

Release 1.17.0

Release 0.9.16

Release 0.9.15

Release 0.9.14

Release 0.9.13

Release 0.9.12

Release 0.9.11

Release 0.9.10

Release 0.9.9

Release 0.9.8

Release 0.9.7

Release 0.0.1

To Do

Bugs

Non-Bugs

License