Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
Site Navigation
Linux Forums
Linux Articles
Product Showcase
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds
Free Publications

In these days all the new netbooks and most laptops have built-in webcam, or at least add one external costs very little, apart from the traditional use in video calls you can use our Linux box to create a monitoring device, it can be used to monitor your child while you are at another PC, or your pet while you are at work, or have a home-made video surveillance system for your properties.

To accomplish this we will use the software Motion, the software is present in many distributions, I will give commands using my Ubuntu 10.04.

Features that made me choose this software is the ability to remain asleep until it detects a noise or movement, and then activates and
records, plus the ability to define custom actions when it start (send an email, an sms , Etc.).

The installation is fairly easy (just become root):

aptitude install motion

Now open the configuration file with an editor, I will use gedit

gedit /etc/motion/motion.conf

This will open a file very long and full of options. Some of them are best left as is, unless you know exactly what youre doing. Ill show
you how to tweak some options to save images in a directory more convenient to consult (default is /tmp), how to configure some
parameters of recording and, finally, how to use the web interface with username and password protecting it (do not enable the default !).

First activate motion in daemon mode, so it can be activated regardless of our session.

# Start in daemon (background) mode and release terminal (default: off)

daemon on

Change the option that indicates where to write the pid of the daemon, put it in /home/username/ so you have the proper permissions.

# File to store the process ID, also called pid file. (default: not defined)

process_id_file /HOME/USERname/motion.pid

Change now the settings for the image resolution, im using 640480

# Image width (pixels). Valid range: Camera dependent, default: 352

width 640

# Image height (pixels). Valid range: Camera dependent, default: 288

height 480

And now we decide how many images taken every second, ill take 4 (may vary from 2 to 100).

# Maximum number of frames to be captured per second.

# Valid range: 2-100. Default: 100 (almost no limit).

framerate 5

After that we can adjust the brightness, contrast and saturation to be used in the acquisition of images. These options have a reason to
exist only if the camera has no auto-detection, as with the cheaper camera, I try to let the default values.

# Let motion regulate the brightness of a video device (default: off).

# The auto_brightness feature uses the brightness option as its target value.

# If brightness is zero auto_brightness will adjust to average brightness value 128.

# Only recommended for cameras without auto brightness

auto_brightness off

# Set the initial brightness of a video device.

# If auto_brightness is enabled, this value defines the average brightness level

# which Motion will try and adjust to.

# Valid range 0-255, default 0 = disabled

brightness 0

# Set the contrast of a video device.

# Valid range 0-255, default 0 = disabled

contrast 0

# Set the saturation of a video device.

# Valid range 0-255, default 0 = disabled

saturation 0

leave a bit of options as they are for the moment, and change the codec to use for the films that well produce, I do not like the default (flash) and so Ive put mpeg4

# Codec to used by ffmpeg for the video compression.

# Timelapse mpegs are always made in mpeg1 format independent from this option.

# Supported formats are: mpeg1 (ffmpeg-0.4.8 only), mpeg4 (default), and msmpeg4.

# mpeg1 gives you files with extension .mpg

# mpeg4 or msmpeg4 gives you files with extension .avi

# msmpeg4 is recommended for use with Windows Media Player because

# it requires no installation of codec on the Windows client.

# swf gives you a flash film with extension .swf

# flv gives you a flash video with extension .flv

# ffv1 FF video codec 1 for Lossless Encoding ( experimental )

# mov QuickTime ( testing )

ffmpeg_video_codec mpeg4

The last option that I changed is the destination where the files are written, the default is /tmp, but since Ubuntu erase it at every boot, I
think is not a good idea, give a directory where you can write as a user and have a lot of space (I put /home/myuser/motion/)

# Target base directory for pictures and films

# Recommended to use absolute path. (Default: current working directory)

target_dir /home/zeno/motion

Motion presents images captured through a web interface, set a username and password

# Authentication for the http based control. Syntax username:password

# Default: not defined (Disabled)

control_authentication username:PASSWORD

Now save the file, and add to our username the group motion:

adduser USER motion

Note that in order for change to take effect it will have to restart the X server, just do a logout and then a login, remove also motion from
autostart at boot with this command:

update-rc.d -f motion remove

From now on we will decide when to start motion and video surveillance, with a simple terminal command as simple user: motion

When the daemon is started, the management of motion can be made through web interface. Open your browser and point to this address:


You will have access to at small Motion interface with which you can edit the configuration file, noting the current settings and start or
pause the motion detection. Also, you can monitor in real time what your webcam is capturing from another web interface. Just point your browser to this other address:


Finally, if you want to associate some action with a motion detection you should act on the motion configuration file
(/etc/motion/motion.conf) and change these parameters:

# Command to be executed when an event starts. (default: none)

# An event starts at first motion detected after a period of no motion defined by gap

; on_event_start value

# Command to be executed when an event ends after a period of no motion

# (default: none). The period of no motion is defined by option gap.

; on_event_end value

You must put your scripts instead of value, could be an email, sms or any action that may be initiated from your PC.

Have fun capturing whats going in front of your webcam when you are away.

Originally posted on my blog http://www.linuxaria.com

Rate This Article: poorexcellent
Comments about this article

Comment title: * please do not put your response text here