Today as I got into my car I realized that someone had broken into it and ransacked my glovebox and center console. I couldn’t nail down exactly when it happened but I couldn’t help but feel violated. Someone else in my neighborhood also had a break in. I decided to do something about it. I immediately went to the closest store and grabbed a cheap webcam and prepared to make a motion triggered surveillance system. (Man, I love Linux).
The camera I grabbed was iHome brand basic webcam for around $15. Most webcams will work with this system from what I can tell. I literally did no research beforehand, which I do not recommend. I got very lucky that the camera I chose worked without much trouble (which practically NEVER happens for me). I highly suggest checking to make sure the hardware will work before buying this or any other camera for this application.
The program I am using is called ZoneMinder, which is a fully featured open source CCTV security system . It was written by someone who had a similar experience to me. This program allows you to have multiple cameras which can be set to only record when they detect motion, and you can even break the camera images into separate zones of detection. This program can also integrate with X10 hardware to control all sorts of toys. All of this is hosted on a web server so you can access it from anywhere in the world if you desire. I’m only going to set up something locally to only record if motion is detected.
Again, you want to make sure your hardware will work with the program, so head over to the ZoneMinder Wiki hardware compatibility list as well as the UVCvideo compatibility list since ZoneMinder can use the UCVvideo drivers for linux.
My camera happened to work with the UCVvideo drivers, so I had to install that first. You can skip this section if you already have a working camera. To begin with I had to install patchUtils form synaptic. You can do the same with the command below:
sudo apt-get install patchUtils
Then I downloaded and installed the UCVvideo drivers [1 ]
git clone git://linuxtv.org/media_build.git
At this point I kept having a bit of a problem, but I found the answer on another blog. This involved running two commands to actually insert the UCV modules:
sudo depmod -a
Everyone will need the following commands to install the dependencies for ZoneMinder. Again, it runs a webserver, so there are a few important dependencies to be installed. Luckily I found a good tutorial to help figure out what all I would need.
sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server
sudo apt-get install ffmpeg libarchive-tar-perl libarchive-zip-perl libdate-manip-perl libdevice-serialport-perl
sudo apt-get install libjpeg62 libmime-perl libstdc++6 libwww-perl zlib1g
At this point, you *may* need to reboot for Apache to configure correctly. I didn’t, but the author of the tutorial I used did.
Now, finally we can install ZoneMinder itself. I installed it form synaptic, but you can get updated installations form the ZoneMInder website. Otherwise run the following:
sudo apt-get install zoneminder
After installing ZoneMinder, you now need to configure and start Apache:
sudo ln -s /etc/zm/apache.conf /etc/apache2/conf.d/zoneminder.conf
sudo /etc/init.d/apache2 force-reload
sudo adduser www-data video
At this point, open Firefox and go to the ZoneMinder dashboard by visiting
Now before I could Add a new monitor (add my camera to ZoneMInder) I had to use another program to connect my camera to ZoneMinder. I found a good video series that explains the steps for installing and configuring my camera and ZoneMinder. The program I needed was mjpg_streamer which you can get and install from sourceforge.
Of course to install this, you can just double-click the .deb file and install it as normal.
Now you have to run mjpg_streamer from the commandline using the following command:
mjpg_Streamer -i “input_uvc.so -d /dev/video0 -y -r 640×480 -f” -o “output_http.so -p 8080″
A short explanation here: “-d /dev/video0″ is the device you want to use. To find out which device your camera is, enter “ls /dev/video*” into the terminal. If you only have one camera, then it will pop up as the only result. Use that address. -y stands for YUYV format MPEG files. “-r 640×480″ attempts to set the resolution. My camera technically supports this resolution, however, that is if you have the correct drivers, which I do not. The -o “output_http.so -p 8080″ means that you are going to stream the video feed to port 8080 on this machine.
Additionally, you can add the flag “-b” to this command to run it in the background. If you do this, you have to manually kill mjpg_streamer when you want to close it.
If you didn’t get any errors, we can check to see if the video is streaming correctly. Open a new tab in Firefox and go to
If you see video, then it is working. If not, go back and double-check you’ve followed all my instructions correctly. If that doesn’t solve your problem, post on the ZoneMInder or UVC forums. I honestly do not know enough to be able to troubleshoot any more than I am explaining in this guide.
So now that your camera is streaming video, we can connect it to ZoneMinder (FINALLY!) So, go back to the ZoneMinder dashboard in your Firefox browser ( http://localhost/zm ) and click “Add New Monitor”. A window will pop up that looks like this make your values match the ones seen in this image):
Name this monitor whatever you like (no spaces or special characters), change the “Source Type” to “Remote”, change the function to Modect, check “enabled” then click the “Source” tab. This window should look like this, expect with blank textbooks:
Fill in the textbooks as I have in the example image above. Basically, you are telling ZoneMinder where to find the streaming video. The “remote Host Name” should be “localhost” since you are using the same machine. Port should be the same value as what you used in the mjpg_streamer command above (8080). The “Remote Host Path” is everything after the backslash form the web address we used to test the camera above “?action=stream”. Now notice the Capture Width and Height is different from what the mjpg_streamer command was. This was an issue with my camera. It could not handle the 620×480 resolution and it defaulted to what is seen here. Be sure that the resolution in these boxes matches the resolution of your video stream. You can check this by looking at the page title of the webpage we used to test the camera “http://localhost:8080/?action=stream” It should read something like “(JPEG Image, 320×240 pixels) – Mozilla Firefox”. Those are the values you should use here. Click “Save” when you are finished editing these settings.
That popup should close and the ZoneMinder dashboard should refresh. If everything is working correctly, your new monitor should have been added. If the text “localhost” under the “Source” column is red, then you have a problem and need to make sure your settings are correct, and that mjpg_streamer is running. Otherwise, the text should be green. Click the motor name to open a live view your new security camera.
With the current settings, it will only record an event if it detects motion. When this happens, the dashboard of ZoneMinder will add numbers in the “Events” column. Click this number to view the event. (Click “Refresh” on the dashboard if it doesn’t update those columns fast enough for you). This will now play back the video of the specific event. The window below shows an example of what an event would look like.
That is it! We are finished. Now I have a smart motion triggered security cam that will archive footage if anyone goes near our cars. Your mileage may vary of course depending on the cameras, lighting, etc. of your particular situation. I was surprised how easy all of this actually was! I’m going to play around with this a bit more and see if I can make it a full fledged security system for our house.
If you have had success with this, please post a comment and tell us about it.