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.
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.
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.
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.