My Home Video Surveillance Setup.

Jayce

Fully Optimized
Messages
3,056
Location
/home/jason
Hello thar. I figured I'd take the opportunity to blab a little bit about my video surveillance setup, mostly because, well, why not, and secondly in case anybody here may have any interest in doing such a thing. I know I had made passes in the past in other threads how I do this but I figured I'd post a thread based directly on that. This may be kind of a honeymoon phase yet, as I've recently switched which software I use, but now that I got the program fine tuned with relative ease, I think this relationship is going to work out just fine.

The server is my old desktop, which is a quad core system (Q8200) with 4GB of DDR2 RAM. It's running Ubuntu 12.04 64 bit and runs services for file/print/download/backup/web and now, video surveillance services. Since I already had the box running 247, it made sense to find a Linux solution so I could just tack it onto the existing system.

Traditionally I've used ZoneMinder for video surveillance. In the past I've used cheaper, lower end cameras, and ZM has worked out great. However I invested in a pair of really decent cameras with 1280x800 resolution, outdoor rated, IR, POE, etc etc etc... After a few days I began having issues with ZM. I just noticed my feed wouldn't come up and suddenly the log file was posting a bunch of errors. Further research suggested it may be the way ZM manages memory, due to the fact it's (currently) shared memory, whereas newer systems and Linux itself uses MMAP, a much more efficient way to handle these tasks. Supposedly the higher resolution cameras are what pushed it over the edge. I'm sure it's fixable, as I just have to find the right memory settings and adjust them accordingly. Plus I hear an updated version is on the horizon, but with no real ETA I decided it was time to check out another application.

Another main contender in the world of Linux/CCTV software is an application known as Motion. I always kind of ignored Motion due to the fact I always assumed it was meant for local USB and/or integrated laptop cameras, which is definitely not what I want since I have IP based cameras. Further reading suggested Motion works great with network based cameras and that it's configured out of the box for USB functionality, with the addition of network cameras being just an extra step or two. I was a little curious about the fact there's no GUI for Motion, which made me think, how can it be that easy to use like other users were suggesting? Turns out when you install Motion, it adds several config files in /etc/motion for you to play with.

motion.conf - this file is for global settings that will be the same across all cameras, OR, if you have only 1 camera, all configs go here.
**thread.conf files are used when there are 2 or more cameras involved**
thread1.conf - this file is for any settings unique to camera 1 and camera 1 only
thread2.conf - this file is for any settings unique to camera 2 and camera 2 only
thread3.conf - this file is for any settings unique to camera 3 and camera 3 only
thread4.conf - this file is for any settings unique to camera 4 and camera 4 only
etc...

So I fire up motion.conf and begin reading the config file. This config file is jampacked of information, which can make your head spin at first until you realize 95% of it is examples and directions. So don't worry, calm down, take a breath, and just... read. I didn't change much at all, but most of the things I changed were:

height - set the height resolution to my camera (default is set very low)

width - set the width resolution to my camera (default is set very low)

FPS - changed it from 2 to 5, which gives me a slightly smoother picture

target_dir - changed it to /var/www/video (I have apache installed) which means if I go to MyServerDDNS-URL.com/video, I can bring up the recorded feeds from anywhere that I have internet (as long as the port is forwarded). Otherwise I can access it locally on my LAN via serverip/video. Make sure whatever you set the target_dir to that the user "motion" has full access. When motion runs, it'll run as the user "motion" (gets automatically created when you install Motion), so make sure that user has access to the directory it's saving the feed to.

threshold - defaulted to 1500 (the amount of pixels that need to move to trigger motion detection to begin recording), but at night when IR mode kicked in with a lesser quality image, I realized some things I wanted caught weren't getting caught. Certain movements I would do wouldn't trigger it, even though 1500 seems pretty sensitive to begin with. My cameras have decent IR quality, but nothing beats the clarity of daytime footage, and I wanted it to be sensitive enough to trigger even if a bird was trotting around the bottom part of the screen. I thought about getting a stand alone IR light to brighten up the deck area even more, but ehh, maybe someday. For now I lowered it considerably (to 250) for now to test and see how things go. So far, so good. I knew by setting it to be more sensitive it would also trigger more false feeds (particularly during the day), but here's the bottom line: It's better to have too much footage than not enough. I'd much rather page through a couple feeds of a bird flying by, a cat walking, the wind blowing a flag, and HAVE the shot of the guy snatching my grill as opposed to not having anything at all. Of course you don't want it so sensitive that a flea jumping past the screen triggers it, but... well you get the point. :p

One thing I did not adjust that I think is a cool feature is the gap feature. With gap (default = 60), you can customize the length of time before the end of an event. If I understand this correctly, it means that if someone walks by and triggers the event, and 55 seconds later they walk by again, those two captures will be under the same event. The default sits fine for me, so I didn't change it... but I figured I'd highlight it a bit.

I also adjusted the output. By default it saves a bunch of jpg files, but then it'll have a single swf file that you can play which basically plays the jpgs from that event in one single line. I changed mine from swf to mpeg4 (which gives me an avi file) so not only do I still have the jpg shots, but I have an actual video file too. Sure, it takes up more space, but so far I'm doing pretty decent on the amount of data I can store, so I may leave it as is.

I also made sure at the very bottom of motion.conf to uncomment thread1.conf (with the proper path to /etc/motion/thread1.conf of course) so thread1.conf would get recognized as a valid camera file. Keep in mind I'm using a 2 camera setup, hence the need to utilize the thread.conf files. Then, in thread1.conf, I added a netcam_url entry, so it read something like:

netcam_url http://192.168.1.100/video4.mjpg (this is specific to my exact camera, your's may vary)

In fact, that's the only thing I have in my entire thread1.conf file. In my case, since my two cameras are identical in make/model/specification/etc, I decided to do exactly what the developers suggest and keep your global (common) configurations in motion.conf, and only keep camera specific settings within each thread.conf file. Since my cameras are identical, I could set the resolution, fps, etc etc with each one. Currently I only have one camera hooked up due to other projects going on around the house (makes more sense to run the cables neatly for camera 2 when my next project is redoing the walls in the next room), but when I set up the 2nd one, I will likely have each thread.conf file containing a different target_dir. That way I can shove all "Backdoor_Cam" feeds in one directory, and "Frontdoor_Cam" feeds in another. Just a way to stay organized. I know you can set the saving convention of the feeds to contain the name of the camera, but ehh... I'd personally like them to be in other directories. Your opinion may vary with that one.

Motion, by default, is set up to use /dev/video0 which makes it super convenient if you're somebody who wants to use whatever camera is already integrated to your laptop or plugged in to your desktop, however once you specify a netcam_url, it takes priority over /dev/video0. That way, if you have network cameras, add their URL accordingly in each thread file by themselves and it'll work out.

The only other thing I took notice of is when I installed Motion, it did not kick on the daemon (aka background mode) because it's disabled by default. Otherwise if you installed this on your laptop, each and every time your laptop fires up it would be recording your movements. Interesting, huh? You should see this RIGHT at the end of installing it via "apt-get install motion" within the output. For me, it was the last line. So, go into /etc/default/motion and change no to yes. Once done, when your system fires up, Motion will fire up with it.

Okay, so now I have Motion running, but dangit I'm getting a lot of activity in my output! Minute after minute after minute... What is it that's triggering Motion to turn on all of the time? Well, of course by me changing the sensitivity to have more sensitive night time motion detect, it by nature means day time will be even more sensitive. However, by looking at the feed I realized that the sensitivity wasn't playing a key role here since the pesky wind was blowing a decently sized bird house we have that was hanging off the edge of our deck... I thought it was heavy enough that it wouldn't give much movement, but it was just enough so when the wind blew, it came into the shot and triggered motion detect. No problem! Motion supports "masks" which you can customize on your own. What you do is essentially create a blank image the same size as your camera resolution and make it black and white depending on where you want motion to be detected... black for no detect, and white for motion detection. By doing this, I was able to block out the bird house from the shot. The only catch is you have to save it as a .pgm, not a regular jpg or png or anything like that. Here's the jpg version of my mask if you want to check it out (imgur wouldn't upload the pgm): http://i.imgur.com/QFkon.jpg You can also see a black section up top, which is actually me blocking out the street from view. The black section on the lower left is the area of the swinging bird house. I basically took a jpg that Motion already detected in a previous event and loaded it into Gimp. By doing this, I can edit the EXACT areas I want to since I can see the full picture. If you're starting from a blank canvas, just make sure you're using a canvas the same size as your camera resolution to ensure accuracy. So if your camera is 640x480, start a canvas 640x480 and do your black/white work there. Now, something to understand, it doesn't mean your camera won't record anything in the black areas... it just means it won't be triggered by motion in the black areas. If I walk past one of the blacked out areas, nothing happens. If I walk into a white area of the screen and it triggers motion detect so the feed is running and recording, but then a car drives by in the blacked out area, it'll still record that vehicle driving by. Also note, PTZ (pan tilt zoom) cameras by nature, when you move them, you're changing the image, so of course motion detection gets triggered then.

It also seems that Motion is a bit lighter on resources than what I expected. I find that when Motion is running and recording events that my server (granted, it's a quad core... but a very low end quad core) doesn't seem to be phased that much, which sits nicely with me since my server does so many things to begin with. I'd also like to highlight quick how crazy easy it is to back everything up. It's all a config file! Copy the config files, save them somewhere else, and if you ever redo your server, bring them back over (after installing Motion of course) and you're good to go!




Okay, now that this thread is turning into a "TL : DR" scenario, let me summarize:

Installed "motion" on my server
Changed /etc/default/motion from no to yes so it could run automatically upon boot
Added my own custom settings to the motion.conf for my specific camera, like FPS, height, width, etc.
Uncommented thread1.conf in motion.conf to essentially "activate" thread1.conf
Added my camera's specific video stream URL to thread1.conf
Changed target_dir so it would save in a specific directory, in my case, an Apache directory so I could view it online easily
Changed permissions on the target directory mentioned above so "motion" had full access, as motion runs as the user "motion" when launched (I used jason:motion with 775 permissions, as an example)
Created a mask file in Gimp and loaded it in to Motion. I saved the mask in /etc/motion for organizational purposes, then pointed motion.conf to look for the mask in the /etc/motion directory

And uh... that's it! I now have a solid home surveillance setup using Motion and my outdoor surveillance cameras. It was a little bit of a bear to run the cable since I wanted hardwired + POE cameras, but luckily my bathroom is in mid renovation now and it also shares an outside wall with the deck area, which is where the backdoor camera is, so I ran the cat5e through there easily to the basement where my office is. The front door camera I have yet to hook up, however I already have a game plan for running those cables when I can get to it. But first... I need to finish out the bathroom renovation before I move on to other projects. :p
 
I hear you. We bought our first house in January, which naturally brings on the "what do I want to change?" mentality. Once we got settled in I realized I'd like to have eyes on our home when we're not here. I look at it like, if somebody wants to get in, they'll get in... but I'm getting their pretty face on camera before they hightail it.

I'll likely be doing a setup similar to this for my fiance's parents, as they have a 2nd property they'd like eyes on when they can't make it there that often. Their worry was sparked when an immediate neighbor of their's was selling their house yet living upstate, but came to realize somebody broke in and was living in their place while it was on the market... creepy...

I figure for that scenario, a nettop (I'll have to test it with my netbook to make sure the Intel Atom will be enough to push it, but I think it'll be acceptable) running Ubuntu + Motion and an indoor IR camera would fit the bill. Nobody should be in the house when they're not there, so if any motion is detected, any motion = red flag. But of course, what about if they steal the camera and nettop, thereby stealing your video feed too? Since the system will be recording a limited amount of feed and not 247 day after day, I think it would be super convenient to configure Motion to save in either an actively sync'd Dropbox or Ubuntu One folder so things are saved to the web before they can realize there's a hidden nettop to steal.
 
Here's two side effects I never thought about when I put this camera in. For one, all of your fails are documented. The other night I made some burgers on the grill. Shut the grill off, turned the deck lights off, and immediately slipped and fell, sending the burgers a good 10 feet in the air. My other half came running out, laughed hysterically, and begged we watch it on video. I hadn't even given it a thought that I had been on camera when I slipped, but alas, we watched my epic fail on repeat. To make matters worse, when I brought new burgers out, we were out of propane on the grill.

Another thing I didn't expect was what I found this morning. I have Motion sending feeds to /var/www/video, so any new feeds come up right there on the page. I F5'd it and saw another came up only a minute prior, so I checked it. Go figure, 3 little kittens running around on the porch playing. I'm not so sure my existing cat would approve... she's a one-cat-per-house kind of feline. Nonetheless, time to figure out how we can rangle these kittens up and make sure they're taken care of and sought after for good homes!
 
I'd love to set something up like this! Way to inspire me. I may need to go out and put some money down on some hardware soon
 
Absolutely. The older I get and the more entrenched I am about taking care of my house, family, etc., this has really given me a substantial comfort zone. It comes convenient too even beyond a security standpoint. Downstairs in the basement I have my stereo, desktop system, office area, etc. When I'm down here, the decibel levels are often astronomical. All I can often hear when somebody is otherwise knocking at the door is the incredible mind blowing FLAC-induced magic known as Pink Floyd's live concerts. That's why I added a spare LCD (simple 17" square LCD) to my server, so I can retain my dual screen setup on my desktop while still having a feed to the outside.

I spent a pretty penny on the cameras I got - 300 bucks a piece. But they're also POE, IP66 rated, 1 megapixel, IR, weatherproof, etc. You can spend far less and get decent cameras, but I wanted cameras that would withstand 0*F as well as 100*F. We get hit with both extremes now and then in PA...

Keep the YouTube tutorial video in mind! Don't forget to post back here, UbuntuForums (if Ubuntu is your distro) or the Motion mailing list for help!
 
Just to update, I tinkered around a bit with the idea of getting multiple feeds on the same page. I kind of wanted a grid layout without having 1 camera feed per tab in my web browser and have to switch between them. I ended up resorting to some basic HTML/CSS and came up with a pretty simple design (thanks to a good buddy who's a web designer who helped me get started).

My motion.html config file
(this example contains 9 cameras. Of course, the number of lines would be dictated upon the number of cameras in use)

That code is from an html file, which I simply named motion.html and stored it in my home directory. Remember that monitor that I mentioned was hooked up to my server? I set the path to this file to be the home page... so if I open Firefox on my server, this page opens automatically so I can see all of my feeds. What's nice is each camera feed acts as its own link, so if I click on it, I get a full size view of that specific feed. Hit back, and I'm back to the grid layout.

Within the thread.conf files (remember, one thread file per camera) you can set the webcam_port accordingly. As you can see, I stuck with the default 8081 and counted upwards. The IP that you see is the same with each camera because it's the IP of my server itself, whereas the port is what dictates camera 1 vs camera 2, etc. If any of you guys are out there using Motion, you can easily plug in this file to allow you to view multiple feeds at once. You just need to be aware of a few things. For one, the IP is going to be whatever your server is. Likewise, the ports will be whatever you set your ports to for each camera. I know by looking at that, 192.168.1.15:8081 = camera 1, etc. That's just what worked for me. Also, if you notice there are some <br /> entries. Those are line breaks. This forces camera 4 5 6 to be on line two and camera 7 8 9 to be on line three due to the placement of the breaks. You can customize the location of the breaks to dictate what kind of grid layout you have. For example, there's 9 lines in this example with a break three ways, meaning you have a 3x3 grid. If you add more lines until you get to 16, and have it break four ways evenly, you'll have a 4x4 viewable grid. Also take note of the width percentage a bit higher up in the config. This width percentage is based on 100%, of course, so if you have 3 cameras listed, don't try to put in 50%, 50%, 50%. Instead, I recommend doing 32%, 32%, 32% for a trio. Reason for 32 and not 33 (which would bring you to 99) is you have a small gap in between each frame, which is a nice separator. Same goes for a four way split... I use 24% instead of 25%. Keep in mind you may have to tinker with the width percentage in order to scale all of your cameras on screen. I have wide screen monitors, which means I have to scroll downward (since my overall height is shorter than my width) to see the rest of my feeds. A quick workaround is to adjust the width percentage to be lower until you can fit the grid on the primary page without scrolling. That's why my example has 3x3, yet instead of 32-33% width, I'm using 25% width - that's so I can fit the grid on my particular monitor without scroll bars.

tl:dr = Adjust the IP, port, and width percentage to your liking until you find a layout/grid that works with your specific resolution/monitor size.

At any rate, by simply throwing this file together, I have an easy way to see both of my cameras (my example had 9, yes, but I only have 2 cameras at my house) at a single time by looking at one screen. As a result I wanted to share with you guys this file in case you wanted to utilize it for your usage. I plan on working with this layout a bit more to see what I can learn. My buddy suggested I add some javascript to it so I can have fields within the embedded web page which allow the user to put in their IP, port, etc. without having to edit the file itself. Cool idea, but I have no idea how to do any coding... but I may take a look at a few links and see where I end up. Despite the fact editing the file is very easy, it'd still be a +1 on the ease-of-use scale to add more integrated approach to adjusting those parameters. If anybody has any suggestions on that front, I'm all ears!
 
Back
Top Bottom