본문 바로가기

라즈베리파이(RPI)

[펌] Raspberry Pi for CCTV using motion

출처 : http://blog.snapdragon.cc/2012/08/15/raspberry-pi-for-cctv-using-motion/

 

Raspberry Pi for CCTV using motion

I wrote about doing CCTV with zoneminder before, but realized that this might be overkill for many people. If you use less than 4 cameras, you can use the motion package. It works nicely with the Logitech webcam, I connected to my Raspberry.

Raspberry Pi running motion over a web browser

Figure 1: Raspberry Pi running motion over a web browser.

The camera worked out of the box except that saturation, brightness, etc was way off. You can configure it with the v4l2-utils package. Once you have verified that the picture is OK by using uvccapture, you should be ready to install motion. For my USB webcam, motion worked out of the box. No settings needed at all. For finetuning, I changed the framerate in /etc/motion/motion.conf to 25. Even at that rate, load stayed at 0.00 with abotu 20% CPU usage. Maybe the GPU is doing the bulk of the image processing work.

By default motion captures .swf and .jpg. For me .swf is enough, so I disabled .jpg output with output_normal off.  If you want to view your cam over a browser, set webcam_localhost off. That way every IP address can access the video stream over a local address like http://10.0.0.19:8081. Further up, you can see my stream. Unfortunately brightness is still a bit too low. I’ll change that later.

Now comes the part where we make our setup really useful. By default motion saves all captures .swf files in the current working directory. When using the init-script, you should save a sensible default output directory. You can change that with the target_dir parameter in /etc/motion/thread1.conf or motion.conf.

So far so good. By now we have motion running and saving all observations to a directory. That’s OK, as long as we can just SFTP into the raspberry and view the footage. If you want your mum to use it, there needs to be something simpler. I used the PHP-script MotionBrowser by Carlos Ladeira as a simple way to view events by day and hour.

Manage recordings done by motion over a simple web interface

Figure 2: Manage recordings done by motion over a simple web interface

For the script to run, you need to install a web server with PHP-support. Apache is overkill here, so I recommend lighttpd or nginx. I won’t go into the details of how to install a webserver, but believe there are many tutorials out there. On top of that you also need mysql to manage the event list. The setup is described on the MotionBrowser site.

Once your webserver is running download motionbrowser.tar and unpack it into /var/www or any other web server root dir. The script worked well, except for serving the .swf-files. When checking download.php, you will notice that the script is actually made to serve .avi-files. We could change that in the motion-settings, but I prefer to stay at .swf because they can be viewed in the browser. Here is what needs to be changed:

In line 53 change avi to swf, so only .swf-files can be downloaded.

1
 if (strtolower(substr(strrchr($filename,"."),1)) !"swf") return;

And also replace the whole header part with just one line to simply view the SWF.

1
 header('Content-Type: application/x-Shockwave-Flash');

That should be it. Enjoy your USD 35 surveillance system.

Update:

If you don’t like refreshing your browser all the time, you can view the live stream in vlc as well.