Zoneminder with Megapixel Cameras
by Matt on Nov.16, 2009, under Linux
I’m continuing to post technical articles from the old blog. This is a zoneminder how-to I wrote for work a while back. The most interesting thing about this article is that I got zoneminder to work with cameras that previously did not work due to their proprietary nature. The particular cameras, the Megapixel MPix13D and MPix1339WIR only work with Internet Explorer which makes getting them to work with zoneminder difficult if not impossible. I was able to get them working though. See the details below.
About the Megapixel cameras. These cameras appear to be Linux based and use a number of opensource libraries to do there thing. The fact that they were designed to only work with Windows was frustrating. With a little research I discovered that the US company responsible for distributing these cameras was AVS Uriel Systems Inc. I contacted them and asked if they would provided the source code for their cameras so that I could get them working with zoneminder. After exchanging a couple of emails I was given access to their SDK. This proved to be all I needed to get everything working. While the SDK did not include the complete source code for the cameras it did include detailed protocol information. I was prepared to write my own protocol handler that would get the cameras working with ffmpeg (and thus zoneminder). The biggest problem was that the mpeg and mjpeg streams the cameras were sending used an unexpected handshake for initializing the stream.
As I was exploring the SDK I discovered something else. Contained in the zip files were alternate firmware for several of the MP series cameras. A little more reading proved that these firmwares were targeted at open systems and used standard protocols. I applied the firmware to one of my cameras and was able to get VLC and ffmpeg to view a stream from the camera directly. This was all I needed to get zoneminder working so I set about setting things up. While I have the SDK and the firmware required to get these cameras working I am not sure that I have the right to distribute either. I would recommend you try to contact AVS Systems and ask for the SDK. They were very responsive to my request so I imagine they will be to anyone else.
On to the zoneminder build.
Zoneminder is the surveillance system software we us to record and log events from the security cameras. It’s opensource and runs on just about any Linux distro. Here’s how to build it on CentOS. Much of the information was gathered from the zoneminder forums.
In order to ease the install I used some packages from rpmforge repo.
You can install the rpmforge repo by doing:
rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
Then install the following packages:
yum install mysql mysql-bench mysql-server mysql-devel mysqlclient10 php \
php-gd php-mysql httpd gcc pcre-devel gd mod_ssl glib2-devel \
gcc-c++ ntp gnutls-devel libjpeg-devel ffmpeg perl-Archive-Tar \
perl-MIME-Lite perl-MIME-tools perl-Date-Manip perl-Time-HiRes \
perl-LWP-UserAgent-Determined perl-PHP-Serialization \
perl-Device-SerialPort perl-Archive-Zip perl-Module-Load \
ffmpeg-devel ffmpeg
now get zoneminder from http://www.zoneminder.com/downloads.html
wget http://www2.zoneminder.com/downloads/ZoneMinder-1.24.2.tar.gz
mkdir src
cd src
tar zxvf ../ZoneMinder-1.24.2.tar.gz
cd ZoneMinder-1.24.2
Configure zoneminder with the following options:
./configure --with-webdir=/opt/arin/httpd/orwell.arin.net/html/zm \
--with-cgidir=/opt/arin/httpd/orwell.arin.net/cgi-bin \
ZM_DB_USER=zmuser ZM_DB_PASS=YOUR_ZM_DB_USER_PW
Build it:
make
Install it:
sudo make install
Enable mysqld:
chkconfig mysqld on
service mysqld start
Log into mysql:
mysql -uroot -p (password is blank)
Set root pw:
set password for root@localhost=password('YOUR_DB_ROOT_PW');
Create zoneminder DB:
create database zm;
Create zoneminder user:
grant create,insert,select,delete,update on zm.* to zmuser@localhost \
identified by 'ChangeME';
Alter and Run zoneminder DB creation script:
vi db/zm_create.sql
Edit Line 314 so that Path varchar(64) is:
`Path` varchar(255) NOT NULL default ””,
These DB schema changes are required because the paths used for our camera source is very long. This is the only modification I had to make to zoneminder to get the MegaPixel cameras working.
Load the SQL file into your zoneminder DB:
mysql -uroot -p zm < db/zm_create.sql
Edit the zm init script:
vi scripts/zm
chkconfig: 345 99 01
Copy init script to /etc/init.d
sudo cp scripts/zm /etc/init.d
Enable zoneminder in init:
chkconfig zm on
Enable httpd:
chkconfig httpd on
Configure httpd:
vi /etc/httpd/conf.d/zoneminder
DocumentRoot "/opt/arin/httpd/zoneminder.yourserver.com/html/"
ServerName orwell.arin.net
ScriptAlias /cgi-bin/ /opt/arin/httpd/zoneminder.yourserver.com/cgi-bin/
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
start httpd:
service httpd start
start zoneminder:
service zm start
Configure Zoneminder via web console.
Goto http://zoneminder.yourserver.com/zm
Select options (far right on top)
Under the System tab:
enable OPT_USE_AUTH
Click the save button
Close the options window and refresh the main page.
You will get a login dialog
username = admin password = admin
open the options dialog again. There will now be a Users tab (the last
one). Add users here.
Select Config tab:
Disable STRICT_VIDEO_CONFIG
Click the save button
Select Paths tab
Change PATH_SOCKS to /var/run/zoneminder
Change PATH_LOGS to /var/log/zoneminder
Change PATH_SWAP to /var/tmp
Click the save button
Create the above mentioned directories:
mkdir /var/log/zoneminder
chown apache:apache /var/log/zoneminder
mkdir /var/run/zoneminder
chown apache:apache /var/run/zoneminder
restart zoneminder:
service zm restart
Select the images tab and edit the following:
Set PATH_FFMPEG to /usr/bin/ffmpeg
Hit the save button.
Close Window
Click the Add New Monitor button on the front page:
Define a new monitor:
Name: Name of location of camera (no spaces)
Source Type: ffmpeg
Function Monitor
Enbled (checked)
Linked Monitors (leave this alone)
Maximum fps: 15
Alarm Maximum fps: 25
Reference Image Blend %g: 7
Click the source tab:
Source Path: http://10.1.1.10/cgi-bin/stream/nph-stream.cgi?id=root&pw=root&streamtype=mpeg&refresh=15&truenph=0
Source Colors: 24-bit color
Capture Width: 640
Capture Height: 480
Preserve Aspect ratio: unchecked
Orientation: Normal
That's it. You should be able to view the live stream from the camera via zoneminder. You can setup zones, and do anything else you can normally do from zoneminder. One thing to note is that while you can log into the cameras with Firefox or whatever some settings pages require Internet Explorer. In particular, the picture adjustment sliders require IE to work properly. If you have any questions drop a comment and I will try to help.