LWN.net Logo

Detect and record video movement with Motion

By Forrest Cook
June 10, 2008

Motion is a video application that monitors a video4linux device such as a USB camera and records movement within the image:

[Motion]

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. Motion is a command line based tool whose output can be either jpeg, ppm fies or mpeg video sequences.

An installation of Motion was performed on a machine with a 3Ghz Athlon 64 processor running Ubuntu 7.04 (Feisty Fawn). The most recent version of Motion (v 3.2.10.1) was downloaded, the file was uncompressed and untared. The normal configure, make and make install steps were performed. If one wishes to record mpeg movies, the libavcodec and libavformat libraries must be installed prior to running configure.

The make install step needed a bit of manual intervention, it was necessary to create the /var/run/motion directory and copy the motion-dist.conf configuration file to /usr/local/etc/motion.conf. The config file was modified to define a USB camera, the camera's default resolution was defined and the destination directory for images was set. The framerate parameter was changed to 2 seconds to slow down the rate of accumulation of image files.

A Kensington Model 67015 VideoCAM VGA USB camera was plugged into the computer. It is a good idea to run a real-time video monitoring application such as xawtv or EffecTV (in DumbTV mode) to adjust the camera's focus, brightness and contrast settings. Running Motion was simply a matter of typing "motion" on the command line. The program takes about 25 seconds to start recording movement, presumably most of this time is spent learning the contents of the video. After this delay, the software would output a line of text and create one .jpg file for each movement it detected. The images were inspected with the Mirage image viewer and a changing sequence of static images was observed.

Motion has a wide variety of capabilities and configurable parameters. The Motion Guide and Config File Options are a good place to read about the various capabilities and the FAQ gives answers to common questions.

One can imagine a number of uses for Motion, cube farm denizens could find out what is causing their pens to disappear at night, people in high crime areas could use it to catch vandals and thieves in the act. The on_picture_save configuration directive can execute a script on motion detection, this could be used to copy captured images to a distant web server for remote monitoring. This feature was tested by adding a line like this: on_picture_save scp %f remote-host:/directory-path to the config file, the operation worked as expected.

It should be noted that inexpensive USB cameras may only work in a very limited set of lighting conditions. Serious surveillance would require an NTSC or PAL video input adapter and a better camera, or a high resolution webcam.

Apparently, no major releases of Motion have been released in a long time, but the developers' mail archive shows that recent work has been done on the project. A new point release just showed up this week, it added a fix for a security bug.

If you are looking for a way to do automated video surveillance, Motion is an excellent tool for the job.


(Log in to post comments)

Detect and record video movement with Motion

Posted Jun 12, 2008 15:47 UTC (Thu) by rvfh (subscriber, #31018) [Link]

I had motion on my old web server (pentium @233MHz, 96MB RAM running Ubuntu Server 6.06 at the
time) to monitor my cat during holidays, using a Philips webcam. Set to take a picture per
second (the minimum frequency), it worked a treat and I could see my cat was alright and
properly fed and cleaned by the person we had mandated.

Motion is a wonderful piece of code, extremely easy to configure and that works wonders at
monitoring anything. All it needs is cheapo webcam and laptop!

HTH

Detect and record video movement with Motion

Posted Jun 12, 2008 18:10 UTC (Thu) by Baylink (subscriber, #755) [Link]

As you noted, inexpensive cameras are noisy in low light and motion may well detect this.

If you need anything more than motion provides, of course, you should probably look at
ZoneMinder before trying to extend it... unless you're just in it for the hack value...

Detect and record video movement with Motion

Posted Jun 16, 2008 6:35 UTC (Mon) by djfoobarmatt (subscriber, #6446) [Link]

I have been using ZoneMinder lately which is maybe overkill for a one camera system but is 
excellent if you're doing surveilance where you want to be able to review events and have
multiple 
cameras with detection zones etc...

Examples of what you can do with an OLPC and motion....

Detect and record video movement with Motion

Posted Jun 13, 2008 3:09 UTC (Fri) by jwb (guest, #15467) [Link]

I used motion for years with the output of an Axis camera, and the combination actually led to
the apprehension of the crack fiend who kept breaking into my office.  I highly recommend this
software.

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds