A quick intro to Zoneminder

Following on from the last post, I’m going to talk about how Zoneminder works and why it struggles a bit with high resolution modern security cameras.

Zoneminder does motion detection based on zones. It’s got a very sophisticated system for avoiding false positives by letting you specify the exact areas of interest and the degree of motion needed to trigger events. It’s quite complicated and tweaking the options takes a lot of trial and error, but that’s what comes of such a powerful system. It’s never quite possible to eliminate false positives but you can get very close.

Examples of zones. Not the view from my window 🙂

The problem is that Zoneminder was designed in the era of fairly low resolution security cameras – standard resolution analogue cameras were the norm and digital security cameras were in the 640×480 range or thereabouts, running at modest frame rates.

Today’s digital security cameras are often full 1080P HD or better. The Hikvision camera I mentioned last time has a resolution of up to 2688×1520 and can run at 20 frames per second. That’s a lot of data.

Zoneminder works by breaking the incoming video stream into individual frames. Frames are then compared and differences between them indicate motion. If the motion meets the criteria set in the zones, Zoneminder records the event.

Events are recorded by storing the individual frames as jpeg image files. When you play back the event, you’re actually seeing each individual frame being streamed in succession to your browser. Similarly when you look at the live view, you’re not viewing the raw stream from the camera but the succession of jpeg images that it’s currently processing.

That’s a lot of images. A five second clip of 20fps motion will generate 100 jpeg images. While Zoneminder can be set to record continuously that would generate a huge number of files. Imagine 24×7 recording at 20fps – that’s 1.7 million jpegs per day!

Analysing the images also takes a fair amount of CPU grunt at those high resolutions. At 2688×1520, that’s over four million pixels to analyse, twenty times every second.

It’s amazing that it’s even possible, but it can be done. I’m running Zoneminder on an i5 CPU and it takes just over 20% of the CPU to keep up with the camera. That’s not too bad for a single camera, but it wouldn’t scale well to running several.

The quick fix is to run your cameras at lower resolutions and/or frame rates. To see the difference, I tried capturing both the main stream and the substream from my camera. The main stream is 2688×1520 and I set it to 20fps at the highest quality. The substream has a maximum resolution of just 640×380 and I set it to 10fps at medium quality. I’m using a single zone that covers about half the image area and is using the “fast, high sensitivity” preset.

Zoneminder runs two processes for each camera – the zmc capture process and, if you’re doing motion detection, the zma analysis process. This lets it scale well to multiple processors. Here are those processes on my computer:

The main stream’s capture process is averaging around 36% of the CPU on one core and the analysis process is using 28%

By comparison the substream is only using 3.3% to capture and 1.3% to analyse.

For most purposes a middling resolution at a middling framerate is perfectly sufficient in a security camera. Setting the main stream to, say, 1920×1080 at 10fps would probably be the right balance between performance and clarity in the image.

It’s just that if you’ve got a really high resolution camera, wouldn’t it be nice to make full use of it?

One strategy is to capture both streams and only do the zone analysis on the low res stream. Using Zoneminder’s linked monitor feature you can capture events from the high res stream when they’re detected by the low res stream without having to analyse the high res one. Unfortunately Zoneminder still has to capture the high res stream, which in itself uses a fair amount of CPU, and you end up with two monitors in the user interface.

If you also want continuous recording it would be more efficient to capture the stream direct to disk as a series of video files rather than as jpegs of each frame. There is an experimental branch of the Zoneminder code that does just that, although it still uses the standard capture process for displaying the live stream so even if you’re not analysing for motion you’ll still get high CPU use from the capture process.

The ideal solution for me would be a system that records the main stream straight to disk and uses the substream for motion detection. The user interface would link the two, allowing you to jump easily to high quality clips of the motion without having to capture the main stream.

There is active development of Zoneminder and it’s possible that it will update to include the direct recording in the main release and gain other features to better deal with high res cameras.

In the meantime, I’ll try the experimental version of Zoneminder and if that doesn’t work I might see if I can use another tool to handle the recording and just use Zoneminder for event detection in the substream.

in Home Automation

Related Posts

Add a Comment

Your email address will not be published. All comments will be reviewed.