# Posts tagged 207MW

## Zoneminder MJPEG and Shared Memory Settings

If you’ve read my big post on the Zoneminder configuration I have at home, you’ll notice that I favored capture of JPEG stills over using MJPEG during initial configuration.

At the time, the reason was simple; I couldn’t make MJPEG work. I’ve now succeed in doing so, and understand why it didn’t work the first time.

## Memory Settings

I remembered reading something in the Zoneminder documentation about a shared memory setting resulting in capture at higher resolutions failing. Originally, when I first encountered the problem I decided that it was simply me getting something wrong with the path to the .mjpeg streams on the cameras, since I was more familiar with capture of jpeg stills from prior scripting.

However, I stumbled across some documentation here from another tinkerer, which also pointed to the memory sharing issue.

The problem is that the buffer of frames (usually between 50 and 100 for the camera) must be contained in memory for processing. If the size of the image:

$buffer\, size\times image\, width\times image\, height\times3_{for\,24\, bits}+overhead$

Exceeds this shared memory maximum, you’ll run into errors or see the camera status go to yellow/orange instead of green. (It can get pretty confusing trying to troubleshoot based on those status colors unless you’re checking the logs… /doh)

In fact, the problem I was seeing was likely directly as a result of the large capture image size of my Axis 207mW, as they cite it directly:

Note that with Megapixel cameras like the Axis 207mw becoming cheaper and more attractive, the above memory settings are not adequate. To get Zoneminder working with a full 1280×1024 resolution camera in full colour, increase 134217728 to, for example, 268424446

/facepalm. I really wish I had come across this the first time around. Either way, you’re going to ultimately run into this problem with either higher framerate connections, color, or higher resolutions.

I followed the tips, here, but doubled them since the machine I’m running ZM has a pretty good chunk of memory available.

The process is simple. You’re going to have to edit /etc/sysctl.conf to include the following somewhere:

# Memory modifications for ZoneMinder (kernel.shmall = 32 MB, kernel.shmmax = 512 MB)
kernel.shmall = 33554432
kernel.shmmax = 536870912

Now, apply the settings with

sysctl -p

Which forces a reload of that file. Next, you can check that the memory parameters have been changed:

brian@brian-desktop:~$cat /proc/sys/kernel/shmall 33554432 brian@brian-desktop:~$ cat /proc/sys/kernel/shmmax
536870912

Which is successful. You can also check it with ipcs -l. Now, reboot ZoneMinder and you shouldn’t have any problems.

## Motion JPEG Time!

Having made these changes, I was ready to finally explore whether MJPEG works! I went ahead and decided to use the MJPEG streams from my two respective types of cameras in place of the static video links. These are:

I also discovered (by reading the manual) that there’s a handy utility on the Axis config page (under Live Video Config -> HTML Examples -> Motion JPEG) which generates the proper URL based on a handy configuration tool where you can select size, compression, and other options:

Handy config page

The idle load on the system has increased, as expected, but that’s partly from me raising the FPS limit to 10 which seems reasonable, and enabling continual recording with motion detection (mocord).

Nice, 10 FPS! (still a gaping hole though...)

I’m making a lot of tweaks as I get ready to transition everything onto a VM on a faster computer with much more disk space (on the order of 8 TB). If you’re interested in reading more about the Linux kernel shared memory settings, I found some good documentation:

• IBM/RedHat settings: here
• Configuring shared memory: here

# Why Home Security?

In recent months, home security and monitoring has become a matter of increasing concern across the country. Whether the reason is local downturn due to a spike in crime or just peace of mind, the price and difficulty of setting up an enterprise-level security system at home is lower than ever.

That said, the variety of hardware, open and closed source monitoring software, and configuration options makes it a bit daunting to jump right into. I’ve worked and experimented with a number of configurations and finally settled on one that I think works best (at least for my needs).

# Camera Hardware

## Camera 1 – Linksys WVC54GCA

Wireless-G Internet Home Monitoring Camera

I originally started out with just one Linksys WVC54GCA. It’s a 640×480, wired/wireless 802.11b/g network camera with built in web server for stills and video, and some simple motion detection and alert functionality. The reason for its choice was simple; price. It’s Linksys’ primary network camera offering, and you can find it as of this writing for $89 at newegg. In addition, there’s a newer camera with 802.11n, the WVC80N. However, it isn’t perfect. To quote the cons of my newegg review: Cons: Wireless range isn’t excellent; I have a very powerful wireless AP with a 12 dBi omnidirectional antenna and a 6 dBi directional antenna, and I had to reposition it so the camera could send video back at a decent bitrate (around 2 megabits is where it sits). An important thing to note is that the latest .24 firmware breaks WPA/WPA2 support. Mine shipped with .24 and I had to downgrade back to .22 for it to work. A bit disappointing, but hopefully future firmware will fix this glaring problem. The linksys forums have the link to a custom built .22 (oddly enough with german language selected by default, but don’t worry, all the menus are still english). Motion detection isn’t perfect, sometimes false positives will get annoying. I have sensitivity set all the way down and still get a few random videos of nothing going on. More recently, I discovered that the software (despite being open source and a *nix derivative) locks up after anywhere between 6-24 hours when the camera is connected wirelessly. This is fixable (in a haphazard sort of way) by calling an internal page that reboots the camera every 3 hours through a schedule in my Tomato router: Tomato Scheduler Screenshot Thus far, this has proven a robust fix and makes the cameras entirely usable. I’ve notified Linksys and even had a chat online with a higher level tech that passed my findings on to a firmware engineer. They’ve recently released an update which purports to fix stability issues: Version v1.1.00 build 02, Jun 15, 2008 - Support of Setup Wizard is temporarily disabled to address security issue - Fix security issues - Fix Camera stability issues I have yet to fully test it. As an aside, the cameras are actually embedded x86 inside, sporting an AMD Geode SC1100 processor, 32? MB of SDRAM (2x TSOP marked PSC A2V28S40CTP), and Ralink 802.11b/g/a(?) chipset (RT2561T) as pictured. AMD Geode SC1100 Camera visible, other SoC RaLink MiniPCI card Image quality is a little above average but nothing wonderful due to the relatively tiny plastic fixed focus lens system. Low light sensitivity is ok, but nothing stellar; you still need moonlight or ambient street lighting to get usable results at night. If you don’t mind those caveats, you’ve basically got the beginnings of a very robust (and cheap) network camera. Night versus day performance There are a number of relevant pages that are undocumented on the camera itself: Reboot: http://USER:PASS@ADDRESS/adm/reboot.cgi MJPEG stream: http://USER:PASS@ADDRESS/img/mjpeg.jpg JPEG still: http://USER:PASS@ADDRESS/img/snapshot.cgi?size=3 (3- 640×480, 2- 320×240, 1- 160×120) The options offered in the camera’s internal setup pages aren’t very robust, but offer just enough for you to do almost everything you’d want to. Image Settings ## Camera 2 – AXIS 207W and MW After acquiring another Linksys camera for myself (and another 3 for the parents), trudging my way through the reboot issue, and reasonable but not stellar image quality, I decided I was ready for something more. Axis seems to have very good support, choice, and performance, in addition to heaps more customization and options for the camera itself. The catch? Price. I decided to start off with Axis’ cheapest offering, the 207-series of network cameras. I managed to snag an Axis 207MW that had been used just once at a trade show that was being sold as used on eBay, and my dad went ahead and just purchased outright a 207W from Newegg. The distinction between the 207W and MW is that the 207MW has a 1.3 megapixel camera supporting resolutions of up to 1280×1024, whereas the 207W is just 640×480. They’re both 802.11b/g so you can move them throughout the house, and have almost identical setup and configuration pages. Of course, like the Linksys WVC54GCA, there’s optional ethernet support as well. Virtually all the other features are the same between the 207W and 207MW. Axis 207MW (the 207W looks identical) As of this writing, the 207MW is$328 at Amazon, and the 207W is $286 at Amazon. Right off the bat, you can tell this camera is much different. It’s got an actual glass lens system, focusing ring, and a compact form factor with a longer cable. In addition, the antenna is external and swivels and snaps out so you can position it however suits getting the best signal. There are a variety of status LEDs on the back that make troubleshooting limited wireless connectivity simpler. The front clear ring is actually a large lightguide for four LEDs that can be either green or amber depending on the status of the camera. These can be disabled as well. Day versus night performance on the 207MW Image quality is also much better on the Axis 207MW than the Linksys. Originally, I had a WVC54GCA mounted where the Axis is now inside the garage. The Axis is both much more stable, and also gets better wireless reception outside in an otherwise difficult to reach trouble spot. Among other things, the Axis offers many more configuration options within its internal administrative pages, as well as (if you’re interested in running it) many more options for built in motion detection. One of the more important things I’ve come across is the ability to change exposure prioritization so the otherwise very well lit driveway doesn’t come out a homogeneous white from pixels saturating as often. This kind of exposure prioritization can be done on the Axis, but not on the Linksys as shown: Exposure settings There are just a wealth of options that really make the Axis shine over the cheaper Linksys if you delve deeper. I could write pages about the differences that the extra nearly$200 makes (if you can afford it). Both cameras offer the ability to upload images and 5-10 second video clips of motion detection events to an FTP share, or attach them to an email. Detailing the differences between the two (and the ultimate shortcomings of both) is another article in and of itself.

At the end of the day, I found motion detection somewhat unreliable on both the Axis and Linksys; either I wound up with far too many motion event video clips or nearly nothing. Even worse, downloading and then watching hundreds if not thousands of false positives a grueling task. If you’re a basic user or just interested in having a camera for temporary purposes while you’re away on a trip, perhaps just the in-camera features are enough. However, if you’re looking for something more robust for a number of permanent cameras with much better motion detection, keep reading. At the end of the day, I use both types of camera just as inputs for ZoneMinder as you’ll see later on.

# ZoneMinder Setup

ZoneMinder is a GPL’d, LAMP-based web tool for managing and monitoring virtually every kind of possible video source. Its supported sources span everything from cheap USB Logitech webcams, to network security cameras with built in webservers (like the two I’ve covered), to traditional video sources through a video capture card. Their documentation is a bit overly complicated (you can get to their supported hardware list here), and at the end of the day you’re going to either need to have local linux driver support (and a path to video like you’d expect for a webcam/TV tuner), or a path for JPEG, MJPEG, or another kind of MPEG4 stream.

The aim of ZoneMinder is to do all motion detection, video archiving, and image processing in one centralized place; simplifying use and making it easier to keep track of new events as they happen. Of course, the only downside to this is that all that motion detection and video capture requires a relatively powerful computer. Official documentation claims that even an ancient Pentium II should be able to do motion detection and capture for one camera at 25 FPS.

On the old computer I’ve configured (with a Pentium 4 Northwood 2.8 GHz and 2 GB of RAM), I’ve found that adding an 8 FPS VGA network camera and doing motion detection and capture adds between 10-20% CPU load.

## Installation

Luckily ZoneMinder is relatively easy to setup if you’ve ever been near a modern linux distro with aptitude. As I noted earlier, ZoneMinder should ideally be run on a LAMP or similar web server, however, they claim that distro, web server, and SQL database support is actually quite diverse. I performed my installation on a fresh install of Ubuntu 9.10 Karmic by following instructions similar to Linux * Screw’s:

sudo apt-get install zoneminder apache2 php5-mysql libapache2-mod-php5 mysql-server ffmpeg

Once that was finished, the following:

sudo ln -s /etc/zm/apache.conf /etc/apache2/conf.d/zoneminder.conf sudo /etc/init.d/apache2 force-reload

At this point, I’d encourage you to enable user authentication in Options -> System -> ZM_OPT_USE_AUTH. Ticking this box and saving will enable another tab, Users. I generally configure one  admin for making changes and a less privileged “User” account for simply viewing the cameras and motion detection events as shown:

Users configuration

The remainder of options are largely fine in their defaults; the only major thing that you should be concerned with are the paths if you care about certain disks being used. I’ve recorded almost 800 events so far in VGA resolution and have used up an additional 1% of the meager 80 GB HDD on the system.

Now, to add some video sources. This is where you really have to either know the path to either JPEGs or a MJPEG stream on the camera.

Click “Add New Monitor” in the bottom right. Now, if you have an Axis or Panasonic network camera (arguably the two de-facto industry standards) there are some presets that are worth checking out that you can use by clicking “Presets” in the top right. Change the source type to Remote (if it isn’t already from using a preset), and name it appropriately. I also usually set the FPS to either 5 or 8; from what I’ve seen, higher really isn’t feasible.

Now click the “Source” tab. This is where if you used a preset, your life is much easier, as the remote host path is already filled in. If not, it’s still simple, you just have to know how to get the relevant data from your source. In my example, I have the following:

From the above screenshot:

Remote Host Name: user:pass@_PATH TO YOUR CAMERA_

Remote Host Port: 80 (Or something else, if you’ve changed it)

Remote Host Path: /axis-cgi/jpg/image.cgi?resolution=640×480

Note that this is for the Axis 207 series cameras, although in general all the Axis cameras follow the same syntax (nice, isn’t it?). You can’t use whatever resolution you want, however, all the major and obvious choices work. You’ll notice I’ve just used VGA instead of the full 1.3 MP 1280×1024 resolution image from the 207MW. This is because using full resolution does seem to generate too much network traffic for my 802.11g network (despite my best efforts, the garage remains a dead zone thanks to chicken wire stucco construction), and FPS takes a large hit. No doubt that if the connection were wired, higher would be feasible. However, VGA is more than enough for now.

Adding the Linksys sources are just as easy given the paths I outlined previously. I haven’t added any internal sources, personally, however I imagine that configuration is the same if not easier; it requires knowing the path and setting a few additional constraints so you don’t overload your server.

## Configuration

Now that you’ve added sources, you can configure their function.

Video source functions

You would think these options would be intuitive, however, they caused a bit of confusion for myself personally due to their shortened names. They are as follows, from the ZM documentation:

• None – The monitor is currently disabled and no streams can be viewed or events generated.
• Monitor – The monitor will only stream feeds but no image analysis is done and so no alarms or events will be generated,
• Modect – or MOtion DEteCTtion. All captured images will be analysed and events generated where motion is detected.
• Record – In this case continuous events of a fixed length are generated regardless of motion which is analogous to a convention time-lapse video recorder. No motion detection takes place in this mode.
• Mocord – This is a hybrid of Modect and Record and results in both fixed length events being recorded and also any motion being highlighted within those events.
• Nodect – or No DEteCTtion. This is a special mode designed to be used with external triggers. In Nodect no motion detection takes place but events are recorded if external triggers require it

In practice, my cameras are generally set to Modect, unless I have an indoor camera with particularly high traffic, in which case Monitor makes more sense since all the motion detection events would be me moving around and about (take it from experience, you see yourself doing some pretty strange things). This is also a nice way of judging how much load each camera adds, as the setting is pretty immediate if you’re watching htop.

With time, you should now have a zoneminder console similar to mine:

ZM Main Console

I’ve noted in particular how offline hosts appear red, while online hosts appear green or orange depending on their function.

Perhaps the only last area of configuration are the zones themselves (finally, the zone in ZoneMinder!) These define the regions of interest, in each video source, that will be used for event detection. Clicking on “1″ under Zones will allow you to modify the default zone for the video source. This is where you’re really given a lot of control far beyond anything in-camera will ever offer from even Axis.  You can add points and create polygons, as well as tweak sensitivity on an interface that looks like this:

Here, I've rejected a region that gives false positives; cars going by on the road.

Returning to the main “Console” view, the rest of the interface itself is relatively self explanatory.

## Daily Use/Monitoring

If you’re interested in viewing all of the video sources currently enabled, clicking “Montage” should give a view similar to the following:

Montage view, including author

You’re also given the FPS below each camera, this is also handy. Lower resolution (eg I show a 320×240 source blacked out) cameras are somewhat intelligently tiled as well, using the available space pretty well.

Clicking on any of the events back on the console page should bring up something similar to the following, showing details about all the motion detection events from the given source (or all sources):

Hope nobody studies this in too much detail...

Clicking on any of the event IDs or names pulls up a window where you can review the event, from a few seconds before, to just after. You can also click anywhere below on the scrub bar to jump ahead or back, as expected. It isn’t perfect, but does a surprisingly good job:

A car enters my driveway at night...

Perhaps the coolest is “Timeline” view, a high-level plot of motion detection activity across all cameras overlaid on a timeline. This gives you an at-a-glance overview of whether the same events were being detected across all cameras at the same time, or to quickly pick out what time of day generates the most activity. In this view, mousing over times and activity as demarked by red on the plot refreshes the thumbnail appropriately, as well as with the detection region highlighted in red.

My timeline for all zones

It isn’t always the most useful way to review events, but perhaps one of the more unique. I’ve found it useful for reviewing a few days or weeks at a glance when I’m gone. There’s also certainly a nice pattern that emerges over time, at least for me.

## Mobile

ZoneMinder supposedly has a nice mobile view available, however, I’ve had relatively little experience with it and had difficulty enabling it on my iPhone 3GS. Viewing the normal ZM site works fine, however, motion detection playback doesn’t work all the time.

In the meantime, I continue to use IP Vision for monitoring all my MJPEG sources:

IP Vision on the iPhone. Streaming MJPEG!

If you’re interested in me detailing this, just let me know. Setup is again straightforward and merely involves knowing the correct paths and forwarding a few ports in your router. Also, it’s a great way to quickly consume tons of 3G bandwidth!

# Conclusions

Setting up a robust, nearly commercial-level reliability home video surveillance system is now easier than ever thanks to the huge variety of video hardware and open source software available. I’ve moved from one single camera with in-camera motion detection sending alert emails with 5 second video clips to a gmail account (which quickly filled to the limit), to a secure and expandable motion detection suite monitoring at times 7 cameras that is accessible virtually anywhere I can get online.

If you’re only interested in home monitoring during a vacation or time away, setting up a system like this might not be the best solution, so long as you’re willing to sift through either an FTP dump full of videos and stills or a gmail account choc-full of videos. However, if you’re serious about having a manageable system with a number of fixed (or PTZ!) cameras that you need constantly monitored, ZoneMinder makes sense and gets the job done. In the future, for serious users, it can even be hosted commercially or simply store the event cache on a network share elsewhere to prevent physical tampering or theft.