# Motion Guide

- Overview
- Installing with apt / Building from source
- Important Definitions
- The Configuration Files
- Command Line Options
- Signals (sent with e.g. kill command)
- Error Logging
- The Basic Setup
- Configuration Options

- Listed alphabetically with mapping of old option names to current names
- Listed by topic
- Detail descriptions of each option

## Overview

- What is Motion?
- How do I get Motion and what does it cost?
- Maintenance and Support
- Which version to download and use?
- What features does Motion have?
- FreeBSD
- MacOSX
- Documentation
- Supported Hardware
- Known Problems

### What is 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. Or in other words, it can detect motion.

The program is written in C and was made for the Linux operating system. Recent revisions have also made it available for BSD.

Motion is a command line based tool with only limited support for configuration via a http interface. The many configuration options are set via the command line or configuration files.

The output from motion can be:

- jpg files
- ppm format files
- movie video sequences

### How do I get Motion and what does it cost?

Motion is an open source type of project. It does not cost anything. Motion is published under the GNU GENERAL PUBLIC LICENSE (GPL) version 2 or later. It may be a bit difficult to understand all the details of the license text (especially if your first language is not English). It means that you can get the program, install it and use it freely. You do not have to pay anything and you do not have to register anywhere or ask the author or publisher for permission. The GPL gives you both rights and some very reasonable duties when it comes to copying, distribution and modification of the program. So in very general terms you do not have to worry about licensing as a normal hobby user. If you want to use Motion in a commercial product, if you want to distribute either modified or original versions of Motion - for free or for a fee, you should read the license carefully. For more information about free software and the GPL, I encourage you to study the very interesting documents about the subject available the of the Free Software Foundation pages about the Philosophy of the GNU Project.

### Maintenance and Support

Both Motion and the Motion Guide are written by people that do all this as a hobby and without asking for any payments or donations. We have a life other than developing Motion and its documentation. This means that bugfixes and updates to this guide are done as our time and families allow it. You are however encouraged to participate and contribute in a very active mailing list. It is a list with a very "positive attitude" and with many contributors that propose features, post patches, discuss problems and patiently answer newbie questions with a very positive spirit. Expect 1-10 emails per day.

To get Motion direct your browser to the Motion Homepage.

On the Releases page you will find links to the latest stable version binaries for some of the most popular Linux distributions. p> Motion was originally written by Jeroen Vreeken and later Folkert van Heusden continued as a lead programmer with Kenneth Lavrsen responsible for Motion Guide, website and releases on Sourceforge.

Staring with version 3.4.1 Motion is managed on github with many maintainers and contributors.

For support we encourage you to join the mailing list instead of writing to the maintainers directly. Newbies and stupid questions are welcome on the list. Contributions in the form of pull requests to the github repository are also very welcome.

### Which version to download and use?

The most current release version can be found on the github releases page here. The master branch of the github repository represents the official development branch of Motion. Additional independent development forks exist in other Github repos that contain additional bug fixes, enhanced features and updated documentation. This guide is based upon the features and options included in the source code with which it is distributed. It was re-written in September 2015 to reflect the changes and options in the code at that time. The majority of the new options and changed names represent differences between the 3.2.12 version and the legacy SVN trunk. Since 3.2.12 many options have been renamed to make setting up Motion easier. A cross reference of the old 3.2.12 option names to the new names can be reviewed here

Motion is included in Debian and Ubuntu while RPM users currently must build from source.

### What features does Motion have?

- 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
- Real time creation of movies using libraries from ffmpeg
- Take automated snapshots on regular intervals
- Take automated snapshots at irregular intervals using cron
- Executing external program when a particular event occurs
- Motion tracking
- Feed events to an MySQL, PostgreSQL or SQLite3 database.
- Feed video back to a video4linux loopback for real time viewing
- Control via simple web interface.
- Automatic noise and threshold control
- Ability to control the pan/tilt of a tracking camera.
- Highly configurable display of text on images.
- Highly configurable definition of path and file names of the stored images and movies.

### FreeBSD

Motion was originally developed for Linux and it is still mainly developed and supported for this platform. Thanks to contributions of Angel Carpintero, Motion now builds on BSD platforms. See the file README.FreeBSD for instructions that are unique to the FreeBSD distribution.

### MacOSX

As of this writing, Motion currently is not able to be built on MacOSX due to lack of a required header file. See Issues for tracking of the status for MacOSX.

### Documentation

You have the following sources of information:

- This Motion Guide
- The Frequently Asked Questions
- The author of the program has written a description of the technology behind motion.
- The man page. After installation simply type 'man motion' into a terminal screen.

### Supported Hardware

Motion supports video input from three kinds of sources.

Standard video4linux devices (e.g. /dev/video0), network cameras and the PI camera. Motion has no drivers for cameras. Installing or configuring the camera itself is outside the scope of this document. Generally, if the device works with other common video player software, it will work with Motion (and vice versa). As a result, it is often convenient to first get the device working with other software and then use those connection options with Motion.

### Known Problems

See also the Frequently Asked Questions and Issues for known open issues.

## Installing with apt / Building from source

- Installing with apt
- Abbreviated Building Guide
- Preparation For Building
- Configure Script
- Make

- Make Install
- Un-install
- Additional Make Options

- Upgrading From Older Version

### Installing with apt

Motion is part of the Ubuntu and Debian repositories and can be installed with the apt tool.

Open up a terminal window and type: `sudo apt-get install motion`

Before we start configuring Motion, we will copy the config file to our Home folder so that the master copy won't be affected. Open a terminal and copy the configuration file to your Home folder with following commands:

`mkdir .motion`

(Note: This will create a hidden folder .motion in your Home directory.)

`cp /etc/motion/motion-dist.conf ~/.motion/motion.conf`

(Note: This command will copy the original motion configuration file to its location.)

Now can open the configuration file for editing:

`sudo nano ~/.motion/motion.conf`

After you you have made all the appropriate adjustments to the configuration file, close it. Then start motion in the terminal simply by typing:

`motion`

### Abbreviated Building Guide

If you are familiar with the building of applications, then the following is a basic build / install script for Ubuntu. If errors occur during the process or you wish to customize the build, please review the extended building instructions further below.

`sudo apt-get install autoconf automake build-essential pkgconf libtool libzip-dev libjpeg62 libjpeg62-dev git libavformat-dev libavcodec-dev libavutil-dev libswscale-dev`

`cd ~`
`git clone https://github.com/Motion-Project/motion.git`
`cd motion`
`autoreconf -fiv`
`./configure`
`make`
`make install`

### Preparation For Building

In order to build Motion from source many shared libraries must be installed. The particular libraries needed will vary depending upon the features desired.

When you install software using pre-compiled binaries (Redhat type RPMs, Debian debs etc) you normally only get what is needed to run the programs themselves. In order to compile programs from source that use these libraries you also need to installed the development packages. These are normally called the same name as the package suffixed by -devel or -dev. These development packages contain the header files (xxx.h) that Motion needs to build. If you build a library from sources you already have these header files. It is recommended to simply install the pre-compiled binary packages and their development brothers.

Open a terminal and run the following commands to install the packages.

Ubuntu / Debian Packages

- Required

`sudo apt-get install autoconf automake build-essential pkgconf libtool git libzip-dev libjpeg62 libjpeg62-dev`

- Optional Packages

- FFMpeg Functionality(Required for creating movies, using network cameras, etc. See note below!)

`sudo apt-get install libavformat-dev libavcodec-dev libavutil-dev libswscale-dev`

- MySQL database functionality

`sudo apt-get install mysql-server libmysqlclient-dev`

- PostgreSQL database functionality

`sudo apt-get install postgresql libpq-dev`

- SQLite3 database functionality

`sudo apt-get install sqlite3`

- JPEG Turbo

`sudo apt-get install libjpeg-turbo8 libjpeg-turbo8-dev`

- SDL

`sudo apt-get install libsdl1.2-dev`

Important ffmpeg/libav note: Motion has been built to use either the libav or the ffmpeg set of libraries. Which set of libraries to use is a user selection and possibly dependent upon which is available in the Ubuntu/Debian repositories. The packages listed above are those that are available within Ubuntu 16.04. The package names in earlier versions or on other distributions will vary. The configure option can also be used to remove the ffmpeg/libav functionality and the dependency on these libraries.

openSUSE Packages

- Required

`sudo zypper install autoconf automake libtool git`

`sudo zypper install --type pattern devel_basis`

`sudo zypper install libjpeg8-devel`

`sudo zypper install -t pattern devel_C_C++`

- Optional Packages

- FFMpeg Functionality(Required for creating movies, using network cameras, etc. SEE NOTE BELOW!)

`sudo zypper ar -f -n packman-essentials http://packman.inode.at/suse/openSUSE_13.1/Essentials/ packman-essentials`

`sudo zypper ar -f -n packman-multimedia http://packman.inode.at/suse/openSUSE_13.1/Multimedia/ packman-multimedia`

`sudo zypper install libffmpeg-devel`

- MySQL database functionality

`Not known by author`

- PostgreSQL database functionality

`Not known by author`

- SQLite3 database functionality

`Not known by author`

Important ffmpeg note: The ffmpeg libraries indicated above are provided by a external repository. This may change in the future. Validate that the repository is still valid when doing the install on openSUSE systems. The default for the configure is to require that ffmpeg or Libav is installed. Use the configure option to compile without the ffmpeg / libav functionality.

FreeBSD

- Required packages

- autoconf
- automake
- gcc
- gmake
- libjpeg-turbo
- pkgconf
- ffmpeg

- Optional database packages

- mysql57-client
- postgresql95-contrib
- sqlite3

- PWC based webcams packages

- pwcbsd
- v4l_compat

### Configure Script

Motion uses a set tools called the "autotools" in order to generate the required scripts in order to compile and install Motion. The next step after installing all of the required and desired libraries is to have the autotools create a configure script. To do this open a terminal and change to the directory with the source code and type

`autoreconf`

If the 'configure' file exists and contains a valid script, the tool will return immediately since no additional work needs to be completed. If the script needs updating, then it will take a moment to return. Once it has been executed, a file called 'configure' will exist in the directory. Note that if the command is run as

`autoreconf -f`

The -f parameter instructs it to force a new configure file to be created. This can be preferable in certain situations so that the configure script gets updated with the correct version number. Once the 'configure' file is created, we can execute it. What the script does is interrogate the system and look for all the needed items in order to compile Motion. In this process it looks to determine which optional components have been installed on the system and if found sets flags to indicate for them to be included. If a particular library is required by Motion and is not found, the configure script will issue an error. The error means that the library was not found because it was either not installed or that it was installed into a location that the script could not find. With the Motion configure script, once it has ended it also lists out all of the optional components that were located. Note that if you KNOW that a particular component is installed yet the configure script reports it as not installed, then it may be necessary to use one or more of the configure options described below to tell the script where to find the particular component.

To run the 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.

When the configure script finishes you should validate that the options desired were correctly identified by the configure. In particular, the ffmpeg option is occasionally not found even if it is actually installed. Various users have indicated this to be a particular problem with the PI. If using a PI and have this issue, you can use the following option

`./configure --with-ffmpeg=/usr/lib/arm-linux-gnueabihf`

For a long term option, you can edit the file `$HOME/.bashrc` and within it place the following two lines at the end `PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf:$PKG_CONFIG_PATH` `export PKG_CONFIG_PATH` This option will however only become effective the next time you get into the terminal shell.

The following options can be specified with the configure script to customize how Motion is built.

Options | Description Defaults for the options are specified in brackets [ ] | 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.
--help=recursive | display the short help of all the included packages |
-V, --version | display version information and exit | Provides the version number of the source code and autotools
-q, --quiet, --silent | do not print `checking...' messages | Illustrates only the results of the script.
--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.
Installation directories: |  |
--prefix=PREFIX | install architecture-independent files in PREFIX [/usr/local] | 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 The configuration file in /usr/local/etc/motion The example config files in /usr/local/motion/examples If you are experimenting with many parallel versions it may be interesting to set the PREFIX to e.g. /usr/local/motion and then add /usr/local/motion/bin to your search path (or simply cd /usr/local/motion/bin before execution). This way you can change version just by changing the symbolic link in /usr/local/motion as suggested earlier in this guide. If you are installing the software on a machine where you have no access to the /usr/local but have write access to a home directory, then you should change this to point to a directory within your home tree. Example: --prefix=$HOME
--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. Note: The executable binary will be placed in a directory "bin" below the directory specified by this option Editor recommends leaving this as default (i.e. not setting it).
--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.
--libexecdir=DIR | program executables [EPREFIX/libexec] | Not used by motion.
--datadir=DIR | read-only architecture-independent data [PREFIX/share] | Not used by motion.
--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. Motion searches for the configuration file "motion.conf" in the following order: 1. Current directory from where motion was invoked 2. $HOME/.motion 3. The motion/ subdirectory inside the sysconfig directory set by this switch. If not defined the default is /usr/local/etc/ Editor recommends leaving this at default. Be careful if you run "make install" again. This will overwrite the motion-dist.conf file that you may have edited.
--sharedstatedir=DIR | modifiable architecture-independent data [PREFIX/com] | Not used by motion.
--localstatedir=DIR | modifiable single-machine data [PREFIX/var] | Not used by motion.
--libdir=DIR | object code libraries [EPREFIX/lib] | Not used by motion.
--includedir=DIR | C header files [PREFIX/include] | Not used by motion.
--oldincludedir=DIR | C header files for non-gcc [/usr/include] | Not used by motion.
--infodir=DIR | info documentation [PREFIX/info] | Not used by motion.
--mandir=DIR | man documentation [PREFIX/man] | Editor recommends the default.
Optional Packages: |  |
--- | --- | ---
--with-linuxthreads | Use linuxthreads in BSD instead of native phtreads | Only relevant for BSD. In Linux we always use this per default.
--with-pwcbsd | Use pwcbsd based webcams ( only BSD ) | This option allow to build motion to support V4L/V4L2 in BSD.
--without-bktr | Exclude to use bktr subsystem , that usually useful for devices as network cameras | ONLY used in *BSD
--without-v4l | Exclude using v4l (video4linux) subsystem. Makes Motion so it only supports network cameras. | Can be used if you do not need support and maybe lack some of the libraries for it.
--with-jpeg-mmx=DIR | Specify the prefix for the install path for jpeg-mmx for optimized jpeg handling |
--with-ffmpeg=DIR | Specify the path for the directory prefix in which the library and headers are installed . If not specified configure will search in /usr/ and /usr/local/ | DIR is the directory PREFIX in which the ffmpeg shared libraries and their headers are installed. If you install ffmpeg from sources and use the default directories or if ffmpeg is installed as a binary package (RPM or deb) you may not need to specify the directory prefix. Configure should find the libraries automatically. If you installed ffmpeg from sources and specified a different --prefix when building ffmpeg you must use the same value for the DIR ( --with-ffmpeg=DIR) or export that location to be included in the PKG_CONFIG_PATH The option of --with-ffmpeg is the default for Motion. If the required libraries are not located, the configure script will stop at the ffmpeg section and report which libraries need to be installed. Once the required libraries are installed, run the script again. As noted previously, make sure to install the -dev versions. For more information on FFmpeg see the documentation for the FFmpeg project.
--without-ffmpeg | Do not compile with ffmpeg | Use this if you do not want to compile with ffmpeg. If ffmpeg is not installed you must specify this option for Motion to build without ffmpeg.
--with-mysql-lib=DIR | Lib directory of MySQL | Normally, configure will scan all possible default installation paths for MySQL libs. When its fail, use this command to tell configure where MySQL libs installation root directory is.
--with-mysql-include=DIR | Include directory with headers for MySQL | Normally, configure will scan all possible default installation paths for MySQL include. When its fail, use this command to tell configure where MySQL include installation directory is. This is the directory with the MySQL header files.
--without-mysql | Do not compile with MySQL support | Use this if you do not want to include MySQL support in the package. This can also be useful if you get compilation errors related to MySQL and you actually do not need the feature anyway.
--with-pgsql-lib=DIR | Normally, configure will scan all possible default installation paths for pgsql libs. When it fails, use this command to tell configure where pgsql libs installation root directory is. |
--with-pgsql-include=DIR | Normally, configure will scan all possible default installation paths for pgsql include. When it fails, use this command to tell configure where pgsql include installation root directory is. |
--without-pgsql | Do not compile with PostgreSQL support | Use this if you do not want to include PostgreSQL support in the package. This can also be useful if you get compilation errors related to PostgreSQL and you actually do not need the feature anyway.
--without-sqlite3 | Disable sqlite3 support in motion. | Use this if you do not want to include SQLite3 support in the package. This can also be useful if you get compilation errors related to SQLite4 and you actually do not need the feature anyway.
--without-optimizecpu | Exclude autodetecting platform and cpu type. This will disable the compilation of gcc optimizing code by platform and cpu. | Use this if the optimization causes problems. Typically if you build on some non X386 compatible CPU.
--with-sdl=DIR | Compile with sdl support. |
--with-jpeg-turbo=DIR | Specify the prefix for the install path for jpeg-turbo for optimized jpeg handling (optional). |
--with-developer-flags | Add additional warning flags for the compiler. | This option is for developers only. It produces a flood of warnings that helps the developer to write more robust code. These warnings are normally harmless but can sometimes be a latent defect.

### Make

Once the configure script has successfully finished and indicates all options desired, a 'makefile' is created. The makefile builds the Motion program and links in all of the required libraries. To run the makefile on most distributions, type: `make` For FreeBSD distributions use `gmake`

The makefile will go through each of the files and compile it. Depending upon the source code obtained, there may be many warnings or possibly none.

If the notifications indicate undefined references, then it is most likely that an additional library needs to be added in via the configure switches. Many of these additional missing libraries issues are related to the version of ffmpeg and how it was built or installed. The following is a sample of some of the extra ffmpeg libraries that may need to be added.

`-lavformat -lswscale -lavcodec -lavutil -lfdk-aac -lswresample -lm -lopus -lz -lva -lvpx -lx264 -lmp3lame -lbz2 -ldl -lvorbisenc -lvorbis -ltheoraenc -ltheoradec`

Once the makefile has completed correctly, it will report 'build complete'.

If you have run `make` before, you should run a `make clean` before running `make` again. This cleans out all the object files that were generated the previous time you ran `make`. If you do not run `make clean` first before you rebuild Motion you may not get the additional feature included. For example: If you built Motion without ffmpeg support and then add it later and rebuild Motion without running `make clean` first the ffmpeg feature does not get compiled into the Motion binary.

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

For most distributions type `make install` to install the files. For FreeBSD systems, use `gmake install`

These commands create the required directories and copy the files into the following locations. (default directories):

- /usr/local/bin
- usr/local/man/man1
- /usr/local/etc/motion
- /usr/local/share/doc/motion
- /usr/local/share/motion/examples

The contents of what gets copied into each directory is as follows: (assuming the default PREFIX /usr/local was used when running configure. Otherwise adjust to the actuals you chose)

- Executable binary "motion" to /usr/local/bin
- Manual page "motion.1" to /usr/local/man/man1
- Document files "CHANGELOG, COPYING, CREDITS, INSTALL, and README to /usr/local/share/doc/motion
- Example configuration files "*.conf" to /usr/local/share/motion/examples
- Configuration file "motion-dist.conf" to /usr/local/etc/motion

Note that any existing files are overwritten. The default config file motion-dist.conf is named like this so that you do not get your working motion.conf file overwritten when you upgrade Motion.

### Un-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.

### Additional Make Options

The make command can be run with several 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. It is very important to always run `make clean` before you run `make` if you change the configuration (like adding features such as ffmpeg) and rebuild motion.

make distclean
  deletes the files: config.status, config.log, config.cache, Makefile, and motion.spec.

### Upgrading From Older Version

If you are upgrading from an older version of Motion many options have been renamed, added or removed. The author recommends that you start by copying the configuration files from the older version to a safe location for reference only. Then start with a clean copy of the new motion-dist.conf installed and make changes to it.

## Important Definitions

Motion is invoked from the command line. It has no GUI. Everything is controlled from config files. From version 3.2 the command line is only used to define location of config file and a few special options.

A few important definitions.

- A snapshot is a picture taken at regular intervals independently of any movement in the picture.
- A "motion" image/movie shows the pixels that have actually changed during the last frames. These pictures are not very useful for normal presentation to the public but they are quite useful for testing and tuning and making mask files as you can see exactly where motion sees something moving. Motion is shown in greytones. If labelling is enabled the largest area is marked as blue. Smart mask is shown in red.
- A "normal" image is the real image taken by the camera with text overlayed.

## The Configuration Files

If Motion was invoked with command line option `-c pathname` Motion will expect the config file to be as specified. When you specify the config file on the command line with -c you can call it anything.

If you do not specify -c or the filename you give Motion does not exist, Motion will search for the configuration file called 'motion.conf' in the following order:

1. Current directory from where motion was invoked
2. Then in a directory called '.motion' in the current users home directory (shell environment variable $HOME). E.g. /home/goofy/.motion/motion.conf
3. The directory defined by the --sysconfdir=DIR when running .configure during installation of Motion
   (If this option was not defined the default is /usr/local/etc/motion)

If you have write access to /usr/local/etc/motion then the editor recommends having only one motion.conf file in the default /usr/local/etc/motion directory.

Motion has a configuration file in the distribution package called motion-dist.conf. When you run 'make install' this file gets copied to the /usr/local/etc/motion directory.

The configuration file needs to be renamed from motion-dist.conf to motion.conf. The original file is called motion-dist.conf so that your perfectly working motion.conf file does not accidentally get overwritten when you re-install or upgrade to a newer version of Motion.

If you have more than one camera you should not try and invoke Motion more times. Motion is made to work with more than one camera at the same time. The motion.conf file establishes global parameters that apply to all cameras and separate camera.conf files that specify the parameters that apply to each specific camera. The camera.conf files are specified at the bottom of the motion.conf file. If you only have one camera you only need the motion.conf file but if you have more than one camera, then you will need to have one camera config file per camera plus the motion.conf file.

So if you have for example two cameras you need motion.conf and two camera config files. So a total of three config files.

An option that is common to all cameras can be placed in motion.conf. (You can also put all parameters in the camera files but that makes a lot of editing when you change a common thing).

An option that is unique to a camera must be defined in each camera file.

It is often seen that people copy the entire motion.conf into the camera config files and change a few options. This works but it not recommended because it is more difficult to maintain and overview. Keep all the common options in motion.conf and the few unique only in the camera config files

The first camera is defined in the first camera file called from motion.conf. The 2nd camera is defined in the 2nd camera file called from motion.conf etc.

Any option defined in motion.conf will be used for all cameras except for the cameras in which the same option is defined in a camera config file.

To make it clear, the camera files format and syntax is the same as motion.conf. An example of what you might want in a camera file as follows: assume you have two cameras, attached to one system. Create files camera0.conf and camera1.conf. At the end of motion.conf, uncomment out the lines that refer to them. The full contents of the camera files can be as simple as

camera0.conf:
`videodevice /dev/video0`
`stream_port 8081`

camera1.conf:
`videodevice /dev/video1`
`stream_port 8082`

Motion reads its configuration parameters in the following sequence. If the same parameter exists more than one place the last one read wins

1. Motion reads the configuration file motion.conf from the beginning of the file going down line by line.
2. If the option "camera" is defined in motion.conf, the camera configuration file(s) is/(are) read.
3. Motion continues reading the rest of the motion.conf file. Any options from here will overrule the same option previously defines in a camera config file.
4. Motion reads the command line option again overruling any previously defined options.

So always call the camera config files in the end of the motion.conf file. If you define options in motion.conf AFTER the camera file calls, the same options in the camera files will never be used. So always put the camera file call at the end of motion.conf.

Nearly all config options can be unique for a specific camera and placed in a camera config file. There are a few options that must be in motion.conf and cannot be in a camera config file: stream_auth_method, webcontrol_* , daemon, and camera.

If motion is built without specific features such as ffmpeg, mysql etc it will ignore the options that belong to those features.

If you run the http control command http://host:port/0/config/writeyes, motion will overwrite motion.conf and all the camera.conf files by autogenerated config files neatly formatted and only with the features included that Motion was built with. If you later re-build Motion with more features or upgrade to a new version, you can use your old config files, run the motion.conf.write command, and you will have new config files with the new options included all set to their default values. This makes upgrading very easy to do.

## Command Line Options

SYNOPSIS

    motion [ -hbnsm ] [ -c config file path ] [ -d level ] [ -k level ] [ -p process_id_file ] [ -l log_file ]

- -c : Full path and filename of config file.
- -h : Show help screen
- -b : Run in daemon mode
- -n : Run in non-daemon mode
- -s : Run in setup mode. Also forces non-daemon mode.
- -d : Run with message log level 1 - 9
- -k : Run with message log type 1 - 9
- -l : Full path and file name for log file
- -p : Full path and file name for the process id file
- -m : Start in pause mode

## Signals (sent with e.g. kill command)

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. Motion responds to the following signals:

Signal | Description | Editors comment
--- | --- | ---
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 movie file of the last event and exit |
SIGUSR1 | Motion will create an movie file of the current event. |

## Error Logging

Motion reports errors to the console when it runs in non-daemon mode. And it outputs even more information when run in setup mode.

Error logging has been implemented so that errors during daemon (background) mode are logged in the syslog or to the user specified log file.

The log is in most Linux systems the file `/var/log/messages` (e.g. RedHat/Fedora) or `/var/log/syslog` and `/var/log/user.log` (e.g. Debian).

## Basic Setup

Before you can start using Motion you need to know some basics about your camera(s).

For video4linux devices, the camera must be installed per the requirements of the camera. It is out of the scope of this document to tell you how to do this and it depends on which type of camera. Once the camera is installed it will have the device name(s) of /dev/video0, /dev/video1, /dev/video2...

FreeBSD has a different naming of devices. When you build Motion for FreeBSD the default device name is /dev/bktr0. Under FreeBSD a TV card has a special device for controlling the tuner (e.g. /dev/tuner0). The option tunerdevice is only valid when Motion is built and running under FreeBSD. For Linux do not include this option in the config file (remove or comment out).

USB cameras take a lot of bandwidth. A USB camera connected to a USB2 port or hub consumes virtually all the bandwidth that the port can handle. Even with a small framesize and low framerate you should not expect to have more than one camera per USB controller. If you need more than one USB camera it is possible to add extra USB PCI cards to your computer. It is also possible that your computer has more than one controller for different USB slots. For example, if the computer has six USB ports, the three on the left may be on controller A versus the three on the right may be on controller B. In this situation, connecting two cameras to ports only on the left would not work due to excessive bandwidth. However connecting one camera to port on the right and the other to the port on the left may work since they are on different controllers.

Motion permits the use of video cards that have discreet input channels. Since USB cameras do not have input channels, the option `input` must be set to the value -1 for USB cameras.

Network cameras are set up via the `netcam_url` parameter. The latest versions of Motion support rtsp format which many cameras now stream. The URL connection string to enter is specific to the camera and is usually provided by the manufacturer. The connection string is the same as what would be used by other video playing software such as VLC. If the camera does not stream via RTSP and instead uses a MJPEG, then Motion can also view that format. See the option `netcam_url` for additional options.

Raspberry Pi cameras are set up via the `mmalcam_name` parameter. Note that name for this parameter derives from the MMAL/OpenMax software. The most common use of this option is to use the Rasberry PI camera.

Composite video cards are normally made with a chip called BT878 (older cards have a BT848). They all use the Linux driver called 'bttv'.

There are cards with more then one video input but still only one BT878 chip. They have a video multiplexer which input is selected with the config option `input`. Input channel numbers start at 0 (which is why the value -1 and not 0 disables input selection). There are video capture cards available with 4 or 8 inputs but only one chip. They present themselves as one single video device and you select input using the 'input' option. If you define e.g. 4 camera config files with the same videodevice name but different input numbers Motion automatically goes into round robin mode.

Many TV tuner cards have the input channels: TV Tuner = 0, Standard composite video = 1, S-VHS = 3. Others have TV=0, composite video 1= 1, composite video = 2, S-VHS = 3. For video capture cards input 1 is normally the composite video input.

Some capture cards are specially made for surveillance with for example 4 inputs. Others have a TV tuner, a composite input and perhaps also a S-Video 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. Use a program such as VLC to experiment with the values.

If you use the TV tuner input you also need to set the frequency of the TV channel using the option `frequency`. Otherwise set `frequency` to 0.

Finally you need to set the TV norm. Values: 0 (PAL), 1 (NTSC), 2 (SECAM), 3 (PAL NC no colour). Default is 0 (PAL). If your camera is a PAL black and white you may get a better result with norm=3 (PAL no colour).

## Configuration Options-Listed Alphabetically

These are the options that can be used in the config file.

All number values are integer numbers (no decimals allowed). Boolean options can be on or off.

Some configuration options are only used if Motion is built on a system that has the matching software libraries installed (MySQL, PostgreSQL, SQLite, FFMPEG, etc).

Version 3.2 | Version 3.4 | Current Version
area_detect | area_detect | area_detect
auto_brightness | auto_brightness | auto_brightness
brightness | brightness | brightness
thread | thread | camera
|  | camera_dir
|  | camera_id
|  | camera_name
contrast | contrast | contrast
daemon | daemon | daemon
| database_busy_timeout | database_busy_timeout
mysql_db | database_dbname | database_dbname
pgsql_db | database_dbname | database_dbname
mysql_host | database_host | database_host
pgsql_host | database_host | database_host
mysql_password | database_password | database_password
pgsql_password | database_password | database_password
pgsql_port | database_port | database_port
| database_type | database_type
mysql_user | database_user | database_user
pgsql_user | database_user | database_user
despeckle | despeckle_filter | despeckle_filter
output_all | emulate_motion | emulate_motion
gap | event_gap | event_gap
| exif_text | exif_text
| extpipe | extpipe
ffmpeg_bps | ffmpeg_bps | ffmpeg_bps
| ffmpeg_duplicate_frames | ffmpeg_duplicate_frames
ffmpeg_cap_motion | ffmpeg_output_debug_movies | ffmpeg_output_debug_movies
ffmpeg_cap_new | ffmpeg_output_movies | ffmpeg_output_movies
ffmpeg_timelapse | ffmpeg_timelapse | ffmpeg_timelapse
ffmpeg_timelapse_mode | ffmpeg_timelapse_mode | ffmpeg_timelapse_mode
ffmpeg_variable_bitrate | ffmpeg_variable_bitrate | ffmpeg_variable_bitrate
ffmpeg_video_codec | ffmpeg_video_codec | ffmpeg_video_codec
framerate | framerate | framerate
frequency | frequency | frequency
height | height | height
hue | hue | hue
input | input | input
| ipv6_enabled | ipv6_enabled
lightswitch | lightswitch | lightswitch
locate | locate_motion_mode | locate_motion_mode
| locate_motion_style | locate_motion_style
| log_level | log_level
| log_type | log_type
| logfile | logfile
mask_file | mask_file | mask_file
max_mpeg_time | max_movie_time | max_movie_time
minimum_frame_time | minimum_frame_time | minimum_frame_time
minimum_motion_frames | minimum_motion_frames | minimum_motion_frames
|  | mmalcam_control_params
|  | mmalcam_name
motion_video_pipe | motion_video_pipe | motion_video_pipe
movie_filename | movie_filename | movie_filename
netcam_http | netcam_keepalive | netcam_keepalive
netcam_proxy | netcam_proxy | netcam_proxy
netcam_tolerant_check | netcam_tolerant_check | netcam_tolerant_check
netcam_url | netcam_url | netcam_url
netcam_userpass | netcam_userpass | netcam_userpass
noise_level | noise_level | noise_level
noise_tune | noise_tune | noise_tune
norm | norm | norm
on_area_detected | on_area_detected | on_area_detected
on_camera_lost | on_camera_lost | on_camera_lost
on_event_end | on_event_end | on_event_end
on_event_start | on_event_start | on_event_start
on_motion_detected | on_motion_detected | on_motion_detected
on_movie_end | on_movie_end | on_movie_end
on_movie_start | on_movie_start | on_movie_start
on_picture_save | on_picture_save | on_picture_save
output_normal | output_debug_pictures | output_debug_pictures
output_motion | output_pictures | output_pictures
jpeg_filename | picture_filename | picture_filename
ppm | picture_type | picture_type
post_capture | post_capture | post_capture
| power_line_frequency | power_line_frequency
pre_capture | pre_capture | pre_capture
process_id_file | process_id_file | process_id_file
quality | quality | quality
quiet | quiet | quiet
rotate | rotate | rotate
roundrobin_frames | roundrobin_frames | roundrobin_frames
roundrobin_skip | roundrobin_skip | roundrobin_skip
| rtsp_uses_tcp | rtsp_uses_tcp
saturation | saturation | saturation
| sdl_threadnr | sdl_threadnr
setup_mode | setup_mode | setup_mode
smart_mask_speed | smart_mask_speed | smart_mask_speed
snapshot_filename | snapshot_filename | snapshot_filename
snapshot_interval | snapshot_interval | snapshot_interval
sql_log_mpeg | sql_log_movie | sql_log_movie
sql_log_image | sql_log_picture | sql_log_picture
sql_log_snapshot | sql_log_snapshot | sql_log_snapshot
sql_log_timelapse | sql_log_timelapse | sql_log_timelapse
sql_query | sql_query | sql_query
| stream_auth_method | stream_auth_method
| stream_authentication | stream_authentication
webcam_limit | stream_limit | stream_limit
webcam_localhost | stream_localhost | stream_localhost
webcam_maxrate | stream_maxrate | stream_maxrate
webcam_motion | stream_motion | stream_motion
webcam_port | stream_port | stream_port
| stream_preview_newline | stream_preview_newline
| stream_preview_scale | stream_preview_scale
webcam_quality | stream_quality | stream_quality
switchfilter | switchfilter | switchfilter
target_dir | target_dir | target_dir
text_changes | text_changes | text_changes
text_double | text_double | text_double
text_event | text_event | text_event
text_left | text_left | text_left
text_right | text_right | text_right
threshold | threshold | threshold
threshold_tune | threshold_tune | threshold_tune
timelapse_filename | timelapse_filename | timelapse_filename
track_auto | track_auto | track_auto
track_iomojo_id | track_iomojo_id | track_iomojo_id
track_maxx | track_maxx | track_maxx
track_maxy | track_maxy | track_maxy
track_motorx | track_motorx | track_motorx
track_motory | track_motory | track_motory
track_move_wait | track_move_wait | track_move_wait
track_port | track_port | track_port
track_speed | track_speed | track_speed
track_step_angle_x | track_step_angle_x | track_step_angle_x
track_step_angle_y | track_step_angle_y | track_step_angle_y
track_stepsize | track_stepsize | track_stepsize
track_type | track_type | track_type
tunerdevice | tunerdevice | tunerdevice
| use_extpipe | use_extpipe
v4l2_palette | v4l2_palette | v4l2_palette
video_pipe | video_pipe | video_pipe
videodevice | videodevice | videodevice
control_authentication | webcontrol_authentication | webcontrol_authentication
control_html_output | webcontrol_html_output | webcontrol_html_output
control_localhost | webcontrol_localhost | webcontrol_localhost
control_port | webcontrol_port | webcontrol_port
width | width | width
ffmpeg_deinterlace | -Depreciated | -Depreciated

## Configuration Options-Listed by Topic

These are the options that can be used in the config file.

All number values are integer numbers (no decimals allowed). Boolean options can be on or off.

Some configuration options are only used if Motion is built on a system that has the matching software libraries installed (MySQL, PostgreSQL, SQLite, FFMPEG, etc).

System Processing

daemon | process_id_file | setup_mode | logfile
log_level | log_type | sdl_threadnr | camera
camera_id | camera_name | camera_dir

Video4Linux Devices

videodevice | v4l2_palette | tunerdevice | input
norm | frequency | power_line_frequency | auto_brightness
brightness | contrast | saturation | hue
roundrobin_frames | roundrobin_skip | switchfilter

Network Cameras

netcam_url | netcam_userpass | netcam_keepalive | netcam_proxy
netcam_tolerant_check | rtsp_uses_tcp

Raspberry Pi Camera

mmalcam_name | mmalcam_control_params

Image_Processing

rotate | width | height | framerate
minimum_frame_time | despeckle | locate_motion_mode | locate_motion_style
text_left | text_right | text_changes | text_event
text_double

Motion Detection

emulate_motion | threshold | threshold_tune | noise_level
noise_tune | area_detect | mask_file | smart_mask_speed
lightswitch | minimum_motion_frames | event_gap

Script Execution

on_event_start | on_event_end | on_picture_save | on_motion_detected
on_area_detected | on_movie_start | on_movie_end | on_camera_lost

Output - General

quiet | pre_capture | post_capture | target_dir

Output - Picture

output_pictures | output_debug_pictures | quality | picture_type
snapshot_interval | snapshot_filename | picture_filename | exif_text

Output - Movie

max_movie_time | ffmpeg_output_movies | ffmpeg_output_debug_movies | ffmpeg_timelapse
ffmpeg_timelapse_mode | ffmpeg_bps | ffmpeg_variable_bitrate | ffmpeg_video_codec
ffmpeg_duplicate_frames | movie_filename | timelapse_filename

Output - Pipe

video_pipe | motion_video_pipe | use_extpipe | extpipe

Stream and Webcontrol

ipv6_enabled | stream_port | stream_quality | stream_motion
stream_maxrate | stream_localhost | stream_limit | stream_auth_method
stream_authentication | stream_preview_scale | stream_preview_newline | webcontrol_port
webcontrol_localhost | webcontrol_html_output | webcontrol_authentication

Database

sql_log_picture | sql_log_snapshot | sql_log_movie | sql_log_timelapse
sql_query | database_type | database_dbname | database_host
database_user | database_password | database_port | database_busy_timeout

Tracking

track_type | track_auto | track_port | track_motorx
track_motorx_reverse | track_motory | track_motory_reverse | track_maxx
track_minx | track_maxy | track_miny | track_homex
track_homey | track_iomojo_id | track_step_angle_x | track_step_angle_y
track_move_wait | track_speed | track_stepsize

## Configuration Options-Detail Descriptions

The following section provides detailed descriptions of each of the configuration options.

### Conversion Specifiers

%Y | year | %m | month | %d | date
%H | hour | %M | minute | %S | second
%T | HH:MM:SS | %v | event | %q | frame number
%t | camera id number | %D | changed pixels | %N | noise level
%i | width of motion area, | %J | height of motion area, | %J | height of motion area,
%K | X coordinates of motion center | %L | Y coordinates of motion center | %C | value defined by text_event
%f | filename with full path | %n | number indicating filetype | %$ | camera name

The use of quotation marks around string is permitted. The conversion specifiers used have the same options as for the C function strftime (3) plus the few that are unique to Motion.

### System Processing

### daemon

- Type: Boolean
- Range / Valid values: on, off
- Default: off

When Motion is started, immediately go to daemon mode and release the terminal.

### process_id_file

- Type: String
- Range / Valid values:
- Default: Not Defined

Specify the full path and file name in order to store the pid for processing.

### setup_mode

- Type: Boolean
- Range / Valid values: on, off
- Default: off

When this option is turned on, Motion starts in setup mode so that the parameters can be set more easily. In setup mode two things happen: With 'motion -s' Motion runs in console mode instead of daemon. It outputs a lot of useful information for each frame from the camera. Each message is prefixed by [number] where number is the camera id number. When you look at the webcam stream you see a black image with numbers. What you see is the number of changed pixels, number of labeled areas and noise setting. When something moves you see the pixels detected as Motion in black and white. The largest labeled area (assuming despeckle is enabled and with the 'l' at the end) is blue. It is only the blue areas which is counted as Motion. If smartmask is enabled you see this as red areas. Here is a suggestion how to initially setup Motion.

- Disable despeckle (comment it out in motion.conf).
- Disable smartmask
- Enable both http control and webcam by setting port numbers. Example 8080 for control and 8081 for webcam.
- Start Motion in setup mode
- View the webcam stream. Either with Iceweasel or with Firefox by entering in the address of http://localhost:8080/
- Open a new tab and connect to the http interface. http://localhost:8080/ . You can now control and change almost anything while Motion is running. To disable a feature enter a space.
- Start by experimenting with noise level. Do this both during daylight and during darkness. You will be surprised to see how much noise a camera makes during night. Try using the automatic noise feature. It should work for most.
- Now try the despeckle feature. Enable it using the recommended default EedDl. If this is not enough experiment. Remember that the l must be the last letter.
- Set the threshold to what you want to trigger Motion.

In normal mode you can use the same setting with two browser tabs and experiment with settings of the camera if needed. From the web interface you can ask Motion to write all your changes back to the config files (motion.conf and camera config files).

### logfile

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not Defined

Use this option to specify the full path and filename to use for logging of the messages generated from Motion. If this option is not defined, the stderr and syslog is used. Note that Motion can generate a LOT of messages and as a result, this option should be considered if the log_level is at any of the higher levels.

### log_level

- Type: Integer
- Range / Valid values: 1 - 9
- Default: 6

This option specifies the level of verbosity of the messages sent from Motion. At a level of 8(DBG), there are a LOT of messages. At a level of 1(EMR) virtually no messages will be output.

The various levels are [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, INF, DBG, ALL).

### log_type

- Type: Discreet Strings
- Range / Valid values: See Below
- Default: ALL

The different components of Motion use different log types. This option allows the user to only show the messages from particular components. The choices for this option are: COR, STR, ENC, NET, DBL, EVT, TRK, VID, ALL

### sdl_threadnr

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

The SDL option is optional and unusual. When SDL is included in the building of Motion, there is the ability for Motion to create a SDL preview window for the user. The author believes this option to be more of a proof of concept on how to create a SDL window and show the image. (This same functionality can be achieved via the stream options) To activate the SDL window, include SDL support in the building of the Motion application. Start Motion and note the thread number indicated. Once that is noted, specify that thread number (or 1 more than that number) for this option. When Motion is started again, it will then create a SDL window to preview the image. To close the window, press X. Author is not aware of any method to restart the SDL window after it has been closed.

### camera

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not Defined

The full path and file name for the camera file. Motion allows for this line to be listed in the motion.conf file multiple times. These specifications should be the LAST lines in the motion.conf file. See the Configuration Files section within this guide for a completed discussion of what to put into the camera0.conf, camera1.conf, cameraX.conf files that would be specified in this option.

### camera_id

- Type: Integer
- Range / Valid values:
- Default: The sequence that the camera file is read

This option is useful for situations where there are multiple cameras being used by Motion. This option allows for the assignment of a numeric id number that can be used in database queries as well as format specifiers.

### camera_name

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

This option specifies a camera name to be used in the format specifiers as well as on the web interface.

### camera_dir

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

This option specifies a alternative directory to contain the individual camera configuration files.

### Video4Linux Device

### videodevice

- Type: String
- Range / Valid values: Max 4095 characters
- Default: /dev/video0 (FreeBSD: /dev/bktr0)

The video device to be used for capturing. Default for Linux is /dev/video0. for FreeBSD the default is /dev/bktr0. See the Basic Setup section of this guide for a additional discussion of this option.

This is the video4linux device name. Ignore this for net cameras.

### v4l2_palette

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

The v4l2_palette allows the user to choose preferable palette to be use by Motion. Note that this is only the preferred option. If the video device does not support the requested format, Motion will loop through the available palettes to try to find one that is supported by both Motion and the device. Motion will report the supported palettes of the device when Motion starts when the log_level is specified as NTC or higher. The default of 17 is highly preferred since this the native format that Motion uses internally.

- V4L2_PIX_FMT_SN9C10X : 0 'S910'
- V4L2_PIX_FMT_SBGGR16 : 1 'BYR2'
- V4L2_PIX_FMT_SBGGR8 : 2 'BA81'
- V4L2_PIX_FMT_SPCA561 : 3 'S561'
- V4L2_PIX_FMT_SGBRG8 : 4 'GBRG'
- V4L2_PIX_FMT_SGRBG8 : 5 'GRBG'
- V4L2_PIX_FMT_PAC207 : 6 'P207'
- V4L2_PIX_FMT_PJPG : 7 'PJPG'
- V4L2_PIX_FMT_MJPEG : 8 'MJPEG'
- V4L2_PIX_FMT_JPEG : 9 'JPEG'
- V4L2_PIX_FMT_RGB24 : 10 'RGB3'
- V4L2_PIX_FMT_SPCA501 : 11 'S501'
- V4L2_PIX_FMT_SPCA505 : 12 'S505'
- V4L2_PIX_FMT_SPCA508 : 13 'S508'
- V4L2_PIX_FMT_UYVY : 14 'UYVY'
- V4L2_PIX_FMT_YUYV : 15 'YUYV'
- V4L2_PIX_FMT_YUV422P : 16 '422P'
- V4L2_PIX_FMT_YUV420 : 17 'YU12'

### tunerdevice

- Type: String
- Range / Valid values: Max 4095 characters
- Default: /dev/tuner0

The tuner device used for controlling the tuner in a tuner card. This option is only used when Motion is compiled for FreeBSD. Make sure to remove or comment out this option when running Motion under Linux. See the Basic Setup section of this guide for a additional discussion of this option.

### input

- Type: Integer
- Range / Valid values: -1, 0 - 7
- Default: 1 (Disabled) /li>

Input channel to use expressed as an integer number starting from 0. This option should normally be set to 1 for video/TV cards, and -1 for USB cameras. This parameter is used only with video capture cards that has more than one input. However if you set the input number to e.g. 1 for a USB camera Motion writes an error message back. If you set it to -1 it does not give you any warning. 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 should set the value to the default -1. Many TV tuner cards have the input channels: TV Tuner = 0, Standard composite video = 1, S-VHS = 3. Other have TV=0, composite video 1= 1, composite video = 2, S-VHS = 3. It is recommended to set the parameter to -1 for USB cameras as your first try. For video capture cards input 1 is normally the composite video input.

### norm

- Type: Discrete Strings
- Range / Valid values: 0 (PAL), 1 (NTSC), 2 (SECAM), 3 (PAL NC no colour)
- Default: 0 (PAL)

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.

### frequency

- Type: Integer
- Range / Valid values: 0 - 999999
- Default: 0 (Not set)

The frequency to set the tuner to (kHz) per the tuner specifications. The default is 0 meaning not set. This option is only relevant if you have a TV tuner card where you can select the tuner frequency. Your tuner card must support this feature.

### power_line_frequency

- Type: Integer
- Range / Valid values: -1 to 3
- Default: -1

This option allows the user to specify the power line frequency that is applicable to the user. This option can help stabilize the images of some webcams that are sensitive to this frequency. This is not normally necessary.

- -1 : Do not modify device setting
- 0 : Power line frequency Disabled
- 1 : 50hz
- 2 : 60hz
- 3 : Auto

### auto_brightness

- Type: Boolean
- Range / Valid values: on, off
- Default: off

Let motion regulate the brightness of a video device. Only recommended for cameras without auto brightness Motion will try to adjust the brightness of the video device if the images captured are too dark or too light. This option will be most useful for video devices which sometimes don't have such an option in hardware. The auto_brightness feature will adjust the brightness of the device up or down until the value defined by the option brightness is reached (1 = dark, 255 = bright). If brightness is zero auto_brightness will try to adjust to the average brightness level 128. You need to know if the camera supports auto brightness. Most cameras have auto everything. If your video device already does this for you this option might cause oscillations. If you do not know assume that it has and do not use the Motion auto brightness feature. At least not to start with.

### brightness

- Type: Integer
- Range / Valid values: 0 - 255
- Default: 0 (disabled)

The brightness level for the video device. Value 0 means that Motion does not set the brightness value but leaves it unchanged. If this setting is used in conjunction with the auto_brightness feature then this setting is the average brightness level in the range 1 (dark) to 255 (bright) that the auto_brightness feature will try to achieve by adjusting the device brightness up and down.

### contrast

- Type: Integer
- Range / Valid values: 0 - 255
- Default: 0 (disabled)

The contrast level for the video device. Disabled (Value 0) means that Motion does not set the contrast value.

### saturation

- Type: Integer
- Range / Valid values: 0 - 255
- Default: 0 (disabled)

The color saturation level for the video device.

### hue

- Type: Integer
- Range / Valid values: 0 - 255
- Default: 0 (disabled)

The hue level for the video device.

### roundrobin_frames

- Type: Integer
- Range / Valid values: 1 - 2147483647
- Default: 1

Specifies the number of frames to capture before switching inputs, this way also slow switching (e.g. every second) is possible. The Round Robin feature is automatically activated where multiple cameras are sharing the same video device. Each camera can then set different `input` or `frequency` options to change camera. If multiple cameras use the same video device, they each can capture roundrobin_frames number of frames before having to share the device with the other cameras.

Round Robin is not relevant for Network cameras or standard USB web cameras. It is used with video capture cards which have multiple inputs per video chip. This is not the ideal way to run multiple cameras. When the capture card changes input it takes some time before the decoder chip has syncronized to the new camera. You can improve this if you have expensive cameras with a syncronize input. Only one camera can be decoded at a time so if you have 4 cameras connected 3 of the cameras will need to wait for their turn. The fact that cameras have to take turns and the fact that you have to skip a few frames after each turn dramatically lowers the possible framerate. You can get a high framerate by viewing each camera for a long time. But then you may miss the action on one of the inactive cameras. If you can afford it avoid Round Robin and buy the more expensive type of capture cards that has one decoder chip per input. If you only need 2 or 3 cameras you can also simply put 2 or 3 cheap TV cards in the computer. Linux has no problem working with multiple TV cards. (or better yet, it multiple cheap network cameras) If multiple cameras use the same video device, they each can capture `roundrobin_frames` number of frames before having to share the device with the other cameras. When another camera wants to watch another input or frequency or size the first `roundrobin_skip` number of frames are skipped to allow the device to settle. The last option `switch_filter` is supposed to prevent the change of camera from being detected as Motion. Its function is not perfect and sometimes prevents detection of real motion. You should start with having the option disabled and then try with the option enabled to see if you can skip less frames without loosing the detection of the type of motion you normally want to detect.

### roundrobin_skip

- Type: Integer
- Range / Valid values: 1 - 2147483647
- Default: 1

Specifies the number of frames to skip after a switch. (1 if you are feeling lucky, 2 if you want to be safe). The Round Robin feature is automatically activated where multiple cameras are sharing the same video device. Each camera can then set different input channels or frequencies to change camera. When another camera wants to watch another input or frequency or size the first roundrobin_ skip number of frames are skipped to allow the device to settle.

### switchfilter

- Type: Boolean
- Range / Valid values: on, off
- Default: off

Turns the switch filter on or off. The filter can distinguish between most switching noise and real motion. With this you can even set roundrobin_skip to 1 without generating much false detection. This is a round robin related feature used when you have a capture card with multiple inputs (controlled by the 'input' option) on the same videodevice.

### Network Cameras

Motion can connect to a network camera through a normal TCP socket. All you need to give it is the URL. The URL given must return either one single jpeg picture or an mjpeg stream. For the time being Motion cannot connect to a video stream such a mpeg, mpeg4, divx. The URL must return one single jpeg image, a mjpeg stream a rtsp stream, file or ftp. When getting a still image, make sure to validate that the camera is serving up a actual raw JPG file and not a HTML page with an embedded JPG which is the current standard. When the netcam_url is defined the video4linux options above are ignored. If the connection to a network camera is lost, Motion will reuse the last good image for approx 30 seconds. After 30 seconds the image is replaced by a grey image with a text telling that the signal is lost and when the connection was lost. This text and its date format is not configurable.

### netcam_url

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined

URL to use if you are using a network camera, size will be autodetected Available prefixes to the URL:

- http://
- ftp://
- mjpg://
- rtsp://
- mjpeg://
- file:///

The prefixes of mjpg and mjpeg are not actual protocols and allow the user to specify different formats and methods to access the network stream. They are internally translated into http. For options such as rtsp, it is recommended that the connection string be validated with other applications such as ffplay or VLC.

When the netcam_url is defined the video4linux options are ignored.

### netcam_userpass

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined

The Username and password for the network camera. For http protocols, this option is for HTTP 1.1 Basic authentication only. The string is specified as username:password. To use no authentication simply remove this option. Digest authentication is only available for rtsp cameras.

### netcam_keepalive

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

The setting for keep-alive of network socket, should improve performance on compatible net cameras.

- off: The historical implementation using HTTP/1.0, closing the socket after each http request.
- force: Use HTTP/1.0 requests with keep alive header to reuse the same connection.
- on: Use HTTP/1.1 requests that support keep alive as default.

### netcam_proxy

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined

URL to use for a netcam proxy server, if required. The syntax is http://myproxy:portnumber Use this if you need to connect to a network camera through a proxy server. Example of syntax: "http://myproxy.mydomain.com:1024 If the proxy port number is 80 you can ommit the port number. Then the syntax is use "http://myproxy.mydomain.com" . Leave this option undefined if you do not use a proxy server.

### netcam_tolerant_check

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

Use less strict jpeg checks for network cameras

### rtsp_uses_tcp

- Type: String
- Range / Valid values: on off
- Default: on

This option specifies the transport method for rtsp cameras. The TCP transport is highly preferred because without this option the rtsp images are frequently corrupted and result in many false positive values and images that appear to be smeared. Off indicates that UDP will be used.

### Raspberry Pi Camera

Motion can use the Raspberry Pi camera when connected. Before setting up Motion with the camera, it is recommended that the user first validate that the camera is functional with the raspistill/raspivid applications.

### mmalcam_name

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined

Name of camera to use if you are using a camera accessed through OpenMax/MMAL. The standard Raspberry Pi camera device name is "vc.ril.camera" without the quotes.

### mmalcam_control_params

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined

This option allows the user to specify control parameters to the Pi camera. The documentation of all of the options available to the Raspberry Camera module is beyond the scope of this guide. In general, the command line options that are available via the raspistill / raspivid applications are the options that can be specified in this Motion configuration option. Some of the more frequently used options are:

- Horizontal Flip: -hf
- Vertical Flip: -vf
- Rotation: -rot

### Image Processing

### rotate

- Type: Discrete Strings
- Range / Valid values: 0, 90, 180, 270
- Default: 0 (not rotated)

Rotate image the given number of degrees. The rotation affects all saved images as well as movies. The rotation feature is used when the camera is hanging upside down (180 degrees) or if you choose a picture format in portrait instead of the normal landscape (90 or 270 degrees). Note that the CPU load increases when using this feature with a value other than 0. Also note that Motion automatically swaps width and height if you rotate 90 or 270 degrees, so you don't have to touch these options.

### width

- Type: Integer
- Range / Valid values: Device Dependent
- Default: 352

The width in pixels of each frame. Valid range is camera dependent. 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 except for rtsp streams which does rescale the network camera image to the requested dimensions. Note that this rescaling comes at a very high CPU cost so it is recommended that the network camera send the image in the same dimensions as included in the configuration file. Motion actually set the size of the image coming from the video4linux device. Your camera or capture/TV card will not support any picture size. You must know which frame size (width and height) the camera supports. If you do not know start with width 320 and height 240 which most cameras and capture cards supports. 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. Older versions of Motion required that dimensions of image must have both height and width that are a multiple of 16. The latest versions have eliminated this requirement.

### height

- Type: Integer
- Range / Valid values: Device Dependent
- Default: 288

The height of the image in pixels. Motion does not scale so should be set to the actual size of the device. In case of a net camera motion sets the height to the height of the first image read except for rtsp streams which does rescale the network camera image to the requested dimensions. Note that this rescaling comes at a very high CPU cost so it is recommended that the network camera send the image in the same dimensions as included in the configuration file. Motion actually set the size of the image coming from the device. Your camera or capture/TV card will not support any picture size. You must know which frame size (width and height) the camera supports. If you do not know start with width 320 and height 240 which most cameras and capture cards supports. 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. Older versions of Motion required that dimensions of image must have both height and width that are a multiple of 16. The latest versions have eliminated this requirement.

### framerate

- Type: Integer
- Range / Valid values: 2 - 100
- Default: 100 (no limit)

Maximum number of frames to be captured from the camera per second. The faster you fetch pictures from the camera the more CPU load you get and the more pictures get included when Motion is detected. Motion will stop storing pictures if the framerate is set to less than 2. Set this parameter to the maximum number of images per second that you want to store either as images or as movies. To set intervals longer than one second use the 'minimum_gap' option instead.

### minimum_frame_time

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

Minimum time in seconds between the capturing picture frames from the camera. Default: 0 = disabled - the capture rate is given by the camera framerate. This option is used when you want to capture images at a rate lower than 2 per second. When this is enabled the framerate option is used only to set the pace the Motion service the webcam port etc.

### despeckle

- Type: String
- Range / Valid values: EedDl
- Default: Not defined

Despeckle motion image using combinations of (E/e)rode or (D/d)ilate. And ending with optional (l)abeling. A way of tuning (by removing or enhancing) noise in the motion image. Options for the despeckle feature are any of 'e', 'E', 'd' or 'D'. This can be combined by a trailing 'l' (letter l) which enables the labeling feature. Default: Not Defined (Don't despeckle and label). Wind blowing grass and trees around or poor light conditions can cause a lot of dots (or noise) to appear in the motion image (See the section on Tuning Motion). This feature removes (or enhances!) this noise and so improves the reliability of motion. The 'e' option removes diamonds, 'E' removes squares and alternating eE will remove circles. Each e/E you add will shrink the noise by a pixel all the way around. So 'despeckle Ee' will remove circles of radius 2. However, this will also shrink the detection by 2 and will affect the threshold. So to remove noise and then restore the detected motion to its original size try 'despeckle EedD'. After the despeckle feature is done you can let the labeling feature search for areas of connected pixels and "label" each area. The program will now trigger motion based on the number of changed pixels in the largest area. In other words, the largest labeled area has to be above the threshold to trigger a motion detected. The value EedDl is a good starting point. The possible combinations are endless and it requires many experiments to find the best combination. Just remember that the labeling feature only works as intended if it runs after the despeckle feature. Ie. the letter 'l' must be the last letter and only one 'l'. If you have very few problems with false detections leave this option either blank or at EedD which will remove most of the single pixel noise. A very detailed technical explanation of the despeckle part can be found at the webpage of the author of this feature Ian McConnell's Webcam: Motion Web Page

### locate_motion_mode

- Type: Boolean
- Range / Valid values: on, off, preview
- Default: off

Locate and draw a box around the moving object. Value 'preview' makes Motion only draw a box on a saved preview jpeg image and not on the saved movie.

### locate_motion_style

- Type: String
- Range / Valid values: box, redbox, cross, redcross
- Default:

Set the look and style of the locate box if enabled.

### text_left

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

User defined text overlayed on each in the lower left corner. Use A-Z, a-z, 0-9, " / ( ) @ ~ # < > \ , . : - + _ \n and conversion specifiers

If the option is not defined no text is displayed at this position.

You can use Conversion Specifiers to define this field and also include a new line specifier as \n and spaces if this option is enclosed in quotes.

By combining spaces and new lines '\n' you can place your text anywhere on the picture. When setting the text using http remote control the text must be URL encoded. The browser does this for you. If you need to set it with a command line tool, use a browser first and let it make the encoded URL for you. Then you can copy paste it to your script file or cron line or whatever you want to use.

This is how the overlayed text is located.

| CHANGES
TEXT_LEFT | TEXT_RIGHT YYYY-MM-DD HH:MM:SS

### text_right

- Type: String
- Range / Valid values: Max 4095 characters
- Default: %Y-%m-%d\n%T

User defined text overlayed on each in the lower right corner. Use A-Z, a-z, 0-9, " / ( ) @ ~ # < > \ , . : - + _ \n and conversion specifiers

If the option is not defined no text is displayed at this position.

You can use Conversion Specifiers to define this field and also include a new line specifier as \n and spaces if this option is enclosed in quotes.

By combining spaces and new lines '\n' you can place your text anywhere on the picture. When setting the text using http remote control the text must be URL encoded. The browser does this for you. If you need to set it with a command line tool, use a browser first and let it make the encoded URL for you. Then you can copy paste it to your script file or cron line or whatever you want to use.

A major difference from text_left is that if this option is undefined the default is %Y-%m-%d\n%T which displays the date in ISO format YYYY-MM-DD and below the time in 24 hour clock HH:MM:SS.

This is how the overlayed text is located.

| CHANGES
TEXT_LEFT | TEXT_RIGHT YYYY-MM-DD HH:MM:SS

### text_changes

- Type: Boolean
- Range / Valid values: on, off
- Default: off

Turns the text showing changed pixels on/off. By setting this option to 'on' the number of pixels that changed compared to the reference frame is displayed in the upper right corner of the pictures. This is good for calibration and testing. This is how the overlayed text is located.

| CHANGES
TEXT_LEFT | TEXT_RIGHT YYYY-MM-DD HH:MM:SS

### text_event

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Default: %Y%m%d%H%M%S

This option is special in that it defines the conversion specifier %C which can be used both for text display and for filenames. This option defines the value of the special event conversion specifier %C. You can use any conversion specifier in this option except %C. Date and time values are from the timestamp of the first image in the current event. The idea is that %C can be used filenames and text_left/right for creating a unique identifier for each event. Option text_event defines the value %C which then can be used in filenames and text_right/text_left. The text_event/%C uses the time stamp for the first image detected in a new event. %C is an empty string when no event is in progress (gap period expired). Pre_captured and minimum_motion_frames images are time stamped before the event happens so %C in text_left/right does not have any effect on those images. You can use Conversion Specifiers to define this field (except for this option itself)

### text_double

- Type: Boolean
- Range / Valid values: on, off
- Default: off

Draw characters at twice normal size on images. This option makes the text defined by text_left, text_right and text_changes twice the normal size. This may be useful when using large picture formats such as 1280 x 720.

### Motion Detection

### emulate_motion

- Type: String
- Range / Valid values: on off
- Default: off

Always save images even if there was no motion

### threshold

- Type: Integer
- Range / Valid values: 1 - 2147483647
- Default: 1500

Threshold for declaring motion. The threshold is the number of changed pixels counted after noise filtering, masking, despeckle, and labelling. The 'threshold' option is the most important detection setting. When motion runs it compares the current image frame with the previous and counts the number of changed pixels after having processed the image with noise filtering, masking, despeckle and labeling. If more pixels than defined by 'threshold' have changed we assume that we have detected motion. Set the threshold as low as possible so that you get the motion you want detected but large enough so that you do not get detections from noise and plants moving. Note that the larger your frames are, the more pixels you have. So for large picture frame sizes you need a higher threshold. Use the -s (setup mode) command line option and/or the text_changes config file option to experiment to find the right threshold value. If you do not get small movements detected (see the mouse on the kitchen floor) lower the value. If motion detects too many birds or moving trees, increase the number. (Unless of course you are one of the many many users who use Motion to bird watch!) Practical values would be from a few hundred to thousands.

### threshold_tune

- Type: Boolean
- Range / Valid values: on, off
- Default: off

Activate the automatic tuning of threshold level. This feature makes Motion continuously adjust the threshold for declaring motion. The threshold setting is ignored when activating this feature. It may give different results depending on your camera, light conditions, indoor/outdoor, the motion to be detected etc. If it does not work well, deactivate the 'threshold_tune' option and use the manual setting of threshold instead.

### noise_level

- Type: Integer
- Range / Valid values: 1 - 255
- Default: 32

The noise level is used as a threshold for distinguishing between noise and motion. 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.

### noise_tune

- Type: Boolean
- Range / Valid values: on, off
- Default: on

Activates the automatic tuning of noise level. This feature makes Motion continuously adjust the noise threshold for distinguishing between noise and motion. The 'noise_level' setting is ignored when activating this feature. It may give different results depending on camera and light conditions.

### area_detect

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

Detect motion in predefined areas (1 - 9) and when Motion is detected in the area, execute the script. All of motion detection still continue. This option is only to execute the on_area_detect script.

Areas are numbered like

- 1 2 3
- 4 5 6
- 7 8 9

### mask_file

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined

The full path and filename for the masking pgm file. If needed, the mask will be resized to match the width and height of the frames being captured. If you have one or more areas of the camera image in which you do NOT want motion detected (e.g. a tree that moves in the wind or a corner of the picture where you can see cars/pedestrians passing by) you need a mask file. This file is a picture that you create in your favorite photo editing program. The areas that you want detected must be white. The error that you want ignored must be black. The pgm image must be the same size (number of pixels high and wide) as the pictures that are taken by the camera. You can adjust sensitivity by using gray tones. If you do not have a mask file disable this option by not having it in the config file or comment it out. If you are using the `rotate` option, note that the mask is applied after the rotation. Detailed Description

The mask file must be a pgm format image file (portable gray map). Note that you must choose the BINARY format.

To use this feature create an image of exact the same size as the ones you get from your camera. Then make it purely white for the areas you want detected and black for the areas you want ignored. You can also make gray areas where you want to lower the sensitivity to motion. Normally you will stick to pure black and white.

One method for generating the mask file is as follows.

Take a motion captured picture, edit it with black and white for the mask and export it as a pgm file. with a program such as gimp. If you cannot save in this format save as a grayscale jpg and then you can convert it to pgm format with

`djpeg -grayscale -pnm [inputfile] > mask.pgm`

(assuming you have djpeg installed - part of the jpeg lib package).

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)

### smart_mask_speed

- Type: Integer
- Range / Valid values: 0 - 10
- Default: 0 (disabled)

Speed for the smart mask. Default is 0 = DISABLED. 1 is slow, 10 is fast. Smartmask is a dynamic, self-learning mask. Smartmask will disable sensitivity in areas with frequent motion (like trees in the wind). Sensitivity is turned on again after some time of no more motion in this area. The built mask is a bit larger at the borders than the actual motion was. This way smartmask works more reliable when sudden moves occur under windy conditions.

Fast means here that the mask is built quick, but it is also not staying very long with no more motion. Slow means that it takes a while until the mask is built but it also stays longer. A good start value for smart_mask_speed is 5. This setting is independent from the framerate. The attack and decay time is constant over all available framerates. When smartmask is enabled and motion is also configured to either write motion-images or motion-mpegs, the current smartmask is copied as an overlay into the black/white motion-pictures/mpegs in red colour. Same thing happens to the webcam stream when Motion runs in `setup_mode`. That way you can easily adjust smart_mask_speed.

The `mask_file` option provides a static mask to turn off sensitivity in certain areas. This is very useful to mask a street with cars passing by all day long etc...

But imagine a scenario with large bushes and big trees where all the leaves are moving in the wind also triggering motion from time to time even with despeckle turned on. Of course you can also define a static mask here, but what if the bushes are growing during spring and summer? Well, you have to adapt the mask from time to time. What if the camera position moves slightly? What if someone grows new plants in your garden? You always have to setup a new static mask.

The answer to this problem is the smart mask feature A dynamic, self-learing mask.

Smart mask will disable sensitivity in areas with frequent motion (like trees in the wind). Sensitivity is turned on again after some time of no more motion in this area. The built mask is a bit larger at the borders than the actual motion. This way smartmask works more reliably when sudden moves occur under windy conditions.

### lightswitch

- Type: Integer
- Range / Valid values: 0 - 100
- Default: 0 (disabled)

Ignore sudden massive light intensity changes given as a percentage of the picture area that changed intensity. The value defines the picture areas in percent that will trigger the lightswitch condition. When lightswitch is detected motion detection is disabled for 5 picture frames. This is to avoid false detection when light conditions change and when a camera changes sensitivity at low light.

### minimum_motion_frames

- Type: Integer
- Range / Valid values: 1 - 1000s
- Default: 1

Picture frames must contain motion at least the specified number of frames in a row before they are detected as true motion. At the default of 1, all motion is detected. Valid range is 1 to thousands, but it is recommended to keep it within 1-5. Note that the picture frames are buffered by Motion and once motion is detected also the first frames containing motion are saved so you will not miss anything. The feature is used when you get many false detections when the camera changes light sensitivity or light changes. Even though Motion accepts large values you should set this to a relatively low number (below 10). For each step larger than 1 Motion reserves space in RAM for the picture frame buffer. If you have a large value Motion will miss many frames from the camera while it is processing the all the pictures in the buffer.

### event_gap

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 60

The seconds of no motion detection that triggers the end of an event. An event is defined as a series of motion images taken within a short timeframe. The value -1 is allowed and disables events causing all Motion to be written to one single movie file and no pre_capture. If set to 0, motion is running in gapless mode. Movies don't have gaps anymore. An event ends right after no more motion is detected and post_capture is over. Disabling events has bad side effects on noise_tune and smartmask. Both features can only work properly outside an event. When event_gap is set to -1, both features don't work properly anymore. 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. The timer starts after the last motion is detected and post_capture images have been saved and appended to open movie files. Any motion detected before the gap timer times out resets the gap timer so it starts counting over again. The option 'event_gap' is important. It defines how long a period of no motion detected it takes before we say an event is over. 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. Motion detected includes post_captured frames set by the 'post_capture' option. The 'gap' option defines how long a pause between detected motions that is needed to be defined as a new event. A good starting value is 60 seconds. The way 'gap' works in more technical terms is:

- A timer that timeouts 'event_gap' seconds after the last video frame with motion is detected.
- If 'post_capture' is activated then the gap timer starts counting after the last image of the post_capture buffer has been saved.
- The gap timer is reset and starts all over each time new motion is detected, so you will not miss any action by having a short 'gap' value. It will just create more events (e.g. more mpegs files)

The gap value impacts many functions in Motion.

- When the timer runs out the event number is increased by one next time motion is detected. When you use the %v conversion specifier in filenames or text features this means that the number in filename or text increased by one.
- The pre_capture feature only works at the beginning of an event. So if you have a very large 'event_gap' value pre_capture is not working very often.
- When you make movies using the ffmpeg features a new movie file is started at the beginning of an event when the first motion is detected. When 'event_gap' seconds has passed without motion (and post_captured frames saved) the movie files are completed and closed.
- Do not use large event_gap values to generate one large movie file. If Motion stops working this movie file never gets properly completed and closed you will not be able to view it.
- Some of the tracking features sets the camera back to the center position when an event is over.

Note that 'event_gap' and 'minimum_gap' have nothing to do with each other.

### Script Execution

Motion can execute external commands based on the motion detection and related events. They are described in the sections below.

Security Warning!

These features mean you have to pay attention to the following.

- Anyone with access to the remote control port (http) can execute any command on your computer with the same privileges as the user running Motion. Anyone can access your control port if you have not either limited access to localhost or limited access using firewalls in the server. You should always have a router between a machine running Motion with remote control enabled and the Internet and make sure the Motion control port is not accessible from the outside.
- If you limit control port to localhost you still need to take care of any user logging into the server with any kind of GUI or terminal session. All it takes is a browser or single command line execution to change settings in Motion.
- It is a good idea to run Motion as a harmless user. Not as root!!

### on_event_start

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Default: Not defined

The full path and file name of the program/script to be executed at the start of an event. An event starts at first motion detected after a period of no motion defined by gap.

You can use Conversion Specifiers and spaces as part of the command. This can be any type of program or script. Remember to set the execution bit in the ACL and if it is a script type program such as perl or bash also remember the shebang line (e.g. #!/user/bin/perl) as the first line of the script.

### on_event_end

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined

The full path and file name of the program/script to be executed when a event ends. An event ends after the event_gap has expired.

You can use Conversion Specifiers and spaces as part of the command. This can be any type of program or script. Remember to set the execution bit in the ACL and if it is a script type program such as perl or bash also remember the shebang line (e.g. #!/user/bin/perl) as the first line of the script.

### on_picture_save

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined

The full path and file name of the program/script to be executed when a picture is saved.

You can use Conversion Specifiers and spaces as part of the command. This can be any type of program or script. Remember to set the execution bit in the ACL and if it is a script type program such as perl or bash also remember the shebang line (e.g. #!/user/bin/perl) as the first line of the script.

Use %f for passing filename (with full path) to the command.

### on_motion_detected

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined

The full path and file name of the program/script to be executed when motion is detected.

You can use Conversion Specifiers and spaces as part of the command. This can be any type of program or script. Remember to set the execution bit in the ACL and if it is a script type program such as perl or bash also remember the shebang line (e.g. #!/user/bin/perl) as the first line of the script.

### on_area_detected

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

The full path and file name of the program/script to be executed when motion is detected in the predefined area indicated in the area_detect option.

You can use Conversion Specifiers and spaces as part of the command. This can be any type of program or script. Remember to set the execution bit in the ACL and if it is a script type program such as perl or bash also remember the shebang line (e.g. #!/user/bin/perl) as the first line of the script.

### on_movie_start

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined

The full path and file name of the program/script to be executed when a new movie is being created.

You can use Conversion Specifiers and spaces as part of the command. This can be any type of program or script. Remember to set the execution bit in the ACL and if it is a script type program such as perl or bash also remember the shebang line (e.g. #!/user/bin/perl) as the first line of the script.

Use %f for passing filename (with full path) to the command.

### on_movie_end

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined

The full path and file name of the program/script to be executed after a new movie was created.

You can use Conversion Specifiers and spaces as part of the command. This can be any type of program or script. Remember to set the execution bit in the ACL and if it is a script type program such as perl or bash also remember the shebang line (e.g. #!/user/bin/perl) as the first line of the script.

Use %f for passing filename (with full path) to the command.

### on_camera_lost

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

The full path and file name of the command to be executed when a camera can't be opened or if it is lost Note that there are situations when motion doesn't detect a lost camera. It is dependent upon the camera and driver and it is advised that this option be tested for each configuration. It has also been observed that there are also situations in which the disconnection of the camera even hangs the PC in which case this script will not be executed.

You can use Conversion Specifiers and spaces as part of the command. This can be any type of program or script. Remember to set the execution bit in the ACL and if it is a script type program such as perl or bash also remember the shebang line (e.g. #!/user/bin/perl) as the first line of the script.

### Output - General Options

### quiet

- Type: Boolean
- Range / Valid values: on, off
- Default: off

Be quiet, don't output beeps when detecting motion. Only works in non-daemon mode.

### pre_capture

- Type: Integer
- Range / Valid values: 0 - 100s
- Default: 0 (disabled)

Specifies the number of pre-captured (buffered) pictures from before motion was detected that will be output at motion detection. The recommended range is 0 to 5. It is not recommended to use large values. Large values will cause Motion to skip video frames and cause unsmooth movies. To smooth movies use larger values of post_capture instead.

Motion buffers the number of picture frames defined by 'pre_capture'. When motion is detected the pictures in the buffer are included in the movie. The effect is that it seems the program knew in advance that the event was going to take place and started the recording before it actually happened. This is a nice feature that give more complete video clips of an event.

If pre_capture is set to 0 the feature is disabled. The recommended value would be approx 0.5 second of video so the value should be defined so it fits the framerate and the desired pre-capture time. You can in theory have up to 100s of pre-captured frames but naturally this makes motion leave a larger footprint in the memory of the computer.

More important Motion is processing all the buffered images including saving jpegs, encoding the movie, writing to databases and executing external programs after the first image is detected as Motion.

Motion will not grab another image until this is done. This means that even moderate values for pre_capture combined with high framerates will mean that you will probably miss many frames of Motion.

It is therefore recommended to use relatively small values for pre_capture. Depending on your chosen framerate and depending on the features enabled values from 1-5 are sensible.

If you wish to create a smooth movie during events using large pre_capture values will do the opposite! It will create a long pause where a lot of action is missed.

To get a smooth movie use a large value for `post_capture` which does not cost any performance hit or RAM space.

### post_capture

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0 (disabled)

Specifies the number of frames to be captured after motion has been detected. 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).. This option is the preferred way to create continuous movies. Post_capture does not consume extra RAM and it does not create pauses in the movie even with large values. If you only store movies and do not have output_normal on, then the recommended post_capture value is what is equivalent to 1-5 seconds of movie.

### target_dir

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined = current working directory

The full path for the target directory for picture and movie files to be saved. The default is the current working directory. This is the target directory for all snapshots, images files and movie files. You will normally always want to specify this parameter as an absolute path.

Note that the file name options are all saved relative to this target_dir This means in principle that you can specify target_dir as '/' and be 100% flexible. But this is NOT recommended. It is recommended that this directory be specified as deep as possible.

### Output - Picture Options

Motion can output different types of pictures. The normal picture is indicated below.

The motion type picture or also referred to as a debug picture is shown below. Note that the largest area is blue and only this is counted as Motion.

The Motion image shows how Motion maintains a "reference frame" which is not just the last picture frame but a mathematical calculation of the past images. This enlarges real Motion and ensures that it is not easy to sneak in slowly.

### output_pictures

- Type: Discrete Strings
- Range / Valid values: on, off, first, best
- Default: on

This option controls the output of the normal image.

'on' is the usual selection.

If you set the value to 'first' Motion saves only the first motion detected picture per event. If you set it to "best" Motion saves the picture with most changed pixels during the event. This may be useful if you store movies on a server and want to present a jpeg to show the content of the movie on a webpage.

"best" requires a little more CPU power and resources compared to "first".

'off' to don't write pictures

### output_debug_pictures

- Type: Boolean
- Range / Valid values: on, off
- Default: off

Output pictures with only the moving object. This feature generates the special motion type movies where you only see the pixels that changes as a graytone image. If labelling is enabled you see the largest area in blue.

If a Smartmask is specified, it is shown in red.

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 these motion images. Motion pictures are stored the same place and with the same filename as normal motion triggered pictures except they have an "m" appended at the end of the filename before the .jpg or .ppm. E.g. the name can be 01-20020424232936-00m.jpg.

### quality

- Type: Integer
- Range / Valid values: 1 - 100
- Default: 75

The quality for the jpeg images in percent. 100 means hardly compressed. A small number means a much smaller file size but also a less nice quality image to look at.

### picture_type

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

This option specifies the type of picture file to output. The recommendation is to always use jpg except if you have a specific need to store high quality pictures without any quality loss.

### snapshot_interval

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0 (disabled)

This parameter specifies the number of seconds between each snapshot

### snapshot_filename

- Type: String
- Range / Valid values: Max 4095 characters
- Default: %v-%Y%m%d%H%M%S-snapshot

This option indicates the file name and optionally the path for the snapshots (jpeg or ppm) relative to target_dir.

The file extension .jpg or .ppm is automatically added.

A symbolic link called lastsnap.jpg (or lastsnap.ppm) is created in the target_dir and will always point to the latest snapshot, unless snapshot_filename is exactly 'lastsnap'

You can use Conversion Specifiers in this option.

### picture_filename

- Type: String
- Range / Valid values: Max 4095 characters
- Default: %v-%Y%m%d%H%M%S-%q

This option indicates the file name and optionally the path for the pictures (jpeg or ppm) relative to target_dir.

The file extension .jpg or .ppm is automatically added.

You can use Conversion Specifiers in this option.

### exif_text

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

Use this option to specify the text to include in a JPEG EXIF comment The EXIF timestamp is included independent of this text.

You can use Conversion Specifiers in this option.

### Output - Movie Options

### max_movie_time

- Type: Integer
- Range / Valid values: 0 (infinite) - 2147483647
- Default: 3600

The maximum length of a movie in seconds. Set this to zero for unlimited length.

### ffmpeg_output_movies

- Type: Boolean
- Range / Valid values: on, off
- Default: off

Use ffmpeg libraries to encode movies of the motion. This option generates a new movie at the beginning of each new event and appends to the movie for each motion detected within the same event. The current event ends when the time defined by the 'event_gap' option has passed with no motion detected. At the next detection of motion a new movie is started.

To use this feature you need to install ffmpeg or Libav.

### ffmpeg_output_debug_movies

- Type: Boolean
- Range / Valid values: on, off
- Default: off

Use ffmpeg libraries to encode motion type movies where you only see the pixels that changes. Works like ffmpeg_output_movies but outputs motion pixel type pictures instead. This feature generates the special motion type movie where you only see the pixels that changes as a graytone image. If labeling is enabled you see the largest area in blue. Smartmask is shown in red. The filename given is the same as the normal movies except they have an 'm' appended after the filename.

### ffmpeg_timelapse

- Type: Boolean
- Range / Valid values: 0 - 2147483647
- Default: 0 (disabled)

Create a timelapse movie saving a picture frame at the interval in seconds set by this parameter.

### ffmpeg_timelapse_mode

- Type: Discrete Strings
- Range / Valid values: hourly, daily, weekly-sunday, weekly-monday, monthly, manual
- Default: daily

The file rollover mode of the timelapse video. Note that it is important that you use the conversion specifiers in ffmpeg_filename that ensure that the new timelapse file indeed is a new file. If the filename does not change Motion will simply append the timelapse pictures to the existing file. The value 'Manual' means that Motion does not automatically rollover to a new filename. You can do it manually using the http control interface by setting the option 'ffmpeg_timelapse' to 0 and then back to your chosen value. Value 'hourly' rolls over on the full hour. Value 'daily' which is the default rolls over at midnight. There are two weekly options because depending on where you come from a week may either start on Sunday or Monday. And 'monthly' naturally rolls over on the 1st of the month.

### ffmpeg_bps

- Type: Integer
- Range / Valid values: 0 - 9999999
- Default: 400000

Bitrate of movies produced by ffmpeg. Bitrate is bits per second. Higher value mans better quality and larger files if the camera is on a fixed bitrate setting. Experiment to get the desired quality. The better quality the bigger files. This option is ignored if ffmpeg_variable_bitrate is not 0 (disabled).

### ffmpeg_variable_bitrate

- Type: Integer
- Range / Valid values: 0 - 100
- Default: 0 (disabled)

Enables and defines variable bitrate for the ffmpeg encoder. The option of ffmpeg_bps is ignored if variable bitrate is enabled. A value of 0 disables this option while values 1 - 100 varies the quality of the movie. The value of 1 means worst quality and 100 is the best quality.

Experiment for the value that gives you the desired compromise between size and quality.

### ffmpeg_video_codec

- Type: Discrete Strings
- Range / Valid values: mpeg1, mpeg4, msmpeg4, swf, flv, ffv1, mov, ogg, mp4, mkv, hevc
- Default: mpeg4

Codec to be used by ffmpeg for the video compression.

Timelapse videos have two options.

- mpg - Creates mpg file with mpeg-2 encoding. If motion is shutdown and restarted, new pics will be appended to any previously created file with name indicated for timelapse.
- mpeg4 - Creates avi file with the default encoding. If motion is shutdown and restarted, new pics will create a new file with the name indicated for timelapse.

Movie files have the following options

- mpeg4 or msmpeg4 - gives you files with extension .avi
- 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
- mov - QuickTime
- ogg - Ogg/Theora
- mp4 - MPEG-4 Part 14 H264 encoding
- mkv - Matroska H264 encoding
- hevc - H.265 / HEVC (High Efficiency Video Coding)

### ffmpeg_duplicate_frames

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

If the CPU can not keep up with the requested frame rate for the movies, should frames be duplicated in order to keep up or should it be skipped.

### movie_filename

- Type: String
- Range / Valid values: Max 4095 characters
- Default: %v-%Y%m%d%H%M%S

File path for motion triggered movies relative to target_dir. Note that the file extension is automatically added to the name based upon the codec selected.

You can use Conversion Specifiers in this option.

### timelapse_filename

- Type: String
- Range / Valid values: Max 4095 characters
- Default: %v-%Y%m%d-timelapse

File path for the timelapse movies relative to target_dir. Note that the file extension is automatically added to the name based upon the codec selected.

You can use Conversion Specifiers in this option.

### Output - Pipe Options

The video4linux driver is written by the same author that first created Motion. You can find the source within apt packages.

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 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.

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

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.

Download the latest via the apt packages and place the file in a place of your own choice.

Untar and uncompress the file to the place you want the program installed. Editor recommends /usr/local/vloopback.

`cd /usr/local`

`tar -xvzf /path/to/vloopback-1.1-rc1.tar.gz`

You now have a directory called vloopback-1.1-rc1. You can rename it to vloopback (mv vloopback-1.1-rc1 vloopback). I recommend creating a symbolic link to the current version. This way you can more easily experiment with different versions simply by changing the link.

`ln -s vloopback-1.1-rc1 vloopback`

Now change to the new directory

`cd vloopback`

Build the code

`make`

There is a good chance that the make will not work and give you a long list of errors. To run make the following must be available on you machine.

- The kernel source files must be installed.
- The source files must be available at /usr/src/linux.
  E.g. the new Red Hat 7.3 does not have a link to the sources called linux. Instead there is a link called linux-2.4. This is easy to fix. Just create a link to the real source tree. Do not rename! Add a link using this command (replacing the kernel version number with the one you have on your machine)
  `ln -s /usr/src/linux-2.4.18-4 /usr/src/linux`
- Alternatively you can change the vloopback makefile so that the "LINUXSRC=/usr/src/linux" line is changed to the actual path. I recommend the link solution since this may solve other similar problems that you can get when installing other software.

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>`

Install the code you built as a Kernel module. There are two options: pipes should be set to the number of video loopbacks that you want. Probably one for each camera. The dev_offset defines which video device number will be the first. If dev_offset is not defined the vloopback module will install itself from the first available video device. If you want the cameras to be assigned to the lower video device numbers you must either load vloopback after loading the video device modules OR use the dev_offset option when loading vloopback. Vloopback then installs itself in the sequence input 0, output 0, input 1, output 1, input 2, output 2 etc. Here is shown the command for our example of 4 cameras and 4 loopback devices and the first loopback device offset to /dev/video4.

`/sbin/insmod /usr/local/vloopback/vloopback.o pipes=4 dev_offset=4`

When you run the command you may get a warning about tainting the Kernel. Just ignore this. You can choose to copy the vloopback.o file into a directory in the /lib/modules tree where the insmod/modprobe programs are already looking for modules. Then the command gets simpler (/sbin/insmod vloopback pipes=.....).

If you want the loopback device to load during boot, you can place the call in one of the bootup scripts such as /etc/rc.d/rc.local. Vloopback should be loaded before you start motion.

To activate the vloopback device in motion set the 'video_pipe' option in the motion.conf file. You can also view the special motion pictures where you see the changed pixels by setting the option 'motion_video_pipe' in motion.conf. When setting the video_pipe and/or motion_video_pipe options either specify the input device as e.g. /dev/video4. You can also set the parameter to '-' which means that motion will find the first vacant video loopback device input. If you have more than one camera you may want to control which loopback device each camera uses. Then you need to define the specific device name in motion.conf for the first camera and in each camera config file for the other cameras. If you set the video_pipe parameter to '-' in the motion.conf file and not setting it in the camera config files, motion automatically assign video devices in the same sequence as the camera config files are loaded. You can combine both video_pipe and motion_video_pipe but then naturally you will need twice as many pipes.

De-activating should be done with this command

`/sbin/modprobe -r vloopback`

### video_pipe

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

if a dash '-' is given motion will use /proc/video/vloopback/vloopbacks to locate a free pipe. Default: not set 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.

### motion_video_pipe

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not defined

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

### use_extpipe

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

This option specifies whether to send the output to a pipe for external encoding into a movie.

Piping raw video to stdout has some advantages comparing to using built-in ffmpeg encoder. First, this way you can use any encoder that supports RAW frames from stdin so you are not limited to the formats that are currently implemented in motion. See examples in extpipe Second, external encoder utilizes separate cpu core on a multi-core system so movie encoding is offloaded from main motion thread to a separate core(s) giving noticeable performance boost

Note that this option does not require the install or configure of the videoloop back

### extpipe

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

This option specifies the program name and options for the program that will receive and process the images during a movie event.

Note that this option does not require the install or configure of the videoloop back

Sample:

extpipe mencoder -demuxer rawvideo -rawvideo w=%w:h=%h:i420 -ovc x264 -x264encopts bframes=4:frameref=1:subq=1:scenecut=-1:nob_adapt:threads=1:keyint=1000:8x8dct:vbv_bufsize=4000:crf=24:partitions=i8x8,i4x4:vbv_maxrate=800:no-chroma-me -vf denoise3d=16:12:48:4,pp=lb -of avi -o %f.avi - -fps %fps

extpipe x264 - --input-res %wx%h --fps %fps --bitrate 2000 --preset ultrafast --quiet -o %f.mp4

extpipe mencoder -demuxer rawvideo -rawvideo w=%w:h=%h:fps=%fps -ovc x264 -x264encopts preset=ultrafast -of lavf -o %f.mp4 - -fps %fps

extpipe ffmpeg -y -f rawvideo -pix_fmt yuv420p -video_size %wx%h -framerate %fps -i pipe:0 -vcodec libx264 -preset ultrafast -f mp4 %f.mp4

### Steam and Webcontrol

Motion has simple webcam server built in. The server can be configured to stream both the images as well allow for a very basic http control of these Motion parameters.

Each camera can have its own stream and it is enabled by specifying the port number. If there are multiple cameras, each camera must have its own unique port number.

The webserver generates a stream in "multipart jpeg" format (mjpeg). Some browsers can not display images fed in this method. Alternatives are being considered for implementation within Motion to resolve this limitation. The most straight forward around this limitation is to create a local HTML page that references the raw stream.

Open up a text editor and paste in the following. `<html> <body bgcolor=000000> <img src=http://yourmotionpc:yourstreamport/ border="0" width=25%></a> </body> </html>`

Change the yourmotionpc with the IP or name of the computer running Motion. Also revise the port number to be the one referenced for the stream.

Save the file and then open it in your browser.

It may also be possible to view the stream via regular stream players such as VLC, mplayer, ffplay, avplay, etc. by specifying the network stream as `http://localhost:myportnumber/stream.mjpg`

Motion can be remote controlled via a simple http interface.

Most Motion configuration options can be changed while Motion is running except options related to the size of the captured images and mask files which are loaded only when Motion starts.

The most obvious tool to use to remote control Motion is any web browser. All commands are sent using the http GET method which simply means that the information is sent via the URL and maybe a query string. You can use any browser (Firefox, Mozilla, Internet Explorer , etc). You can also use the text based browser lynx to control Motion from a console. It navigates fine through the very simple and minimalistic http control interface of Motion.

But it is probably simpler to connect to the control port with a browser, navigate to the function you want, and copy the URL from the browser URL entry line. If your `webcontrol_port` is 8080 and you browse from the same machine on which Motion runs simply look up http://localhost:8080/ and navigate around. Connecting from a remote machine is done by using a domain name (example http://mydomain.com:8080/) or the IP address of the machine (example http://192.168.1.4:8080/). The option `webcontrol_localhost` must be off to allow connection from a remote machine.

If you want to use a script or cron to automatically change Motion settings while Motion runs you use a program that can fetch a webpage. We simply just throw away the html page that Motion returns. Programs commonly available on Linux machines are wget and lwp-request. Here is an example of how to start and stop motion detection via cron. These two lines are added to /etc/crontab.

    0 9 * * * root /usr/bin/lwp-request http://localhost:8080/0/detection/start > /dev/null
    0 18 * * * root /usr/bin/lwp-request http://localhost:8080/0/detection/pause > /dev/null

If you want to use the http remote control from your own software (for example your own PHP front end) you can set the new motion.conf option html_output off. Then Motion answers back with very basic text only and no html around it.

To remote control Motion from a web pages you can for example use PHP. In PHP it takes this simple code line to send a remote commend to Motion. Here we pause motion detection for camera 2

`readfile('http://localhost:8080/2/detection/pause');`

ALERT! Security Warning! This feature also means you have to pay attention to the following.

- Anyone with access to the remote control port (http) can alter the values of any options and save files anywhere on your server with the same privileges as the user running Motion. They can execute any command on your computer with the same privileges as the user running Motion. Anyone can access your control port if you have not either limited access to localhost or limited access using firewalls in the server. You should always have a router between a machine running Motion with remote control enabled and the Internet and make sure the Motion control port is not accessible from the outside.
- If you limit control port to localhost you still need to take care of any user logging into the server with any kind of terminal session.
- Run Motion as a harmless user. DO NOT RUN AS ROOT!!

### ipv6_enabled

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

# Listen to IPv6 localhost instead of IPv4 (default: off)

### stream_port

- Type: Integer
- Range / Valid values: 0 - 65535
- Default: 0 (disabled)

# The mini-http server listens to this port for requests (default: 0 = disabled) TCP port on which motion will listen for incoming connects with its webcam server. Note that each camera must have its own unique port number and it must also be different from the control_port number. A good value to select is 8081 for camera 1, 8082 for camera 2, 8083 for camera 3 etc etc. This must be placed in motion.conf and not in a camera config file.

### stream_quality

- Type: Integer
- Range / Valid values: 1 - 100
- Default: 50

Quality setting in percent for the mjpeg picture frames transferred over the webcam connection. Keep it low to restrict needed bandwidth. The mjpeg stream consists of a header followed by jpeg frames separated by content-length and boundary string. The quality level defines the size of the individual jpeg pictures in the mjpeg stream. If you set it too high you need quite a high bandwidth to view the stream.

### stream_motion

- Type: Boolean
- Range / Valid values: on, off
- Default: off

When set to 'on' slow down the stream to 1 picture per second when no motion is detected. When motion is detected the stream runs as defined by stream_maxrate When 'off' the stream always runs as defined by stream_maxrate. Use this option to save bandwidth when there is not anything important to see from the camera anyway.

### stream_maxrate

- Type: Integer
- Range / Valid values: 1 - 100
- Default: 1

Limit the framerate of the stream in frames per second. Set the value to 100 for practically unlimited. Don't set this parameter too high unless you only use it on the localhost or on an internal LAN.

### stream_localhost

- Type: Boolean
- Range / Valid values: on, off
- Default: on

Limits the access to the stream to the localhost. By setting this to on, the stream can only be accessed on the same machine on which Motion is running.

### stream_limit

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

This parameter limits the maximum number of images per connection and is determined by multiplying actual stream rate by desired number of seconds

### stream_auth_method

- Type: Integer
- Range / Valid values: 0 to 2
- Default: 0

This parameter establishes desired authentication method for the stream and web control ports. The parameters have the following meaning.

- 0 = disabled
- 1 = Basic authentication
- 2 = MD5 digest (the safer authentication)

Note that if you are enabling the webcontrol feature of Motion, you really really really ... should enable security authentications. No. Seriously. You really should. See the security warnings in this document regarding how it completely opens up your system.

### stream_authentication

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not Defined

This parameter establishes the username and password to use for the stream. The syntax is username:password

### stream_preview_scale

- Type: Integer
- Range / Valid values:
- Default: 25

If the webcontrol page has HTML enabled, Motion displays all of the streams on the home webcontrol page in HTML format so that all the images can be viewed by standard browsers.

This parameter indicates the percentage to scale the stream image when it is placed on the page. Numbers greater than 100 are permitted.

### stream_preview_newline

- Type: string
- Range / Valid values:on / off
- Default: on

If the webcontrol page has HTML enabled, Motion displays all of the streams on the home webcontrol page in HTML format so that all the images can be viewed by standard browsers.

This parameter determines whether the image is placed on a new line in the webcontrol web page.

Preview images are placed on to the webcontrol home page in camera id number order. This This parameter allows the user some flexibility in organizing the images on the page.

Setting this parameter to off will set the image to the right of any image from a lower numbered thread number. Setting it to 'on' will place the image on the start of the next line(below).

Full customization of the webcontrol page is NOT planned in the Motion development. Users that require a more polished and customized preview page are encouraged to create their own local HTML page that references the streams.

### webcontrol_port

- Type: Integer
- Range / Valid values: 0 - 65535
- Default: 0 (disabled)

Sets the port number for the http based control of the Motion parameters. This option must be placed in the motion.conf file and not in a camera config file. Port numbers below 1024 normally require that you have root privileges. The port 8080 is the typical selection of the port for this purpose.

### webcontrol_localhost

- Type: Boolean
- Range / Valid values: on, off
- Default: on

This option restricts the control of the Motion parameters to the localhost. This option must be placed in motion.conf and not in a camera config file. By setting this to on, the control using http (browser) can only be accessed on the same machine on which Motion is running.

### webcontrol_html_output

- Type: Boolean
- Range / Valid values: on, off
- Default: on

Enable HTML in the answer sent back to a browser connecting to the webcontrol_port. This option must be placed in motion.conf and not in a camera config file. The recommended value for most is "on" which means that you can navigate and control Motion with a normal browser. By setting this option to "off" the replies are in plain text which may be easier to parse for 3rd party programs that control Motion.

### webcontrol_authentication

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

This parameter establishes the username and password to use for the stream. The syntax is username:password

### Database

Motion can be compiled with MySQL, PostgreSQL or SQLite3 database support. When enabled Motion can be configured to add a record to a table in the database as specified by the sql_query. The query can contain the fields that are used and the value are given by using conversion specifiers for dynamic data like filename, time, number of detected pixels etc. Motion does not place any binary images in the database and it cannot remove old records.

Motion only adds records to the database when files are created. The database contains records of saved files which means to get a record in the database the feature that enables for example motion detection, timelapse, snapshots etc must be enabled. The sql_log options defines which types of files are logged in the database.

The following are sample create table queries for different databases.

Mysql : CREATE TABLE security (camera int, filename char(80) not null, frame int, file_type int, time_stamp timestamp(14), event_time_stamp timestamp(14));

Postgresql : CREATE TABLE security (camera int, filename char(80) not null, frame int, file_type int, time_stamp timestamp without time zone, event_time_stamp timestamp without time zone);

### sql_log_picture

- Type: Boolean
- Range / Valid values: on, off
- Default: on

Log to the database when a motion triggered image file is created.

### sql_log_snapshot

- Type: Boolean
- Range / Valid values: on, off
- Default: on

Log to the database when creating a snapshot image file.

### sql_log_movie

- Type: Boolean
- Range / Valid values: on, off
- Default: off

Log to the database when creating motion triggered movie file.

### sql_log_timelapse

- Type: Boolean
- Range / Valid values: on, off
- Default: off

Log to the database when creating timelapse movie file

### sql_query

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not Defined

SQL query string that is sent to the database when the sql_log_* item is triggered.

You can use Conversion Specifiers within the query.

Sample Query

insert into security(camera, filename, frame, file_type, time_stamp, text_event) values('%t', '%f', '%q', '%n', '%Y-%m-%d %T', '%C') insert or ignore into images (camera_nbr, file_name, year, month, day, hour, minute) values (8, '%f', '%Y','%m','%d','%H','%M')

### database_type

- Type: String
- Range / Valid values: mysql, postgresql, sqlite3
- Default: Not Defined

This option specifies the database type.

### database_dbname

- Type: String
- Range / Valid values: Max 4095 characters
- Default: Not Defined

The name of the database. For Sqlite3, the full path and name to the database.

### database_host

- Type: String
- Range / Valid values: Max 4095 characters
- Default: localhost

The host on which the database is located

### database_user

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

The user account name for database

### database_password

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

The user password for database

### database_port

- Type: Integer
- Range / Valid values:
- Default:

The port number that is used for the database. Typical values are: mysql=3306 and postgresql=5432

### database_busy_timeout

- Type: Integer
- Range / Valid values:
- Default: 0

If the database is busy when the request is issued, this parameter indicates the time to wait before issuing a timeout message.

### Tracking

This is still at the experimental stage.

Motion can move the camera to a fixed position given in degrees pan (left-right) and tilt (down-up). Movement can be set with absolute coordinates or relative to current position. There is also an auto tracking feature for the Logitech Quickcam Sphere/Orbit but it is not very mature. Search the Motion home website or community development pages for additional information regarding tracking if these features are required.

### track_type

- Type: Discrete Strings
- Range / Valid values: 0 (none), 1 (stepper), 2 (iomojo), 3 (pwc), 4 (generic), 5 (uvcvideo)
- Default: 0 (None)

Type of tracker.

Motion has special tracking options which use either a serial stepper motor controller, an iomojo smile cam or a Philips WebCam driver compatible pan/tilt camera such as the Logitech Quickcam Sphere or Orbit.

To disable tracking, set this to 0 and the other track options are ignored.

Value 1 is for the special Motion Tracking project using a stepper motor and a home made controller.

Value 2 is for the iomojo smilecam

Value 3 is for pwc type USB tracking cameras such as the Logitech Quickcam Sphere/Orbit which is driven by the pwc (Philips WebCam) driver. To use this camera your version of pwc must be at least 8.12.

Value 4 is the generic track type. Currently it has no other function than enabling some of the internal Motion features related to tracking.

Value 5 is for uvcvideo type USB tracking cameras such as the Logitech Quickcam Sphere/Orbit MP which is driven by the uvcvideo driver.

### track_auto

- Type: Boolean
- Range / Valid values: on, off
- Default: off

Enable auto tracking Requires a tracking camera type supported by Motion.

### track_port

- Type: String
- Range / Valid values: Max 4095 characters
- Default:

This is the device name of the serial port to which the stepper motor interface is connected. Only used for stepper motor tracking.

### track_motorx

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

The motor number that is used for controlling the x-axis. Only used for stepper motor tracking.

### track_motorx_reverse

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

Description

### track_motory

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

The motor number that is used for controlling the y-axis. Only used for stepper motor tracking.

### track_motory_reverse

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

### track_maxx

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

The maximum position for servo x. Only used for stepper motor tracking.

### track_minx

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

### track_maxy

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

The maximum position for servo y. Only used for stepper motor tracking.

### track_miny

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

### track_homex

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

### track_homey

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

### track_iomojo_id

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

Use this option if you have an iomojo smilecam connected to the serial port instead of a general stepper motor controller. Only used for iomojo camera.

### track_step_angle_x

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

Angle in degrees the camera moves per step on the X-axis with auto tracking. Currently only used with pwc type cameras. Requires a tracking camera type pwc.

### track_step_angle_y

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

Angle in degrees the camera moves per step on the Y-axis with auto tracking. Currently only used with pwc type cameras. Requires a tracking camera type pwc.

### track_move_wait

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

Delay during which tracking is disabled after auto tracking has moved the camera. Delay is defined as number of picture frames. The actual delay is depending on the chosen framerate. If you want the camera to move maximum once every 2 seconds and the framerate is 10 then you need to set the track_move_wait value to 2 * 10 = 20.

### track_speed

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

Speed to set the motor to. Only used for stepper motor tracking.

### track_stepsize

- Type: Integer
- Range / Valid values: 0 - 2147483647
- Default: 0

Number of steps to make. Only used for stepper motor tracking.