Difference between revisions of "Dummies Guide"

From ZoneMinder Wiki
Jump to navigationJump to search
Line 1: Line 1:
This is a short guide for using ZM. It's concise, and tells you what you need to know.
How to install Zoneminder , ( v1.33.16.) with Mysql 8 on Ubuntu 19.10


If you wish to view the full ZM Documentation, I recommend viewing it through the PDF view, as the sphinx website is not efficient and requires javascript. PDF View: https://readthedocs.org/projects/zoneminder/downloads/pdf/stable/
Since the official Zoneminder eoan has Dependency wait on lgw01-amd64-051 , We will have to install Zoneminder disco  on Ubuntu 19.10.


==Install==
First of all we will have to install mysql-server-8 on Ubuntu 19.10 and enable mysql_native_password


Installation can be done using the synaptic package manager .


Use the install guides provided by Bbunge on the wiki:
Then open the Ubuntu terminal
[https://wiki.zoneminder.com/Contents#Installation_Procedure Zoneminder Wiki: Contents]
These are the best supported install guides.


[[Ubuntu]] or [[Debian]] / Devuan is recommended.
sudo su


Some install guides omit required dependencies using VLC as a source type (libvlc). Search forum and wiki if this is necessary.
gedit /etc/mysql/my.cnf


Here's a guide for using an external HDD: [https://wiki.zoneminder.com/Using_a_dedicated_Hard_Drive Using a dedicated Hard Drive]
Then enter the following line below [mysqld] on the opened my.cnf file and save the file


For ZM < 1.29 Make sure you add <code>innodb_file_per_table=1</code> and ensure that the ZM database is InnoDB format, otherwise you may run into the issues described in [[MySQL]]. This should not be necessary in 1.30.4 and later.
[mysqld]


If you want to use the bleeding edge / unstable release (not recommended for new users) you can grab the [https://launchpad.net/~iconnor ubuntu ppa], and the debian repo [http://zmrepo.zoneminder.com/debian/master is here]. Add debian repo in apt like e.g.
default_authentication_plugin= mysql_native_password
<pre>
deb http://zmrepo.zoneminder.com/debian/master jessie/
</pre>


==Test out a Camera==
Then on the Ubuntu terminal


systemctl restart mysql


Once you get ZM installed, you will want to test out a camera.
Then enter the following commands on the terminal to set root password for mysql server
You can do a webcam, or you can do an IP camera.
See the [[Hardware_Compatibility_List]]


I recommend you start with an old [[Axis]] IP Camera. They are well documented and easy to setup.
mysql CREATE USER 'admin'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your password';
Buy an old one for $10-20. Follow the instructions on either the Zoneminder Hardware compatiblity list,
on ispyconnect's url list, or in the user manual for the camera. Any respectable camera will document it's RTSP and MJPEG and JPG paths for you to access. ONVIF is also an option to find the paths for RTSP cameras. This is covered in more detail in [[Finding Camera Stream Paths]].


mysql GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;


Follow the instructions in the Hardware Compatiblity List for parameters
mysql FLUSH PRIVILEGES ;
for setting up a camera the first time. If you have an error, look at the logs.


IP address, path, port, and Resolution must be correct. Most other fields can be left at defaults. If you are using MJPEG you use the http option (of remote). If you are using H264 / RTSP you use the RTSP or RTP option. If this doesn't make sense, read the rest of this document.
systemctl restart mysql


If you can view the MJPEG or JPG url in your browser, you will be in good shape. Take that path, and put it into Zoneminder. If the camera requires authorization, consult the user manual, or you can try adding the username and password before the ip like so username:password@ipaddress
Then install Zoneminder
e.g. root:mypass@192.168.1.5
This is an alternative to 192.168.1.5?username=root&pwd=mypass which most guides tell you to do. Both will work, however the latter can vary in what keywords it uses while the former requires no keywords.


If pass is blank, you type in root:@192.168.1.5
The Zoneminder disco deb file is downloaded from https://launchpad.net/~iconnor/+archive/ubuntu/zoneminder-master/+build/18492553/+files/zoneminder_1.33.16~20191229135312-disco_amd64.deb


==Obtaining more Cameras==
GDebi Package Installer can be used to install the Zoneminder disco deb file


Before installing Zoneminder disco deb file to overcome dependency issues we will have to  download libmysqlclient20and install first  using the GDebi Package Installer.


In ZoneMinder, when you add a camera, you have a few options:
Then install Zoneminder disco deb file that we have downloaded .
* '''LOCAL''' Camera connected directly to computer (webcam, or analog camera thorugh bttv card)(typically /dev/video0)


* '''REMOTE''' Grab MJPEG stream or RTSP (h264) stream from IP camera on the network
Creating user and zmpass


* '''FILE''' Grab a jpg file somewhere locally and display that (you provide jpeg images that change from somewhere). Can be used in unusual ways (i.e. a slide show, <insert use here>).
Open the Ubuntu terminal and enter  following 5 commands


* '''FFMPEG''' and '''LIBVLC''' use the respective libraries to pull a stream similar to REMOTE does for RTSP only. The forum recommends to use FFMPEG, if you are using RTSP. This is an alternative for REMOTE.
mysql


Local I do not recommend. BTTV pci cards for analog cameras are limited in resolution (704x480px). HD Analog cameras are compatible through remote if the video encoder outputs an RTSP/MJPEG stream (unknown if works with local). A video encoder is basically a DVR that serves video on the network. More details below.


After that you have FILE and REMOTE. I have not used FILE for anything but testing. I will cover REMOTE.
CREATE USER 'zmuser'@localhost IDENTIFIED WITH mysql_native_password BY 'zmpass';


GRANT ALL PRIVILEGES ON zm.* TO 'zmuser'@'localhost' WITH GRANT OPTION;


'''REMOTE''' has the option of either RTSP (h264) or MJPEG streams.
FLUSH PRIVILEGES ;


mysqladmin -uroot -p reload


===MJPEG===
It was observed that there are missing *.ini files in /etc/php/7.3/mods-available/ which will make problems in getting zoneminder Console.
These include [[Arecont Vision]], Axis, Bosch, [[Foscam]], [[Grandstream]], Instar, Messoa, Zavio and others.  
The prices scale with features. Old indoor Axis cameras at 480p-720p resolution (no IR) can be found
online easily for $10-80. It is easy to find MJPG cameras of 480p resolution. It is generally more expensive to find 720p MJPEG cameras, but they exist. More pixels means higher cost. Also, more pixels means you need a better CPU.


Also see, [[Hardware_Compatibility_List#Single_Board_Computers SBC cameras]].
Therefore the necessary files have to be copied from /usr/share/php7.3-mysql/mysql


===RTSP===
sudo cp /usr/share/php7.3-mysql/mysql/*.ini /etc/php/7.3/mods-available/
These cameras use h264 compression. However ZM decodes all incoming video to jpeg files,
so it's not as efficient. This requires libvlc, or ffmpeg to convert
the video to jpg files. It's easier to find a 1080p RTSP camera, for $70 vs. an 1080p MJPEG camera, generally.


Note: Users with 1.32+ can use H264 passthrough, which writes the h264 direct to mp4, and saves some CPU usage.
sudo service apache2 reload


===Conclusion===


Using Remote you must choose either MJPEG, RTSP, or a mix.  
chmod 740 /etc/zm/zm.conf
If you want a high quantity of cameras, it's more efficient
chown root:www-data /etc/zm/zm.conf
to use all MJPEG cameras. If you have a small number, or If you want to purchase high-end
adduser www-data video
server hardware, then it doesn't matter. With powerful enough server hardware, you will be able
a2enmod cgi
to run 20-30 HD cameras of either type without difficulty, if not more.
a2enconf zoneminder
a2enmod rewrite
chown -R www-data:www-data /usr/share/zoneminder/
systemctl enable zoneminder
service zoneminder start


Let me state again - '''high-end''' server hardware will perform better than desktop, or low end server hardware. I have seen this firsthand between two servers: KFSN4-DRE and the KGPE-D16.  The latter runs ZM with 25+ cameras, not breaking a sweat. The former reaches a limit at about 10. Note that I run MJPEG only. Load averages 1.5 - 2.5 for 32 cores. A bigger limitation is HDD size.
sudo service apache2 reload


I needed the most affordable HD MJPEG cameras, so I searched and settled on the Foscam 9805's and 9804's. However they are no longer being sold by Foscam. New Foscam models do not have MJPEG and I don't recommend them. You can buy 9805 online used, but the quality may be lower and I also don't recommend it. It depends what hardware and software version they are. The E models with new software tend to be 3FPS while the W models with old firmware and hardware I have seen run 1FPS. I currently recommend buying Axis (new or used), although they do not have IR. This is not a problem, as outdoors IR on cameras attracts spider webs, and external IR is recommended, anyways. Another brand I have found success with is DLink. The DCS-932 cameras are good, although they are SD resolution and the IR is 10m (short range IR). Otherwise, any respectable name brand camera will work. Look through the hardware compatibility list. Read the user manual before you purchase the camera, and look for the following: Outdoors/indoors, IR/no-IR, Resolution (and double check the JPEG stream has the higher resolution, if using MJPEG). IR can be supplimented with external appliances. External IR, may have a light sensor which turns on IR when dark enough, simply provide power.
Open zoneminder web console (http://localhost/zm/)
 
=== A note on Analog Cameras ===
 
If you are upgrading an existing camera installation, you will likely have coaxial cables for the old cameras. These can be used with Zoneminder in either LOCAL, or REMOTE. LOCAL, via a PCI or PCI-Express card, REMOTE through a video encoder that takes the analog stream and converts to either MJPG or RTSP. I recommend the latter.
 
There is no reason to rip out, or ignore old coaxial cables. They are perfectly viable for Zoneminder. They may be a step behind the IP cameras, however they can be used.
 
Also consider investing in HD Analog cameras. However you are on your own here. I have not researched into this. It should be possible to get an HD Analog Video Encoder that will take an HD analog camera and offer for Zoneminder to read as an RTSP/MJPEG stream. If you are doing this, beware that you research and try to get one that follows a standard for CCTV HD encoding. Otherwise, you might be at the mercy of one brand. Also consider the existing coaxial cable. Long cable runs may not be able to handle HD Analog, as easily as old video. When in doubt, just use traditional NTSC or PAL video.
 
==Watching the Cameras==
 
Cameras can be watched from ZM web server. Montage view is good. See notes section for a hint about > 6 camera setups.
 
Another way is to make an html file on a remote machine with the following code embedded in an img tag. Adjust monitor ID as needed.
[https://wiki.zoneminder.com/How_to_stream_from_another_ZoneMinder_installation  How to stream from another ZoneMinder installation]. Also an easy way to embed video in a website (img tag). It is possible to use FFServer as a server for a website. FFServer (part of FFMPEG project) will take the video feed, and offer it up to clients. I have used FFServer with [[Zmodopipe]]. See [[Dedicated SBC Camera Monitor]] for notes on refreshing the stream periodically.
 
Streaming in ZM, does not slow it down, in my experience.
 
If you embed the URL in an img tag, include http prefix or it wont work.
<pre>
img width="500px" height="500px" src="http://zmserveripaddress/zm/cgi-bin/nph-zms?mode=jpeg&monitor=#&scale=100&maxfps=5&user=username&pass=password"
</pre>
 
Call it locally:
<pre>
firefox file:///home/username/file.html
</pre>
 
=== Quick Example ===
 
[[Example Camera View HTML]]
 
[https://forums.zoneminder.com/viewtopic.php?f=37&t=26982 Embedding Streaming Video in External Website] from Forums
 
==Recording in Zoneminder==
 
You can record everything (good, but no way to find events). You can modect everything (light HDD use, but misses stuff). You can mocord everything (best, but uses HDD). And finally, You can mix it up. I would recommend in small setups, to throw a >1TB HDD in there for videos and set everything to mocord. For larger setups, you will want to customize each camera based on its priority.
 
In ZM 1.32 and newer, you can use multiple HDs, and assign cameras to where they should be saved.
 
==Motion Detection==
 
'''What's all this motion detection stuff, anyhow?'''
 
The strength of zoneminder lies in its motion detection (thus the 'zone' in zoneminder, being the motion detection zones). See: [https://wiki.zoneminder.com/Understanding_ZoneMinder%27s_Zoning_system_for_Dummies  Understanding Zoneminder's Zoning system for Dummies]
 
Start with the most sensitive settings, and make them less sensitive until no false alarms are recorded. Night IR detects more false events than daylight. Monitoring for all alarms can easily be done by <code>$ tail -f /var/log/syslog</code> in Devuan based distros.
 
Or you can record everything, if modect isn't working. Mocord will combine both modect and record, having everything recorded, but making a graph where motion occurs (in '''show timeline'''). Mocord is the best, but uses more HDD. Beware of running into issues with [[PurgeWhenFull]] not able to keep up.
 
 
'''Why motion detection?'''
 
Using modect or mocord is '''recommended''' here. Because you are able to click from the main zm index - events - '''show timeline''', and from there quickly review your modect events. Because you save HDD space. And [[SMS Notifications]] and [[ZMTrigger]] can be setup off of modect alarms (the latter requiring either modect, mocord, or nodect).
 
 
'''Any downsides?'''
 
Zones must be tuned to be sensitive enough to see all events, but not so sensitive as to detect false alarms. This requires work, and is not guaranteed to work 100% even after tweaking.
 
 
'''Tips'''
 
*Zones should be as small as possible, and you should use as few zones per monitor, to lower CPU usage.
*If you see events with 1 or 2 alarm frames occuring, you can make a background filter to delete these.
*Aggressive Modect usage can run into issues with [[PurgeWhenFull]], beware.
*Transitions from [https://forums.zoneminder.com/viewtopic.php?f=36&t=27141 daylight to IR] cause false alarms. The solution is to "Set a max alarmed area so it doesn't alarm if the whole area is changing".
*I prefer the usage of external hardware motion sensors via [[ZMTrigger]] over modect. Less CPU, and more reliable / flexible.
 
 
'''Conclusion'''
 
After all is said and done, motion detection works but has limitations. Motion detection tends to report false alarms from weather, wildlife, changing from IR to Day sensor, and others. For users that need accurate motion detection, you will either need to A) tune the zones so that no false alarms occur (see [https://wiki.zoneminder.com/Understanding_ZoneMinder%27s_Zoning_system_for_Dummies  Understanding Zoneminder's Zoning system for Dummies]) or B) use the cameras built in motion detection or C) use external motion sensors with [[ZMTrigger]] or some combination of the above.
 
==Hardware Advice==
 
When setting up the cameras, here is some advice.
* Use fuses on the PSU output to the cameras, if using passive POE adaptors.
* Use barrel plug splitters, and use one 12V PSU. (i.e. a barrel plug that is a 1 to 5 splitter). Cameras in my experience use around 200-400mA of current at 12V (400mA is when IR LEDs are on).
* If you purchase axis cameras, be aware that the cameras are 5V and the barrel plug is 4.0mm x 1.7mm. It's easiest to use POE on these.
* Installing areas where the temperature is high may cause early camera failure (especially for cheaper cameras). Even something as simple as a corner of an enclosed room where the sun shines all day may be enough heat.
 
==Troubleshooting==
 
 
* Watch logs.
 
* Use forum search.
 
* Use web search.
 
* Enable component logs and navigate to /var/log/zm/.
 
* <code># tail -F /var/log/syslog</code>
 
* Beware of underlying hardware faults such as bad RAM.
 
==Notes==
 
 
 
* Some cams will have two video streams (e.g. Hikvision, Amcrest). 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. Read the data sheet / user manual for cameras you intend to purchase.
 
* I found it helpful to include monitor ID in camera names, as you run into monitor ID in logs often.
 
* Proprietary cameras are known to report to outside IPs. Don't give them internet access. Only the server should be wan-accessible. Make a separate network.
 
* 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 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). 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: [https://forums.zoneminder.com/viewtopic.php?f=32&t=23417&p=89249  ZM Forums: Problems when two people are watching live] [http://kb.mozillazine.org/Network.http.max-persistent-connections-per-server Network.http.max-persistent-connections-per-server]. This max persistent connections per server must be > 6 in order to see > 6 camera streams.
 
* Adding "< /dev/null" to the ffmpeg path used by ZM seems to fix some issues. See [https://forums.zoneminder.com/viewtopic.php?f=32&t=23861&p=91771  ZM Forums: Truncated Video Export]
 
* If you are going to use a BT878 based card, you can add a heatsink onto the top of all *878 chips. This has been mentioned in the [https://forums.zoneminder.com/search.php?keywords=heatsink+bt878 forums in various spots], Use a ruler, and measure the dimensions in mm, then purchase one on digikey. A heatsink attached to the plastic of the IC, instead of the actual IC die is not ideal, but it will help. EDIT: I'm not sure if this is necessary, in hindsight. Also consider a video encoder instead of a BT878 card (e.g. search auction sites for 1 or 2 or 4 channel video encoder).
 
* Edit /etc/default/rcS (applies to devuan/trisquel) and make sure auto FSCK is enabled. Failure to set this, will require manual intervention when the server is repairing the filesystem, requiring you to press a key.
 
* Make sure the BIOS is set to reboot after power fails.
 
* Set colourspace to 32-bit for a possible performance boost.
 
* Don't set an FPS limit on REMOTE or FFMPEG, or VLC cameras in Zoneminder. The FPS should only to be set at the IP camera itself. FPS limiting is for LOCAL cameras, only.
 
* With larger camera setups (one 10, one >20 cameras) I needed to change the watchdog timer (/usr/bin/zmwatch.pl) from the default of 10 seconds to 30 or 60 seconds in order to avoid periodic drop outs of individual cameras. The cameras would drop, and not return, unless i restarted zoneminder or disabled and enabled that camera. This setting is managed in options - system. If you see dropouts after that, review /usr/bin/zmwatch.pl and insert additional logging. You can also add a hack to the API so that if cameras drop out they are restarted. See documentation of ZM API. For my setups, they typically drop out once a day on specific cameras. Other cameras will never drop out.
 
* Do NOT point cameras at bright light, such as facing a window, a garage door, or anything that generates glare. It will blur the image.
 
* Best buy a set of adaptors such as these: to use with your normal 5.5 2.1mm barrel plug. Search multi type 23 or 28 dc power adapter.
 
[[File:Universal-28pcs-5-5x2-1mm-Multi-type-Male-Jack-for-DC-Plugs-for-AC-Power-Adapter.jpg 640x640.jpg|200px|Coaxial barrel plug adaptors||Universal 28pcx Multi type Male Jack for DC Plugs]]
 
* I made a script to watch cameras that drop out, and disable/reenable them for my 1.29 setup. See [https://forums.zoneminder.com/viewtopic.php?f=9&t=26909 here]. This also doubles as a notification in case the cameras somehow are powered off. You'll get emails telling you cameras are down.
 
==See Also==
 
*[[Cron]] example
 
* [[Dedicated SBC Camera Monitor]] Guides for using a Beaglebone Black or Desktop as a client to watch the ZM Server.
 
*[[Example Camera View HTML]] A quick html file you can deploy on clients to watch the server.
 
*[[Exporting Videos Hack]] (not recommended)
 
*[[Finding Camera Stream Paths]]
 
*[[ffmpeg]] Example usage, and notes.
 
*[[MJPEG_vs_H264]] For ZM < 1.31, use MJPEG for large deployments
 
* [[MySQL]] can require some optimizing, and there are potential gotchas. Though newer releases of Zoneminder may have resolved some of the issues.
 
*[[OpenVPN]] tips
 
* [[PurgeWhenFull]] requires configuration on larger systems, or systems where events are created at a pace faster than PurgeWhenFull can keep up. Failure to do so, will result in all events being blank, and you will have to fix it.
 
* [[SMS Notifications]] or email.
 
* [[Zmodopipe]] Is a tool that can tie an analog DVR system to Zoneminder, although it is far from perfect. I have documented it there, and recommend purchasing a (some #) channel video encoder instead.
 
* [[ZMTrigger]] is a tool that can be used to take outside information and overlay it onto the camera display. For example, you might take the temperature, or wind speed, and overlay it on a camera. It can also be used as external motion detection. Experience with electronics and microcontrollers such as AVRs, Pics, and the Arduino IDE are applicable here.
 
===Other Users===
 
*[[How to share an USB camera from a remote ZM server to another ZM Server]]
 
*[[General Notes]]
 
*[https://forums.zoneminder.com/viewtopic.php?f=32&t=23815&hilit=i+run+this+script+every+night Backup DB script (Recommended)]

Revision as of 03:36, 4 January 2020

How to install Zoneminder , ( v1.33.16.) with Mysql 8 on Ubuntu 19.10

Since the official Zoneminder eoan has Dependency wait on lgw01-amd64-051 , We will have to install Zoneminder disco on Ubuntu 19.10.

First of all we will have to install mysql-server-8 on Ubuntu 19.10 and enable mysql_native_password

Installation can be done using the synaptic package manager .

Then open the Ubuntu terminal

sudo su

gedit /etc/mysql/my.cnf

Then enter the following line below [mysqld] on the opened my.cnf file and save the file

[mysqld]

default_authentication_plugin= mysql_native_password

Then on the Ubuntu terminal

systemctl restart mysql

Then enter the following commands on the terminal to set root password for mysql server

mysql CREATE USER 'admin'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your password';

mysql GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;

mysql FLUSH PRIVILEGES ;

systemctl restart mysql

Then install Zoneminder

The Zoneminder disco deb file is downloaded from https://launchpad.net/~iconnor/+archive/ubuntu/zoneminder-master/+build/18492553/+files/zoneminder_1.33.16~20191229135312-disco_amd64.deb

GDebi Package Installer can be used to install the Zoneminder disco deb file

Before installing Zoneminder disco deb file to overcome dependency issues we will have to download libmysqlclient20and install first using the GDebi Package Installer.

Then install Zoneminder disco deb file that we have downloaded .

Creating user and zmpass

Open the Ubuntu terminal and enter following 5 commands

mysql


CREATE USER 'zmuser'@localhost IDENTIFIED WITH mysql_native_password BY 'zmpass';

GRANT ALL PRIVILEGES ON zm.* TO 'zmuser'@'localhost' WITH GRANT OPTION;

FLUSH PRIVILEGES ;

mysqladmin -uroot -p reload

It was observed that there are missing *.ini files in /etc/php/7.3/mods-available/ which will make problems in getting zoneminder Console.

Therefore the necessary files have to be copied from /usr/share/php7.3-mysql/mysql

sudo cp /usr/share/php7.3-mysql/mysql/*.ini /etc/php/7.3/mods-available/

sudo service apache2 reload


chmod 740 /etc/zm/zm.conf chown root:www-data /etc/zm/zm.conf adduser www-data video a2enmod cgi a2enconf zoneminder a2enmod rewrite chown -R www-data:www-data /usr/share/zoneminder/ systemctl enable zoneminder service zoneminder start

sudo service apache2 reload

Open zoneminder web console (http://localhost/zm/)