Dummies Guide
Notes I've recorded as I've learned ZoneMinder.
Install:
Use the installation guides provided on the : Zoneminder Wiki
In my installation I used Trisquel based on Ubuntu 14LTS. There were no compatibility issues.
Test out a Camera:
Once you get ZM installed, you will want to test out a camera. You can do a webcam, or you can do an IP camera. See the Hardware Compatibility LIst
An Axis is a good test. They are well supported (though HD is expensive). Buy an old one for $10-20. Another good brand is Arecont Vision.
Follow the instructions in the Hardware Compatiblity List for parameters for setting up a camera the first time. If you have an error, look at the logs.
Resolution must be right on the cameras. A lot of other fields can be ignored.
If you can view the MJPEG or JPG url in your browser, you will be in good shape.
Obtaining more Cameras:
You have a few options here.
- LOCAL Camera connected directly to computer (webcam, or analog camera thorugh bttv card)
- REMOTE Grab mjpeg stream or rtsp (h264) stream from IP camera on the network
- FILE Grab a jpeg file somewhere on the server and display that (you provide jpeg images that change from somewhere)
- FFMPEG and LIBVLC use the respective libraries to pull a stream similar to REMOTE does for RTSP only.
Analog cameras are limited in resolution (about 700x400px). So called HD Analog cameras are not compatible with ZM. However analog cameras can use a network encoder to turn an analog stream into an IP Camera RTSP stream. After that you have FILE and REMOTE. I have not used FILE for anything but one off cameras. I will cover REMOTE.
REMOTE gives you the option of either RTSP (h264) or Mjpeg cameras. Both will work.
Mjpeg cameras:
These include Arecont Vision, Axis, Bosch, Foscam, Grandstream, Instar, Messoa, Zavio and others.
The prices scale with features. Old Axis cameras at 480p resolution (no IR) can be found
online easily for $10-50. New Foscams can be purchased at their online store
for $80-130 with 1080p resolution (IR). Above that is beyond my budget. More pixels means higher cost.
Also see, SBC cameras. ArduinoCam, etc. It should be possible to run cameras with a BBB or an arduino that output 1080p JPEG snapshots or stream. The tools are there.
RTSP cameras: These cameras use h264, compressing and streaming the feed. However ZM decodes all incoming video to jpeg files, so it's not optimized. [ Exception is feature-h264-videostorage branch]. These require libvlc, or ffmpeg to convert the video for zoneminder. Same as MJPEG, the prices go up accordingly as you get more resolution. However it's generally easier to find a 1080p RTSP camera, for $70 vs. an MJPEG camera.
Conclusion:
Based on your needs you must choose either MJPEG, RTSP, or a mix. If you want a high quantity of cameras, it's more efficient to use all MJPEG cameras. If you have a small number, or If you want to purchase high-end server hardware, then it doesn't matter. With powerful enough server hardware, you will be able to run 10-20 HD cameras of either type without difficulty. In fact, a lot of my CPU usage comes from compressing the video (optional, see below).
In my case, I needed the most affordable HD MJPEG cameras that I could use, so I searched high and low and settled on the Foscam models. Beware that some of their newer models do not have MJPEG streaming, and some firmware have issues with the stream not working. Read carefully on the foscam forums before purchasing. Or (better) use something like an Axis. Or an SBC.
Watching the Cameras:
Watching the cameras in ZM console is easy but what about from another computer?
Once you get the cameras setup you will want to monitor them somehow. Zoneminder will be able to provide a stream for you. The following code can be embedded in an html page and networked computers can view. Adjust monitor ID as needed. How to stream from another ZoneMinder installation
This seems to work with little performance strain on ZM, from my setup watching 10 1080p cameras.
(though resolution is less than 1080p in browser).
Recording in Zoneminder:
I don't recommend you follow this guide for exporting videos for most setups But it's here if you want it
If you have enough high resolution cameras you will see your disk space fill up fast. Zm records in 10 minute segments and captures every jpeg. There is no compression of similar frames. Every jpeg is captured.
How do you avoid filling up the HDD with lots of cameras?
You use a filter which will take recordings from some specified range and create a video for all matches. Then you make a filter that will delete the videos which have already had videos created.
Or alternatively, you use motion detection (see below), recording only when motion occurs (modect, not mocord).
What do you mean filter?
On the zm home console, there is a filter button. Click that, specify the range of videos you want to create videos for, click the checkbox for 'create video for al matches', submit, select it to run in the background, done.
How is it going to make the video?
You can specify parameters in FFMPEG_OUTPUT_OPTIONS in the options of zm. Make sure you are using ffmpeg, not avconv. You also need to specify the path for ffmpeg. I used the ffmpeg binary.
I settled on the following path for ffmpeg
output options:
- -c:v libx264 -preset ultrafast /videosfolder/on/some/path/`date -d "-1 days" +"%Y%m%d-%H%M%S-%N"`.avi < /dev/null
VP9 compresses best, but is slower to encode. If you have hardware optimized for VP8 or VP9, maybe it will be better.
Here are a couple others I tried (no idea what I am doing), before settling on libx264:
- -c:v libx264 -preset fast -crf 38 -vf hqdn3d=8:6:12
- -r 1 -f image2 -i %07d.jpg -vcodec libvpx-vp9 -crf 18
- -r 25 -q:v 1 /mnt/where/my/videos/go/`date -d "-1 days" +"%Y%m%d-%H%M%S-%N"`.webm
- -r 1 -f image2 -i %07d.jpg -vcodec libx264 -crf 18 -preset slower
More are on Zoneminder forums.
So with
-c:v libx264 -preset ultrafast /videosfolder/on/some/path/`date -d "-1 days" +"%Y%m%d-%H%M%S-%N"`.avi < /dev/null
This works, but puts all videos from all monitors into one folder. The next step was to make script Script for Deleting Old Exported Video Folders that would take files daily from this folder and put them into subdirectories labeled by the date. Then I made script Script for Deleting Old Exported Video Folders pt.2 that would measure the filesystem capacity of this folder (it is a dedicated drive) and if the capacity is over a set amount, delete the oldest two days.
This worked well, except that finding videos among the dozens in one day was slow.
The next step was based off of this post:
Event Video Saved to Custom Location by Default
So I edited zmvideo.pl and was able to get most of the cameras to export to their own folders (see above forum posts). Though now I had to change ffmpeg output options to:
-c:v libx264 -preset ultrafast
as now the perl script is managing where the output folders go.
I had to debug when setting up the perl script in order to make it work. Permissions, and watching the /var/log/zm/{zmvideo,zmfilter}.log helped.
What if I want to only use ZM to record the video, and not export video
This is an option most people should use but it's advised to use motion detection. You can set a dedicated HDD for a moderate number of cameras and get sufficient history on it. This will require configuring zones (not difficult, but tiny learning curve), which is covered well in the article Understanding ZoneMinder's Zoning system for Dummies
Exporting video allows you to compress events, which means you can get more of a backlog.
How do I view more than 10 minute segments of video?
If you have the videos in ZM, go to the ZM main webpage, click the cameras events you want to see (the number) and then click 'view timeline'. The rest is self explanatory.
What about motion detection
The strength of zoneminder lies in its motion detection (thus the 'zone' in zoneminder, being the motion detection zones). This is best explained by again, Understanding Zoneminder's Zoning system for Dummies
I personally have indoor cameras set to the fastest settings, and then change percent to pixels, lowering the value to below 1%. I also make smaller zones on the screen as having one large zone for the whole camera (if the camera covers a large distance) will not be likely to catch much, unless you make pixels' value minute.
For outdoor cameras, where the background is moving due to wind, you would use less sensitive settings, obviously.
Is motion detection required?
Using modect is recommended. Because you are able to click from the main zm index - events - show timeline, and from there quickly review your modect events. And because you save HDD space.
Troubleshooting:
- Watch logs.
- Use forum search.
- Use web search.
- If you click, 'component logs' in the options - logs section of zm, you will get log files in the /var/log/zm/ folder.
Notes
- In future ZM It may not be necessary to do the perl hack. The hack is not difficult.
- Some cams will have two video streams (e.g. Hikvision). The resolutions/video type may or may not be the same. For example, there may be a low resolution mjpeg stream, and a high resolution RTSP stream.
- I found it helpful to name the cameras after the monitor ID as you run into monitor ID in logs, often.
- Proprietary cameras are known to report to outside IPs. Don't give them internet access. SBCs might be more secure.
- Many cameras have default telnet passwords, in addition to the default web access passwords. Change these or keep cameras away from the wan. Cameras are common botnet targets.
- With server motherboard hardware, you will be able to have more cameras (servers are more powerful, and better servers will have better performance).
- I use an SSD for the base OS, and HDDs for the Videos / ZMEvents respectively. I use ext4 filesystem for the HDDs. I had tried using ext2 filesystem for better performance, but the fsck time is prohibatively slow for ext2 (>24 hours for >2TB), therefore I do not recommend using it. Ext4 seems to work well. Older ext2, or ext3 fs can be upgraded to ext4.
- When viewing the cameras in Firefox, once you get more than 6 cameras from ZM on the browser Firefox will not display the seventh. This is due to a limit of Firefox and can be adjusted in about:config. See: ZM Forums: Problems when two people are watching live
- Adding "< /dev/null" to the ffmpeg path used by ZM seems to fix some issues. See ZM Forums: Truncated Video Export
- If you are going to use a BT878 based card, you probably should add a heatsink onto the top of all *878 chips. This has been mentioned in the forums in various spots, and I noticed one of my chips out of the 3 on the board not working correctly after the first test. A heatsink with similar dimensions can be purchased from electronic stores such as digikey, mouser, adafruit, or sparkfun. Use a caliper or a ruler, and measure the dimensions in mm, then search for a similar heatsink. You will also need some kind of adhesive. I used an epoxy based thermal adhesive. Thermal adhesive is different from thermal paste, in that paste is not meant to hold anything together.
- Zmodopipe Is a tool that can tie an analog DVR system to Zoneminder, although it is far from perfect.
Mysql Notes
I had an issue with the ibdata1 file in /var/lib/mysql/ growing too large. It includes some database information and in my 10GB root partition, was taking up 8GB.
The solutions I found were:
- backup zm database, delete zm db, delete ibdata file, then restore database (not hard but be careful) How to Shrink/Purge Ibdata1 file
OR
- Move the ibdata file to another partition
Optionally, changing the database type to have an innodb file per each table as mentioned in the "how to shrink purge ibdata1 file in mysql" link will supposedly keep less data used in the ibdata1 file in the future, allowing the former to be deleted when not needed. On the other hand the ibdata file by default, will not shrink, ever. This may or may not be an issue in MariaDB.
Looking for the least invasive procedure, I went with moving /var/lib/mysql, and adding the optional my.cnf parameter. This required the following tricks (may only apply to Ubuntu 14.04).
There are a number of guides on moving Mysql, yet many of them omit adding the alias to apparmors settings. This is required. Failing to do so will result in "Job failed to start" when mysql is run with #service mysql start.
A guide that covers all the steps required to move mysql on Ubuntu 14LTS without omitting anything is here: Ask Ubuntu: Moving Mysql datadir Note that within my mysql installation there was no socket file in /var/lib or in my.cnf.