This article was published more than a year ago, there may have been developments.
Please take this into account.

Set up a Security Webcam with “motion detect” using linux, in contrast to other solutions, is a procedure quite simple, despite the lack of a GUI for the configurations (often it is good not to have a GUI). On the front “hardware” everything we need is a webcam USB, regarding the software we will need a Linux distribution and the program “motion” (in the official repositories). Below I translate and I simplify the procedure comes from the blog

What can we do with a setup like this?

  • record video and / or individual frames in case there is some movement in the area shooting,
  • take pictures at regular intervals, even if there is no change in the recovery,
  • execute the stream the recovery area,
  • assign a specific extension the video taken,
  • in case there was an area on the move is possible show a rectangle in the area of ​​interest to emphasize the movement, to exclude false positives,
  • configure in a simple way un backup filming (for example on Dropbox) to access wherever we are in the recovery area.

Ubuntu is the most widely used Linux distribution in the world, I do not have to hurt the users of other distros, but all the examples of this tutorial refer to Ubuntu. Nothing remains that everyone can install it on their own (Fedora, BSD, Slackware, etc.). First link our webcams the pc. My webcam is a very economical, bought some time ago at a department store in unless 10 Euro.

Now install and start the software “motion“, a script on the command line that will allow the recording of moving parts.

sudo apt-get install motion
sudo motion

It should all work the first time and without the need for configuration, but for those who want to change the basic settings… The configuration file is dedicated “/etc/motion.conf” (will note that there are no more files “threadN.conf” in this directory, each corresponds to a webcam which can be configured individually (if there were more than one). The images are saved in “/tmp/motion” and every time you restart your PC are automatically deleted.

Note: make sure to restart the server “motion” every time you change a setting.

south / etc / init.d / motion restart

To change the settings, just take a look at the configuration file. They are well commented (in inglese). Here are some useful configuration for organize data quickly:

#/etc / motion / motion.conf

# Locate and draw a box around the moving object.
locate on

# Draws the timestamp using same options as C function strftime(3)
text_right %Y-%m-%dn%T-%q

# Text is placed in lower left corner
text_left SECURITY CAMERA %t - Office

If we want to imprint date and time on the photos:

# File path for snapshots (jpeg or ppm) relative to target_dir
snapshot_filename %Y%m%d/camera-%t/snapshots/hour-%H/camera-%t-%v-%Y%m%d%H%M%S-snapshot

# File path for motion triggered images (jpeg or ppm) relative to target_dir
jpeg_filename %Y%m%d/camera-%t/motions/hour-%H/camera-%t-%v-%Y%m%d%H%M%S-%q-motion

# File path for motion triggered ffmpeg films (mpeg) relative to target_dir
movie_filename %Y%m%d/camera-%t/movies/hour-%H/camera-%t-%v-%Y%m%d%H%M%S-movie

# File path for timelapse mpegs relative to target_dir
timelapse_filename %Y%m%d/camera-%t/timelapses/hour-%H/camera-%t-%Y%m%d-timelapse

Finally we can optionally organize a backup. I will not elaborate explanations of the various steps to set, there are various ways all equally useful: from their own solutions of Ubuntu (Ubuntu One, dejadup), a Dropbox, Automatic upload of server FTP, to transfer tunnelling SSH. It depends, as always, from what we seek and what tools we have available (and the speed of configuration in my case). Among other things we've talked about similar topics in the past, The following is a small list:

And finally here is the video time lapse that is automatically encoded by motion with two exceptional guest star: Romeo e Tara. Forgive the shape a little’ Spartan.


I keep this blog as a hobby by 2009. I am passionate about graphic, technology, software Open Source. Among my articles will be easy to find music, and some personal thoughts, but I prefer the direct line of the blog mainly to technology. For more information contact me.


Gabriele Merlonghi · 12 March 2013 at 7:34 PM

Hello, Another interesting article… because I took care of a little’ time ago for an integrated video surveillance and domotics. At the moment the project is at a standstill due to lack of physical time to make it go forward.
I used ZoneMinder I think he uses the same “motion”, you know him ?

    TheJoe · 13 March 2013 at 8:09 AM

    Ciao Gabriele,
    I gave a quick look at zoneminder. It really does not seem to depend on motion, I have no idea that the software motion detect even be rewritten.
    From the quick glance I gave now I must say that in addition to integrating the same functions as motion adds other important functions: are configurable multiple cams, is configurable via web interface (which is not little) and allows you to record events such as motion to any change of scene.

    Thank you for reporting, was not familiar with zoneminder, will try it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.