A user guide written by a newbie user.
Editor: Kenneth Lavrsen
Original
URL for this document. http://www.lavrsen.dk/sources/webcam/motion_guide.htm
Version:
1.17 (for motion 3.0.3), 2002 Jul 13, 14:08
From version 3.0.1 of motion this
guide is now part of the distribution. The jpg files however are not included.
Go to the URL above if you want to see the guide with pictures.
1.5 Added a detailed
description about using the video4linux loopback device with Motion.
1.6
Corrected some details about module loading order in the video loopback section
that was added in 1.5.
1.7 Added fix for filename bug in the mpeg_encode
feature. Added note that ffmpeg sources are currently no longer available at
the ffmpeg site.
1.8 Added a reference to the URL of the original document
in case someone gets a copy in a package or paper copy and wants to see the
latest online.
1.9 Updated for rev 3.0.1. Removed the bugfixes that are now
all fixed in 3.0.1. Added a section describing the new make file options.
1.10
Added method for downloading ffmpeg from the CVS
1.11 Corrected the feature
description of ffmpeg.
1.12 Added a fix for using ffmpeg version 0.4.5. Also
added a link to locations of the ffmpeg-0.4.5.tar.gz file (no guarantee that
it will always be valid). Updated version of motion to 3.0.2. This version does
not yet cover the experimental 3.1.0 version.
1.13 Added even more ffmpeg
0.4.5 download URLs. One of them must work.
1.14 Added note about ffmpeg
and processor type in the ffmpeg section.
1.15 Updated to version 3.0.3.
ffmpeg now fixed. Added the new 3 usertext options and a section to describe
these.
1.16 Updated so that examples shows 3.0.3.
1.17 Clarified that
the timelaps function of ffmpeg generated mpegs is fixed to one shot per minute.
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. Or 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. It has
absolutely no graphical user interface. Everything is setup either via the command
line or via a set of configuration files (simple ASCII files that can be edited
by any ASCII editor).
The output from motion can be:
Motion is an open source type of project. It does not cost anything. It is
licensed under what is known as the GNU GENERAL PUBLIC LICENSE.
This means
that you can use this program as you want but there are some strict rules about
distribution and modification that must be observed. To the private user that
install this at home as a hobby this means "free - enjoy" - forget
about licenses. To the professional who wants to make money on other peoples
work and not contribute to the "free software movement" you will be
in serious legal trouble. Read the license carefully to see what is allowed
and what is not.
To get motion direct you browser to the Motion Homepage
Under the download page you will find a series of stable versions and a series of development versions.
The latest stable versions is 3.0.3.
There is an experimental version
3.1.0 which is not yet covered by this document.
This is the list stolen from the Motion Homepage.
You can find more information and links at the Motion Homepage.
Motion is distributed as source files that you must compile yourself. There
are some binary RPM files but they do not seem up to date.
I recommend compiling.
It is not very difficult.
You may run into some small problems when compiling
with either MySQL or PostgreSQL support. No worries. See the speciel sections
about the two later in this document.
The short story is:
Configure is script that you run to setup the build environment for the C-compiler. It generates the "Makefile" which the program "make" uses to compile and install the software.
To run configure your current directory must be the motion directory. You
type
./configure
You can add the parameter ./configure --help to get help
on the different switches.
This is walk through of the options. The configure script used is based on another configure scripts and contains some not very interesting switches.
Option |
Description |
Editors comment |
-h, --help |
display this help and exit |
|
--help=short |
display options specific to this package |
This command shows the options special to motion. Recommended |
--help=recursive |
display the short help of all the included packages |
|
-V, --version |
display version information and exit |
Gives no useful information |
-q, --quiet, --silent |
do not print `checking...' messages |
Not very useful. Output to screen is only a few lines anyway. |
--cache-file=FILE |
cache test results in FILE. [disabled] |
No function |
-C, --config-cach |
alias for `--cache-file=config.cache' |
No function |
-n, --no-create |
do not create output files |
Used for testing if other switches produce error - without writing anything to the disk |
--srcdir=DIR |
find the sources in DIR. [configure dir or `..'] |
DIR is a directory path. Editor recommends having the current directory being the motion installation directory and not using this switch. Then it defaults to the same directory as where the configure script is which is the current directory. |
Installation directories: |
||
--prefix=PREFIX |
install architecture-independent files in PREFIX |
The default /usr/local means that the executable
binary "motion" is installed in /usr/local/bin, the manual
page in /usr/local/man/man1, the document files in /usr/local/docs/motion-version,
configuration file in /usr/local/etc, and some examples config files
in /usr/local/examples/motion-version |
--exec-prefix=EPREFIX |
install architecture-dependent files in EPREFIX [PREFIX] |
If you set this it only defines an alternative
installation directory for the executable binary. |
--bindir=DIR |
user executables [EPREFIX/bin] |
With this option you can control exactly in which directory the executable binary is installed. The previous option automatically adds the bin directory. Here you are in fill control. |
--sbindir=DIR |
System admin executables [EPREFIX/sbin] |
Not used by motion. Ignore it. |
--libexecdir=DIR |
program executables [EPREFIX/libexec] |
Not used by motion. Ignore it. |
--datadir=DIR |
read-only architecture-independent data [PREFIX/share] |
Not used by motion. Ignore it. |
--sysconfdir=DIR |
read-only single-machine data [PREFIX/etc] |
This is where motion both installs the default
configuration file and also where it later searches for it.
Editor recommends leaving this at default. Be careful if you run "make install" again. This will overwrite the motion.conf file that you have edited and experimented with for hours. Make sure to keep a copy in a safe place. Alternatively, copy the working file to the motion base install directory. Then make install will simply copy the same file back again. |
--sharedstatedir=DIR |
modifiable architecture-independent data [PREFIX/com] |
Not used by motion. Ignore it. |
--localstatedir=DIR |
modifiable single-machine data [PREFIX/var] |
Not used by motion. Ignore it. |
--libdir=DIR |
object code libraries [EPREFIX/lib] |
Not used by motion. Ignore it. |
--includedir=DIR |
C header files [PREFIX/include] |
Not used by motion. Ignore it. |
--oldincludedir=DIR |
C header files for non-gcc [/usr/include] |
Not used by motion. Ignore it. |
--infodir=DIR |
info documentation [PREFIX/info] |
Not used by motion. Ignore it. |
--mandir=DIR |
man documentation [PREFIX/man] |
Editor recommends the default. |
Optional Packages: |
||
--with-libavcodec=DIR |
Specify the path for libavcodec (part of ffmpeg) |
DIR is the location of the libavcodec directory
in the FFmpeg package. |
--with-mysql=DIR |
normally, configure will scan all possible default installation paths for mysql. When its fail, use this command to tell configure where mysql installation root directory is. |
DIR is the installation directory of mysql. E.g.
/usr/local/mysql |
--without-mysql |
Do not compile with MySQL support |
Use this if you do not want to include MySQL support
in the package. |
--with-pgsql=DIR |
Include PostgreSQL support. DIR is the PostgreSQL
base install directory, defaults to /usr/local/pgsql. |
Default is that make searches in the normal installation
directories of most distributions. |
--without-pgsql |
Do not compile with PostgresSQL support |
Use this if you do not want to include PostgresSQL
support in the package. |
Environment values. |
||
CC |
C compiler command |
Normally you should not have to worry about any of these. |
CFLAGS |
C compiler flags |
|
LDFLAGS |
linker flags, e.g. -L<lib dir> if you have libraries in a nonstandard directory <lib dir> |
|
CPPFLAGS |
C/C++ preprocessor flags, e.g. -I<include dir> if you have headers in a nonstandard directory <include dir> |
|
CPP |
C preprocessor |
|
Not much to say about this. When you run make, all the C-source files are
automatically compiled and linked. Just look out for error messages.
Make
uses a file called "Makefile" which is generated by the "configure"
script you just ran. If you have special needs you can manually edit this file.
Next time you run configure a new Makefile will be generated and your changes
are lost.
If you have run make before, you should run a "make clean" before
running make again. This cleans out all the output files that were generated
the previous time you ran make. On other words:
First time you build motion
run configure, make, make install. If you need to build it again (to run with
different configure options) run configure, make clean, make, make install.
"Make install" simply copies all the nice files that were generated
during the compilation/linking that make did.
In version 3.0.3 the following
is done by make install.
Makes the directories (if they do not already exist): /usr/local/bin, usr/local/man/man1, /usr/local/etc, /usr/local/doc/motion-3.0.3, /usr/local/doc/motion-3.0.3, and /usr/local/examples/motion-3.0.3.
Copies the following files from the base motion directory (assuming the default PREFIX /usr/local was used when running configure - otherwise adjust to the actuals you chose)
Note that the any existing files are overwritten. Pay attention to your configuration file motion.conf. You may not want this overwritten. Keep a copy in a safe place before you run "make install"
From the motion base installation directory you simply run make uninstall
And delete the base installation directory in /usr/local and any link pointing to it. If you have forgotten where you installed it or someone else did it for you, simply search for the files and directories starting with motion. If the filenames and the directories match the names described in the "Make Install" section of this document, you can safely delete them.
The make command can be run with severel options. make, make install and make uninstall has already been described above.
make clean deletes all the binary files (object files) and the motion
binary generated by make. It also deletes temporary files and any jpg files
that motion has saved in the motion source directory.
make distclean
deletes the files: config.status, config.log, config.cache, Makefile, and motion.spec.
make
updateguide fetches a frech new copy of this guide and place it in your
motion source directory. Note that the pictures are not downloaded.
make
dist performs make clean, make distclean and make updateguide in one single
operation.
You have the following sources of information:
This document (you are
lucky to have found it).
The author of the program has written a description
of the technology behind motion.
The man page. After installation simply
write man motion
The default motion.conf file that comes with the package.
Misc.
document that comes with the package gives a few hints. When this is written
the FAQ describes the wrong information about where motion searches for the
motion.conf file.
Input devices: Here we are thinking about the cameras.
Motion supports
video input from two kinds of sources.
Standard video4linux devices (e.g. /dev/video0). Motion has no drivers for
cameras. Installing the camera itself is outside the scope of this document.
But here are some nice links.
Network cameras (which are actually a camera with a built in web server that can be connected directory to you network.
Motion is invoked from the command line. It has no GUI.
A few important definitions.
SYNOPSIS
motion [ -BCDhlmNpQw] [ -A ipnr] [ -a seconds] [ -c changes] [ -d device]
[ -E command]
[ -F file] [ -f nr] [ -G seconds] [ -g seconds] [ -i input]
[ -L noise] [ -M address] [ -n norm]
[ -O command] [ -P device] [ -q quality] [ -S nr] [ -s widthxheight] [ -t target dir]
[ -u user:pass ]
[ -U webcam_path ] [ -V device]
Option |
Description |
Editors comment |
-A |
IP address or URL for Network Camera (e.g. an Axis network camera) |
Only relevant for network cameras. |
-a seconds |
time between two automated snapshots, valid range: 0 to thousands, default: 0 |
The default value of 0 means that the feature is disabled. |
-B |
Encode all jpg images to mpeg after a event using mpeg_encode |
An event is defined as a series of motion images taken within a short timeframe. E.g. a person walking through the room is an event that may have caused 10 single jpg images to be stored. This option make motion (using mpeg_encode) to merge the individual jpg images into a small mpeg "film" showing the event. |
-C |
Output changes count for every frame, usable for tuning |
This feature writes the detected number of changed
pixels (after noise filtering) to the console. Motions outputs the
numbers for all threads continuously for every frame read from the
video device. The output format is "changes: number_of_changes".
The number is an expression
of how many pixels that changed and how much. The higher a value,
the more motion This feature does not work
when in daemon mode! |
-c changes |
threshold for detecting a change, Valid range: 1 to thousands, default: 1500. |
Use the -C switch to experiment to find the right value. If you do not get small movement detected (see the mouse on the kitchen floor) lower the value. If motion detects too many birds or moving trees, increase the number. |
-D |
Daemonize |
This means that motion is started as background
process(es) and you return to the command prompt right away. |
-d device |
video4linux capture device, default: /dev/video0 |
The syntax for the value is /dev/devicename where device name in Linux is normally video0, video1, video2 etc. The actual device number is set by the device driver. See the documentation for this. |
-E command |
Execute 'command' when detecting motion. |
The command is executed at the beginning of the
event before the images are stored. |
-F file |
pgm image to use as a mask for filtering motion. This file must have the same size as you have set for the video4linux device. |
Full path of the PGM (portable gray map) mask
file. |
-f number |
Maximum number of frames per second. Valid range: 0 to limit of camera, default: none |
Maximum number of picture frames per second that motion
takes when detecting movement. Default
is none which means that it takes as many as possible. |
-G seconds |
Minimum gap between two shots in seconds. 0 to thousands, default: 0 |
It is the minimum time from an image is saved till an image is saved again. |
-g seconds |
minimum gap between events, Valid range: 1 to thousands, default 60 |
An event is defined as a series of motion images taken within a short timeframe. E.g. a person walking through the room is an event that may have caused 10 single jpg images to be stored. This option defines how long a pause between detected motions that is needed to be defined as a new event. |
-h |
Display an short text with all command line functions. |
Display a short 1 line help text for each command option. Motion terminates right after having shown the text. If Motion already runs it is no problem. You can invoke it with the -h option without any impact on the running processes. |
-i input |
input channel to use. Valid range: depends on video capture card, default: not set |
If you have a video capture card you can define the channel to tune to using this option. If you are using a USB device, network camera or a capture card without tuner you can ignore this. |
-L noise |
Noise level, all changes smaller than this level will be considered noise. Valid range: 1 to 255, default: 32 |
This is different from the threshold parameter. This is changes at pixel level. The purpose is to eliminate the changes generated by electric noise in the camera. Especially in complete darkness you can see the noise as small grey dots that come randomly in the picture. This noise can create false motion detection. What this parameter means is that the intensity of a pixel must change more than +/- the noise threshold parameter to be counted. |
-l |
Do not locate and mark motion on output pictures |
The mark is in the form of a rectangle on the saved images so that you can easily see what it was that was moving in the picture. It is a matter of taste if you want this. |
-M address |
Send a mail to 'address' when detecting motion. |
Uses the standard UNIX 'mail' program which is part of the 'sendmail' package. |
-m |
Output 'motion' images |
Motion images shows the motion content of the pictures. This is good for tuning and testing but probably not very interesting for the general public. Default is not to store motion images. Motion pictures have an m at the end of the filename. |
-N |
Don't output normal images |
Normal image is an image that is stored when motion is detected. It is the same image that was taken by the camera. I.e. not a motion image as defined above. Default is that normal images are stored. This option turns the feature OFF. |
-n norm |
norm to use (pal/pal-nc/ntsc/secam), default: pal |
Only relevant for capture cards. This sets the video coding standard for the card. In most of western Europe PAL is used. In France and some eastern European countries SECAM is used. In the Americas and Japan NTSC is used. |
-O command |
Execute 'command' when an image is saved. The name of the image will be given as argument. |
The command can be a simple UNIX command, a bash script, a perl program, a real binary program, anything. The program is given the stored image filename as a parameter. |
-P device |
video4linux video loopback input for normal images. If a dash '-' is given as device, motion will try to use /proc/video/vloopback/vloopbacks to find a free pipe on its own. default: not set |
See the video4linux loopback
device web site for more information about video loopback |
-p |
Output ppm images instead of jpeg. This will reduce CPU load but disk I/O will increase a lot. |
|
-Q |
Don't sound the warning beep when detecting motion. (This doesn't change anything in daemon mode, there never is a beep there) |
|
-q quality |
JPEG image quality, Valid range: 0-100,default: 75. |
100 means hardly compressed. A small number means a much smaller file size but also a less nice quality image to look at. 50 is a good compromise for most. |
-S number |
Send a SMS to number using sms_client when detecting motion. |
Not a feature that has received much attention recently. If you live in GSM land you are probably better off using the email to SMS gateway that most GSM providers have using your mail client. For more information se the sms_client home page. |
-s widthxheight |
Picture size, Valid range: Camera dependent, default: 352x288 |
Motion actually set the size of the image coming from the video4linux device. The selected size must be supported by the device. For some device drivers like pwc (driver for Philips USB cameras) setting the size to a non-standard value makes the driver create an image of the nearest smaller size and create a gray band around the image to fit the size given by motion. Note that it is the driver and not motion that generates the gray band. Motion will try to detect motion in the entire image including the gray band. |
-t target-dir |
destination for snapshots |
This is the target directory for all snapshots, motion images and normal images. The default is the current working directory (current working directory of the terminal from which motion was started). You will normally always want to specify this parameter either as a command line option or in the config file. |
-U url|IP_addr |
Webcam path |
URL for a net camera. |
-u user:pass |
For password-protected network cameras, use this option for the HTTP 1.1 Basic authentication mechanism. default: No authentication |
Only relevant for network cameras. |
-V device |
Output device name |
Device name that motion uses to generate output. See the video4linux loopback device web site for more information about video loopback. Note: This is not the capturing device name. To set the capturing device use the -d option. |
-w |
Activate light switch filter. With this option on motion will not classify sudden light differences as a motion (not 100% fail proof!) |
Default (switch not set) is off. |
These are the options that can be used in the config file. They are
overridden by the command line!
All number values are integer numbers (no
decimals allowed). Boolean options can be yes or no (values "1", "yes"
and "on" all means true and any other value means false).
Option |
Description |
Editors comment |
adjust_rate yes|no |
Try to make the frame rate of the created mpegs as normal as possible. Normal means round 25 frames per second. Allowed values: yes, no. Default: no |
Adjust the number of frames for an mpeg movie to get almost 25 frames per second. |
always_changes yes|no |
Always display the differences between the captured frame and the reference frame. This can come in handy while tuning your setup. Default: no |
This feature writes the detected number of changed
pixels (after noise filtering) to the console. Motions outputs the
numbers for all threads continuously for every frame read from the
video device. The output format is "changes: number_of_changes".
The number is an expression
of how many pixels that changed and how much. The higher a value,
the more motion This feature does not work
when in daemon mode! |
auto_brightness yes|no |
Motion will try to adjust the brightness of the video device if the images captured are to dark or to light. This option will be most useful for video devices like web cams, which sometimes don't have such an option in hardware. Default: no |
With this option enabled motion will try to regulate the brightness of a video device. If your video device already does this for you this option might cause oscillations. Editor recommends to experiment for best result. |
daemon yes|no |
Start motion in daemon mode and release terminal. Default: no |
(Important! In version 2.6.3 and earlier this
option was misspelled deamon). Wonder about the word and its spelling.
Look here! |
drawtext_changes yes|no |
Turns the last two digits (counting each individual frame) after the timestamp osd on/off. Default: no |
By setting this option to 'yes' the number of pixels that changed compared to the reference frame is displayed over the date/time stamp in the lower right of the pictures. This is good for calibration and test. Maybe not so interesting for a greater public. Set it to your personal taste. |
drawtext_shots yes|no |
User defined text overlayed on each frame. Use A-Z, 0-9 - : and '_' as space. Default: none |
Setting the option 'drawtext_shots' to on adds the frame number as '- two digits' after the time stamp. If you save pictures faster than once per second or you generate mpegs with ffmpeg - it can be quite nice to identify each picture frame by a unique time stamp. Set it to your personal taste |
drawtext_user TEXT |
User defined text overlayed on each frame. Use A-Z, 0-9 - : and '_' as space. Default: none |
User defined text is displayed in the lower left corner of the pictures. If the option is not defined no text is displayed at this position. The user defined text can be the english alphabet - UPPERCASE letters only, the digits 0-9 and the characters "-" and ":". Use the underscore "_" as a space. |
execute command |
External command to be executed when detecting motion. Default: none |
Do not write "none" if you do not want to execute commands. Simply do not include the option in the file or comment it out by placing a "#" as the first character on the line before the execute command. |
ffmpeg_cap_new yes|no |
Use ffmpegs libavcodec to encode mpeg movies in realtime. Default = no |
To use this feature you need to install the FFmpeg
Streaming Multimedia System |
ffmpeg_timelaps yes|no |
Use ffmpegs libavcodec to encode a timelaps movie. Default = no |
The ffmpeg_timelaps function takes pictures at a fixed rate of one per minute. This cannot be configured. To use this feature you need to install the FFmpeg Streaming Multimedia System. See ffmpeg section later in this document. |
ffmpeg_bps bps |
Bitrate of mpegs produced by ffmpeg. Default: 400000 (400Kbps) |
Experiment to get the desired quality. The better quality the bigger files. See ffmpeg section later in this document. |
framerate number |
Maximum number of frames that are saved per second.
Valid range: 2-100. Default: 100 (almost no limit). |
Note. Motion will stop storing pictures if the
framerate is set to less than 2. |
frequency value |
The frequency to set the tuner to (kHz). Valid range: per tuner spec, default: 0 (Don't set it) |
This option is on relevant if you have a TV tuner card where you can select the tuner frequency. Your tuner card must support this feature. |
gap seconds |
The minimum gap between two events in seconds. Default: 60 |
An event is defined as a series of motion images
taken within a short timeframe. E.g. a person walking through the
room is an event that may have caused 10 single jpg images to be
stored. This option defines how long a pause between detected motions
that is needed to be defined as a new event. |
height pixels |
The height of each frame. Valid range: Camera dependent, default: 288 |
The height of the image in pixels. Motion does
not scale so should be set to the actual size of the v4l device.
In case of a net camera motion sets the height to the height of
the first image read. |
input number |
Select the input of the video device. Valid range: depends on video capture card, default: 8 |
This parameter is really used only with video capture
cards that has more than one input. |
jpg_cleanup yes|no |
Remove all jpeg images after making a mpeg movie of them. Default: no |
When this option is set to yes jpg images will be deleted after creation of an mpeg movie. If you want to see the individual jpg images you should choose no. Otherwise set it to yes and keep your disk space more under control. |
lightswitch yes|no |
Activate light switch filter. With this option on motion will not classify sudden light differences as a motion (not 100% fail proof!). Default: no |
Editors recommendation. Experiment to see what works best for your application. |
locate yes|no |
Locate and draw a box around the moving object. Default: yes |
|
low_cpu yes|no |
When this option is enabled motion will grab only one frame per second while not detecting motion. Default: no |
This is smart for running a server that also does other tasks such as running Apache, MySQL etc. Motion grabs one frame per seconds until it detects motion. Then it speeds up to normal speed and take pictures as set by the option "framerate". |
mail address |
Address to send an e-mail to when detecting motion Default: none |
Address in the normal form name@domain.name. An e-mail is sent for each event. Not each picture. |
mask_file file |
PGM file to use as a sensitivity mask. This picture MUST have the same width and height as the frames being captured and be in binary format. Default: not set. |
Full path of the PGM (portable gray map) mask
file (binary format). |
max_mpeg_time seconds |
The maximum length of an mpeg movie. Default: 3600 seconds (one hour). Set this to zero for unlimited length. |
|
mpeg_encode yes|no |
Use the Berkeley mpeg encoder 'mpeg_encode' to make movies of the events Default: no |
For more information here is a link to the Berkeley
mpeg encoder. |
mpeg_encode_bin path |
Specify the path to the mpeg_encoder. Default is /usr/local/bin/mpeg_encode |
This option is not included in the default motion.conf file. It specifies the path to the Berkely mpeg_encode executable binary file. The default value is /usr/local/bin/mpeg_encode. This is normally where the encoder gets installed if you build from source. But if you install a binary RPM the encoder will most likely end up in /usr/bin/mpeg_encode. In this case set this option. |
minimum_gap seconds |
The minimum time between two shots in seconds. Valid range: 0 to thousands, default: 0 (no minimum) |
This is the minimum gap between the storing pictures while detecting motion. The value zero means that pictures can be stored almost at the framerate of the camera. |
motion_video_pipe devicename|- |
The video4linux video loopback input device for motion images. If a particular pipe is to be used then use the device filename of this pipe, if a dash '-' is given motion will use /proc/video/vloopback/vloopbacks to locate a free pipe. Default: not set |
Using this you can view the results in real time.
E.g. by using the program camstream.
(Please confirm). The
difference between this option and the video-pipe option is that
this option shows the motion version of the images instead of the
normal images. |
netcam_url URL |
Specify an url to a downloadable jpeg file to use as input device. Such as an AXIS 2100 network camera. Default: not set. |
Example: http://www.gate.com/pe1rxq/jeroen.jpg |
netcam_userpass user:pass |
For network cameras protected by username and password, use this option for HTTP 1.1 Basic authentication. The string is specified as username:password. Default: No authentication |
Only relevant for network cameras. |
night_compensate yes|no |
When this option is set the noise threshold will be lowered if the picture is to dark. This will improve the sensitivity in dark places. However it might also increase the number of false alarms since most cameras also compensate for this with their AGC which will increase noise. Default: yes |
Editors recommends to experiment for best result as this depends heavily on the camera and light conditions. |
noise_level level |
The noise level is used as a threshold for distinguishing between noise and motion. Valid range: 1 to 255, default: 32 |
This is different from the threshold parameter. This is changes at pixel level. The purpose is to eliminate the changes generated by electric noise in the camera. Especially in complete darkness you can see the noise as small grey dots that come randomly in the picture. This noise can create false motion detection. What this parameter means is that the intensity of a pixel must change more than +/- the noise threshold parameter to be counted. |
norm 0|1|2|3 |
Select the norm of the video device. Values: 0 (PAL), 1 (NTSC), 2 (SECAM), 3 (PAL NC no colour). Default: 0 (PAL) |
This value is only used for capture cards using the BTTV driver. |
oldlayout yes|no |
If this option is set to yes motion will use
the old style filenames for saving images: 'No-YYYYMMDDHHMMSS-Fm'
No is the event number, Fm the frame number for that second. As
default motion will create directories for years, months, days and
so on. |
Editors notes. If you do not choose this option motion will generate a deep directory structure of year/month/day/hour/minute. This is nice for a simple web interface but it becomes a little more complicated to write an automatic script that keeps the last 100 pictures available and deletes the rest. If you want to delete any picture older than 2 days this is easier with the new layout. Choose the one that fits your need best. |
onsave command |
Execute 'command' when an image is saved. The name of the image will be given as argument. Default: not set. |
Full path name of the program/script. |
onmpeg command |
Execute 'command' when an mpeg movie is generated. The name of the movie will be given as argument. Default: not set. |
Full path name of the program/script. |
output_motion yes|no |
Output pictures with only the moving object. Default: no |
Motion images shows the motion content of the
pictures. This is good for tuning and testing but probably not very
interesting for the general public. Default is not to store motion
images. Motion pictures have an "m" at the end of the
filename. E.g. for the old directory layout the name can be 01-20020424232936-00m.jpg. |
output_normal yes|no |
Output 'normal' pictures. Default: yes |
Normal image is an image that is stored when motion is detected. It is the same image that was taken by the camera. I.e. not a motion image as defined above. Default is that normal images are stored. |
post_capture number |
Specifies the number of frames to be captured after motion has been detected. Valid range: 0 to thousands, default=0. |
The purpose of this is mainly to create smooth
video clips each time motion is detected. Use it to you personal
taste (and disk space). |
ppm yes|no |
Output ppm images instead of jpeg. This uses less CPU time, but causes a LOT of hard disk I/O, it is generally slower than jpeg. Default: no |
Editors recommendation is to always use jpg except if you have a specific need to store high quality pictures without any quality loss. For web cameras you should always choose jpg. |
quality value |
The quality for the jpeg images. Valid range: 1-100,default: 75 |
100 means hardly compressed. A small number means
a much smaller file size but also a less nice quality image to look
at. 50 is a good compromise for most. |
quiet yes|no |
Be quiet, don't output beeps when detecting motion. Default: no |
|
realconfig filename |
With this option set to yes motion images will contain the actual difference in the frames. Normally the pictures will show the moving parts of the newest frame. Default: no |
In version up to 2.6.3 you would use this option
to have motion control more than one camera. |
realmotion yes|no |
With this option set to yes motion images will contain the actual difference in the frames. Normally these pictures will show the moving parts of the newest frame. Default: no |
This is another useful tuning option. This option
only works in combination with the "output_motion" option. |
snapshots seconds |
Make automated snapshots every N seconds. Valid range: 0 to thousands, default: 0 (No snapshots) |
The snapshots are stored in the target directory with the "-snapshot" appended to the body of the filename. E.g for the oldlayout the filename can be 01-20020425003030-snapshot.jpg |
roundrobing_frames number |
Specifies the number of frames to capture before switching inputs, this way also slow switching (e.g. every second) is possible. Default: 1 |
Roundrobing feature is described in a section later in this document. |
roundrobing_skip number |
Specifies the number of frames to skip after a switch. (1 of you are feeling lucky, 2 if you want to be safe). Default: 1 |
Roundrobing feature is described in a section later in this document |
snapshot_overwrite yes|no |
All snapshots are named 'lastsnap.[jpg|ppm]' instead of time coded names. Thus every new snapshot overwrites any existing ones. Default: no |
Note that the default motion.conf file says that the filename is snapshot.[jpg/ppm]. This is wrong. The filename is lastsnap.[jpg/ppm] when using this feature. |
sms number |
Number to send an SMS to with sms_client. Default: none |
Not a feature that has received much attention recently. If you live in GSM land you are probably better off using the e-mail to SMS gateway that most GSM providers have using your mail client. For more information se the sms_client home page. |
switchfilter yes|no |
Turns the switch filter on or off. The filter can distinguish between most switching noise and real motion. With this you can even set roundrobing_skip to 1 without generating much false detection. Default: no. |
|
target_dir directory_path |
Target directory for pictures. Default: current working directory |
This is the target directory for all snapshots, motion images and normal images. The default is the current working directory (current working directory of the terminal from which motion was started). You will normally always want to specify this parameter either as a command line option or in the config file. Use an absolute directory path (not relative) if you want to use mpeg_encode. |
thread filename |
Thread option. With this a separate config file can be specified to be used for a new separate thread. |
This is used when you have more than more camera/device.
From version 2.9.x this replaces the realconfig option. |
threshold value |
Threshold for declaring motion. Valid range: 1 to thousands, default: 1500. |
Use the -C command line option or the always_changes config file option to experiment to find the right threshold value. If you do not get small movement detected (see the mouse on the kitchen floor) lower the value. If motion detects too many birds or moving trees, increase the number. Practical values would be from a few hundred to 2000 indoors and 1000-10000 outdoors. |
videodevice device_name |
The videodevice to be used for capturing. Default: /dev/video0 |
This is the video4linux device name. |
video_pipe device_name|- |
The video4linux video loopback input device for normal images. If a particular pipe is to be used then use the device filename of this pipe, if a dash '-' is given motion will use /proc/video/vloopback/vloopbacks to locate a free pipe. Default: not set |
Using this you can view the results in real time.
E.g. by using the program camstream.. The
difference between this option and the video-pipe option is that
this option shows the normal version of the images instead of the
motion images. |
webcam_port port_no |
TCP port on which motion will listen for incoming connects with its http server. Default is 0 which is disabled. |
Webcam feature is described in a section later in this document |
webcam_quality level |
Quality setting for the jpeg files transferred over this connection (usually very low). Default is 30. |
Webcam feature is described in a section later in this document |
webcam_motion yes|no |
If set to yes only send images with motion over the webcam connection, else send frames continuously. Default is no. |
Webcam feature is described in a section later in this document |
webcam_maxrate rate |
Limit the framerate of the webcam. Default is 100. |
Webcam feature is described in a section later in this document |
width pixels |
The width of each frame. Valid range: Camera dependent, default: 352 |
Motion does not scale so should be set to the
actual size of the v4l device. In case of a net camera motion sets
the height to the height of the first image read. |
MySQL CONFIG FILE OPTIONS |
||
mysql_db |
|
Name of the MySQL database |
mysql_host |
|
IP address or domain name for the MySQL server. Use "localhost" if motion and MySQL runs on the same server. |
mysql_user |
|
The MySQL user name. |
mysql_password |
|
The MySQL password. |
PostgresSQL CONFIG FILE OPTIONS |
||
pgsql_db |
|
Name of the PostgresSQL database |
pgsql_host |
|
IP address or domain name for the PostgresSQL server. Use "localhost" if motion and PostgresSQL runs on the same server. |
pgsql_user |
|
The PostgresSQL user name |
pgsql_password |
|
The PostgresSQL password |
pgsql_port |
Default is 5432 |
The PostgresSQL server port number |
TRACKING CONFIG FILE OPTIONS |
||
track_port |
This is the serial port to which the stepper motor interface is connected. |
|
track_motorx |
The motor number that is used for controlling the x-axis. |
|
track_maxx |
The maximum position for servo x. |
|
track_iomojo_id |
Use this option if you have an iomojo smilecam connected to the serial port instead of a general stepper motor controller. Default: -1 (Use the stepper motor interface) |
|
A signal can be sent from the command line by typing e.g. kill -s SIGHUP
pid, where the last parameter is the process ID which you get by typing
ps -ef | grep motion. The PID is the first on the list which is the parent
process for the threads. (If you use a version of motion 2.6.3 or earlier, you
must kill each individual process and start motion again).
Motion responds to the following signals:
Signal |
Description |
Editors comment |
SIGALRM |
Motion will generate a snapshot. |
|
SIGHUP |
The config file will be reread. |
This is a very useful signal when you experiment with settings in the config file. |
SIGTERM |
If needed motion will create an mpeg file of the last event and exit |
|
SIGUSR1 |
Motion will create an mpeg file of the current event. |
|
To use this feature you need to install the Berkeley
mpeg_encode program.
The program is pretty old (1995) and there has been
some problems with compiling the source code. There is a guy doing an exciting
project called AMIDE.
This project includes the mpeg_encode program and it seems that the author of
AMIDE has polished the old mpeg_encode a little bit calling it 1.5b.2. The author
has placed 2 versions. A binary only RPM for the Intel 386 platform and two
RPMs with full source. I installed just the binary RPM from the AMIDE site and
it worked fine. The binary RPM contains only two files: mpeg_encode itself which
it installs in /usr/bin and a manual page. Motion looks for the mpeg_encode
in the directory /usr/local/bin. So either move the binary to this place, or
place a link to it OR use the "secret" config file option mpeg_encode_bin.
Ie. to enable the feature you need the following entries in the motion.conf
file.
# Use the Berkeley mpeg encoder 'mpeg_encode'
# Default: no
mpeg_encode
yes
mpeg_encode_bin /usr/bin/mpeg_encode
The last line is not included in the default config file. The default value is '/usr/local/bin/mpeg_encode' so if this is where your mpeg_encode is, you do not need to add it to your config file.
Your target_dir option should be an absolute path (starting with /) when using mpeg_encode.
The feature itself works like this:
Everytime motion detects motion a jpg picture is stored. This happens at the framerate you have specified with the 'framerate' option (or at the interval set by the 'minimum_gap' option if different from zero). When the event is over (time defined by the 'gap' option) motion generates a small mpg film using mpeg_encode. This is important to notice when you test the feature the first time. You will have to wait the period defined by 'gap' before you see the mpg file on your disk. If you have used a small framerate or used the minimum_gap option the film is going to be over in a split second. For this feature to be useful you should let motion store pictures almost real time. To generate better films you can play with options like 'post_capture' which will take extra picture after a motion is detected to create better floating films and 'adjust_rate' which will try to generate a 25 fps film. To avoid your harddisk from getting full because a bird is hopping around on the lawn, there are two parameters you can use. 'jpg_cleanup' will delete all the jpg files once the mpeg has been generated. 'max_mpeg_time' limits the duration of an mpeg film to the number of seconds you specify.
The ffmpeg option can generate mpeg films very fast and "on the fly". This means that the mpeg film is growing each time motion is detected. With the Berkeley mpeg_encode feature the film is generated based on the saved jpg pictures. With ffmpeg the film is generated directly by motion. Note that when you build motion with ffmpeg (configure using --with-libavcodec=DIR) DIR must be the path to the directory containing libavcodec.a. If you install ffmpeg in /usr/local/ffmpeg then the directory is /usr/local/ffmpeg/libavcodec.
The ffmpeg_cap_new option generates a new film at the beginning of each new 'event' and appends to the film for each motion detected within the same event. The current 'event' ends when the time defined by the 'gap' option has passed with no motion detected. At the next detection of motion a new mpeg film is started.
The
ffmpeg_timelaps generates a picture at a constant framerate of 1 frame
per minute. Gives
your viewer the chance to watch the day pass by. Nice effect to film flowers
etc closeup during the day. Note that this rate cannot be configured. Options
like frame_rate, snapshot, gap etc has no impact on the ffmpeg timelaps function.
There is an option ffmpeg_bps. This sets the
bits per seconds of the generated film. The higher value - the better quality
- the bigger file. Experiment to get the desired quality/file sizes.
If you set any of the options that lowers the frame rate to less than 2, Motion will use the value 2. Otherwise ffmpeg will crash with floating point error.
If you want to use this feature you can read about the FFmpeg Streaming Multimedia System
As of mid June 2002 the files at the ffmpeg site
are not available. There is no clue to why they have been
removed on the ffmpeg website. Maybe it has been removed because it was too
buggy.There are still a lot of activities on the project CVS so hopefully there
will be a new release soon. Motion has been developed to work with ffmpeg version
0.4.5!
The version 0.4.5 that was removed from the files
area at Sourceforge is still available on the URL below but there is no guarantee
for how long. The URL is
http://ffmpeg.sourceforge.net/ffmpeg-0.4.5.tar.gz
Here are more alternatives - one of them must work.
http://prdownloads.sourceforge.net/ffmpeg/ffmpeg-0.4.5.tar.gz
http://telia.dl.sourceforge.net/sourceforge/ffmpeg/ffmpeg-0.4.5.tar.gz
http://www.kehuelga.org/video/dvd/appl/ffmpeg-0.4.5.tar.gz
http://source.hotr.com:8080/tv/ffmpeg-0.4.5.tar.gz
http://davedina.apestaart.org/download/ext/SOURCES/ffmpeg-0.4.5.tar.gz
http://home.pages.at/bashy/download/ffmpeg-0.4.5.tar.gz
It seems that the current CVS version of ffmpeg does not work well with motion. The bitrate is very low and the bitrate value in motion.conf seems to be ignored. If you want to experiement here is the method for downloading the entire ffmpeg package from CVS:
You must have CVS installed!
You change directory to the directory in
which you want ffmpeg sources installed. For example to create the ffmpeg tree
in /usr/local
cd /usr/local
First you need to login anonymously
In a terminal window you write the
command.
cvs -d:pserver:anonymous@cvs.ffmpeg.sourceforge.net:/cvsroot/ffmpeg login
It then askes for a password. Just press <enter>.
Then you download the entire ffmpeg tree with the command
cvs -z3 -d:pserver:anonymous@cvs.ffmpeg.sourceforge.net:/cvsroot/ffmpeg co ffmpeg
It then downloads the whole thing in your current directory under a directory called ffmpeg, and then it is the normal installation procedure.
In versions up to 2.6.3 the mask file must be in the ppm format (portable
pixel map). Note that you must choose the BINARY format.
From version 2.9.9 the feature is changed
to use a pgm format mask file (portable gray map). Note that you must
choose the BINARY format.
The feature is simple. Create an image of exact
the same size as the ones you get from your video device (camera). Make a purely
white picture and paint the areas that you want to mask out black. You can also
make gray areas where you want to lower the sensitivity to motion. Normally
you will stick to pure black and white.
Note that the mask file option masks
off the detection of motion. The entire picture is still shown on the picture.
This means that you cannot use the feature to mask off an area that you do not
want people to see.
Below are an example of a webcam picture and a mask file to prevent the detection cars in the street.
Normal picture. Notice the street is visible through the hedge.
Mask file (converted to png format so it can be shown by your web browser)
You can use the MySQL database to register each file that is stored by motion. What is stored is the
filename (full path), and the time.
You need to generate a new database with
a name of your own choice. You must enter this name in the config file (mysql_db
option). Select the new database in MySQL and create a new table "security"
with the following fields:
You can create the table using the following SQL statement.
CREATE TABLE security (filename char(60) not null, minute int, hour int, day int, month int, year int, type int);
Remember to update grant table to give access to the mysql username you choose
for motion.
Note that motion does not store the seconds so you have have
many files saved with the same time stamp. To get the exact time you will need
to extract that from the file name.
If you are having trouble when installing motion with MySQL support you may have the same problem as the editor of this document had on his first Linux machine.
Versions from 2.9.9 works with no problems when mysql installed as a Red Hat RPM where
mysql is installed in the standard directories
Data files in /var/lib/mysql
Binary
program files in /usr/bin
Libraries in /usr/lib/mysql
Daemon in /usr/sbin
Misc
shared stuff in /usr/share/mysql
Headers in /usr/include/mysql
Manual
pages in /usr/man/man1
When installing the generic binary from www.mysql.com the directory structure
is different.
MySQL recommends not compiling MySQL with gcc version 2.96.
And this is what Red Hat ships with. I assume that MySQL similar to Apache can
be configured to different layouts. The generic i386 binary that they have on
their site has been made with everything under one directory. This makes sense
when you download and untar one package without compiling.
The structure of mysql is then (assuming installing undet /usr/local).
Base
dir is /usr/local/mysql
Data files in /usr/local/mysql/data
Binary program
files in /usr/local/mysql/bin/
Libraries in /usr/local/mysql/lib
Daemon
in /usr/local/mysql/bin/
Misc shared stuff in /usr/local/mysql/share
Headers
in /usr/local/mysql/include
Manual pages in /usr/local/mysql/man (though
I believe the install script does copy them to a standard location)
The workaround for 3.0.3 is:
If you have an RPM based distro I would recommend using the RPM from mysql if you want to replace the mysql that came with your distribution to the latest and greatest. This way you do not have to worry about the work-around above. See also next section about PostgreSQL
It would be too much to go into detail about how to setup and use MySQL. After all this is a guide about Motion. However here are some hints and links.
Setting
Up a MySQL Based Website A beginners guide from Linux Planet.
Webmonkey
PHP/MySQL tutorial Entertaining and easy to read.
The phpMyAdmin
homepage. The best and simplest tool to use MySQL (editors opinion). Requires
Apache/PHP.
The
Soothingly Seamless Setup of Apache, SSL, MySQL, and PHP. Another good beginners
tutorial
Same/similar as for MySQL above.
There are the same potential installation as for MySQL. The workaround is
the same.
Motion is looking for a header file called xxx/postgresql/libpq-fe.h
where xxx is the path that gcc is searching for headers. Often PostgreSQL header
files are installed either in a directory called pgsql or directly in /usr/include.
You
can either change the motion source or create a symbolic link. Editor recommends
the link method because then you do not have to think about it when you try
new versions of Motion.
Motion has a mini (very very mini) http server built in. Each thread can have its own webserver. If you enable the webcam server (option webcam_port to a number different from 0) and you have threads you must make sure to include webcam_port to different ports or zero (disable) in each thread config file. Otherwise motion will crash because each webcam server will use the setting from the motion.conf file and try to bind to the same port.
These are the special
webcam parameters.
The webserver generates a stream in "multipart jpeg" format. You cannot watch the stream with most browsers. Editor has tried Internet Explorer 6, Netscape 6.2 (windows) and Konquerer. Only Netscape on Linux can show the stream. For public viewing this is not very useful. There exists a java applet called Cambozola. Same tool is also used in the motion.cgi program that is available from the motion homepage. To enable the feature to a broad audience you should use this applet or similar.
To use the webcam feature with Cambozola is actually very simple.
1. Create a html page in which you will want the streamed picture.
2. In the html page include this code
<applet code=com.charliemouse.cambozola.Viewer
archive=cambozola.jar width=400 height=300>
<param name=url value=http://www.myurl.com:8081>
</applet>
Where the width and height is the area of the applet. Adjust it to the same
size or a little larger than your streamed image.
Replade www.myurl.com:8081
by the real url and port number of your choice.
3. In the same directory you place the cambozola.jar file. No need to build the java applet from source. Simply use the applet in the package. Or copy it from motion.cgi package. It is the same version.
4. Enable the feature in motion with these config lines.
############################################################
# Webcam:
############################################################
# Supply a live stream using multipart jpegs with a mini
# http deamon.
# Default: not set
webcam_port 8081
webcam_quality 30
webcam_motion no
webcam_maxrate 4
Naturally adjust the settings to your preference. Maxrate and quality are important to limit the load on your server and link. Don't set them too high.
Motion supports capture cards with more than more input. The inputs are controlled
through the Video4Linux interface and are simply numbered. To find out which
number means what you can experiment with a program such as Camstream. Here
you can see which input has which number easily.
Some capture cards are specially
made for surveillance with for example 4 inputs. Others have a TV tuner, a composite
input (phono socket) and perhaps also a S-VHS input. For all these cards the
inputs are numbered. The numbering varies from card to card so the easiest is
to experiment for 5 minutes with a program that can show the videostream.
This feature is automatically activated where multiple threads are sharing
the same video device. Each thread can then set different input channels or
frequencies to change camera. These are the special roundrobing options:
-
If multiple threads use the same video device, they each can capture roundrobbing_frames
number of frames before having to share the device with the other threads.
-
When another thread wants to watch another input or frequency or size the first
round_robing_skip number of frames are skipped to allow the device to
settle.
TV tuner cards are used the same way as video capture cards except one of the inputs have one extra parameter which is the "frequency" for the TV tuner. The value is the value that the bttv driver sends to the capture card. Use a program such as Camstream or xawtv to experiment with the values.
This is still at the experimental stage. Read more about it motion tracking page.
Drawtext is a new feature added to motion version 3.0.3. It enables you to taylor the on-screen display (OSD) to your taste and to add your own user defined text.
Motion has the following on screen display.
|
USERTEXT is a user defined text defined by the 'drawtext_user' option. If
the option is not defined no text is displayed at this position.
CHANGES
is the number of pixels that changed compared to the reference frame. Good for
calibration and test. Maybe not so interesting for a greater public. The feature
can be turned on or off by setting the 'drawtext_changes' option to on or off.
YYYY-MM-DD
is the date in international date format - year four digits - month two digits
- date. This cannot be changed.
HH:MM:SS is the time - hour : minute : second.
This cannot be changed either.
FM is the frame number. If you save pictures
faster than once per second or you generate mpegs with ffmpeg - it can be quite
nice to identify each picture frame by a unique time stamp. Setting the option
'drawtext_shots' to on or off adds the frame number as '- two digits' after
the time stamp.
The 3 options 'drawtext_user', 'drawtext_changes' and 'drawtext_shots' can be entered both in the motion.conf file and in each thread.conf file. E.g. you can set the 'drawtext_changes' and 'drawtext_shots' only in motion.conf setting the format of the display the same way for all cameras and then add unique 'drawtext_user" options in each thread.conf file. This way you can display "FRONT DOOR", "BACK DOOR" and "GARAGE" on 3 different cameras.
The user defined text can be the english alphabet - UPPERCASE letters only, the digits 0-9 and the characters "-" and ":". Use the underscore "_" as a space.
The video4linux device is a Kernel module which installs itself as a video
pipe. It has an input and an output. The module simply takes anything that comes
on its input and send it out at the output. The purpose of this is to create
a standard video4linux type video device that other programs can then use. You
may now ask: "What do I need that for?".
Only one program can access
a video device at a time. When motion is using a camera - no other program can
access the same camera. But motion is made to be able to feed a video signal
to the video loopback device. This way an additional program such as Camstream,
Xawtv, a video stream server etc can watch the signal from a camera that motion
uses already. What you see is not the live camera stream but the exact same
picture that motion uses for detecting motion and the same pictures that are
saved/streamed. You can also choose to see the "motion" type images
where you see the pixels that are changing - live. Originally the video4linux
pipe was used as an interface between Motion and a Webcam server. Since version
2.9 Motion has had its own webserver so this usage is no longer very relevant.
When you install the video loopback device it will create an input - for example /dev/video5 and an output - for example /dev/video6. You can then tell motion to "pipe" the video signal to the /dev/video5 and look at the pictures live using e.g. Camstream on /dev/video6. Camstream is "fooled" to think it is looking at a real camera.
Installing the video loopback device is not difficult. At least not when you have this document available.
First you must prepare your system for more video devices. You will need
two extra devices for each video pipe that you want.
For example if you have
4 cameras they will probably run at /dev/video0, /dev/video1, /dev/video2, and
/dev/video3. So you will need additional 8 video devices. This is easy to do.
mknod /dev/video4 c 81 4
mknod /dev/video5 c 81 5
mknod /dev/video6
c 81 6
mknod /dev/video7 c 81 7
mknod /dev/video8 c 81 8
mknod /dev/video9
c 81 9
mknod /dev/video10 c 81 10
mknod /dev/video11 c 81 11
Note that
the video device number is the same as the last parameter given on each line.
You may need to set the ownership and permissions (chown and chmod) to be the same as the video devices that were already there.
Now you need to install the video loopback device.
When compiling on a newer Linux distribution you may get a warning about
a header file malloc.h. To remove this warning simply change the header
reference as suggested by the warning.
In vloopback.c you replace the
line
#include <linux/malloc.h>
with the line
#include <linux/slab.h>
Motion contains a number of features that helps you tune the settings of
motion to the optimal. They are all described in the config file table above
but this section will try to illustrate them a bit more and give some guides
to how to tune.
The settings that are difficult to set are the settings that
decides or influence when to detect motion. These are
Special tuning options
Normal picture frame
Motion type picture frame with realmotion set to 'no'
Motion type picture frame with realmotion set to 'yes'
Note the dark area
in the upper left corner which is the area masked off by the mask_file option.