Thursday 23 February 2012

Howto Turn your old webcam into a motion-detecting security camera in Linux


If you have an old cam that you are not using, you can use it as a security cam. Control Motion is a program that monitors the video signal from one or more cameras and is able to detect if a significant part of the picture has changed; in other words, it can detect motion. The program is written in C and is made for the Linux operating system (using the video4linux interface). Motion is a command line based tool whose output can be either jpeg, ppm fies or mpeg video sequences. Motion is strictly command line driven and can run as a daemon with a rather small footprint.

What motion can do?

  • Taking snapshots of movement
  • Watch multiple video devices at the same time
  • Watch multiple inputs on one capture card at the same time
  • Live streaming webcam (using multipart/x-mixed-replace)
  • Real time creation of mpeg movies using libraries from ffmpeg
  • Take automated snapshots on regular intervals
  • Take automated snapshots at irregular intervals using cron
  • Execute external commands when detecting movement (and e.g. send SMS or email)
  • Motion tracking (camera follow motion – special hardware required)
  • Feed events to a MySQL or PostgreSQL database.
  • Feed video back to a video4linux loopback for real time viewing
  • Lots of user contributed related projects with web interfaces etc.
  • User configurable and user defined on screen display.
  • Control via browser (older versions used xml-rpc)
  • Automatic noise and threshold control
  • Motion is a daemon with low CPU consumption and small memory footprint.

Install Motion

- For ubuntu / LinuxMint and other debian based systems, you can install motion from terminal using the command:
sudo apt-get install motion
- For Fedora :
RPM for Fedora 12/13/rawhide on x86/x86-64 Available on RPM Fusion, build without DB support.
Motion and all its dependencies (ffmpeg…) are available on the RPM Fusion repository. Configure the repository and Install motion with
yum install motion
-For other linux distributions download and install the tar package.
  • ntar and uncompress the file to the place you want the program installed. Editor recommends placing the motion source file directory in /usr/local.
cd /usr/localtar -xvzf /path/to/motion-3.2.X.tar.gz
  • Before to start compiling be sure to have build essential installed:
sudo apt-get install build-essential
  • You will now have created a directory called motion-3.2.X. You can rename it to motion (mv motion-3.1.X motion). I recommend creating a symbolic link to the current version. This way you can more easily experiment with different version simply by changing the link.
ln -s motion-3.2.X motion
  • Now change to the new directory
cd motion
  • Run configure. You can start with the defaults. If you need to modify the installation parameters you can read the next section.
./configure
  • Build the code
make
  • Install the code, manual page, etc
make install
  • In /etc/motion/ you will find a file called motion-dist.conf. If it is the first time you install Motion – rename this file to motion.conf and edit as a minimum the settings: videodeviceinputnormfrequencywidthheight and target_dir. That should get you going.
  • Run the program. To enable more features you must modify the config file.
motion

Using Motion:

To start motion open terminal and type :
sudo motion
After motion is installed, we have to configure Motion to save captured images in a remote server, to do that we need to install wput a command line FTP client that upload the captured photos by motion , to an remote FTP server. You can install wput by entering the following command into a terminal :
sudo apt-get install wput
- Now you can configure Motion to use wput to upload captured photos by adding the lines bellow to motion.conf file :
gedit /etc/motion/motion.conf
And add these lines at the end of the file:
# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)# The filename of the picture is appended as an argument for the command.on_picture_save wput ftp://USERNAME:PASSWORD@REMOTE SERVER %f
Now save and close.
- Finally, we will add Motion to startup automatically start with the server, to do that go to top menu System–>Preferences–>Startup applications then add a new startup program, type in a name for it and then type:
Selection_061
You should now be able to open a web interface for Motion now by typing in localhost:8000 from the server itself or XXX.XXX.X.XXX:8000 from another computers web browser. To view a live stream of your webcam type localhost:8001 from the server itself or XXX.XXX.X.XXX:8001 from another computers web browser. You can change settings from this interface here too, you can even make Motion generate it’s own config files to fit your setup exactly.
Result after installing motion:
motion1
Useful Links: lavrsen, infectedproject

No comments:

Post a Comment