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 is made for the Linux operating system.

Motion is a command line based tool. It has absolutely no graphical user interface. Everything is setup via a set of configuration files (simple text files that can be edited by any plain text editor).

Motion can output either image files of the picture frames containing motion or movie files showing the entire event. Motion can also invoke other programs when motion is detected.

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, you are encouraged 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 bug-fixes 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

To get motion you have different options. To get the latest and greatest version you can direct your browser to the Motion project on Github and download the latest sources.

For many major Linux distributions you will also be able to find Motion in the software repositories.

On the Download Files page you will find a links to the latest stable version both as sources and binaries for some of the most popular Linux distributions

Motion was originally written by Jeroen Vreeken. He was succeded by Folkert van Heusden, and from version 3.1.12, Motion was managed by Kenneth Lavrsen. The actual programming was done by a large group of contributors. From 2016 Kenneth Lavrsen handed over the program ownership and maintenance to Mr. Dave.

For support we encourage you to join the mailing list instead of writing to the project developers. We are all very active on the mailing list and by using the mailing list much more users will have benefit of the answers. Newbies and stupid questions are welcome on the list. Contributions in the form of patches are also very welcome on the mailing list. If you are on Github you are also welcome to submit pull requests.

Which version to download and use?

As of August 2016 the recommended version of Motion version is the latest develop code from Motion project on Github. There is currently a pre-release of version 3.4.1 available on Github release 3.4.1 and soon a release 4.0.0 will be released to mark that the project has fresh resources and a new Github repository.

Soon the versions of Motion will hit the repositories of various distributions.

What features does Motion have?

The list is long but the main features are

Taking inputs from multiple video devices at the same time incl network cameras

Saving pictures when the video signal from a camera contains motion

Create movie files containing the event in which the motion occurred

Execute external program when detecting movement

Execute external program at the beginning of an event of several motion detections.

Execute external program at the end of an event of several motion detections.

High configurable definition of path and file names of the stored images and films.

Other operating systems than Linux

Motion can be compiled on other operating systems than Linux but not all features will be supported. Motion has been compiled on FreeBSD and MacOS. These platforms however have had only limited testing.

The default motion.conf file (motion-dist.conf) that comes with the package.

Supported Hardware

Input devices: Here we are thinking about the cameras.

Motion supports video input from two kinds of sources.

Standard video4linux devices (e.g. /dev/video0) and network cameras. 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.

If you use use a Logitech Quickcam Orbit or Sphere using the driver pwc/pwcx and kernel 2.6.X you should replace the file in the Motion sources called pwc-ioctl.h with the one that comes with the your pwc version. Motion is shipped with 3 versions of pwc-ioctl.h-VERSION. Rename the one that fits your major pwc version number best to pwc-ioctl.h (after renaming the current to something else). There has been some small adjustments in the API that requires that you have the right header file.

Motion is mainly distributed as source files that you must compile yourself. There is also an RPM made on Fedora Core 3. And Debian packages are available for selected versions.

The short overview of the steps to install Motion from sources.

Preparation: Motion uses a number of shared libraries that must be installed on your computer before you can build Motion. The needed shared libraries depends on the features you wish to use. Features network camera, ffmpeg, MySQL and PostgreSQL needs specific shared libraries installed. See preparation section for more information.

Download the motion source files (distributed as tar'ed and compressed files). 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 placing the motion source file directory in /usr/local. If you do not have write access to the /usr/local directory (you are under the mercy of an ignorant system administrator with a severe case of paranoia) - you can install the program in a directory in your home directory. You will then need to read the next section about how to configure before you compile the program. Below is shown the exact commands using version 3.2.X installed in /usr/local as an example (replace /path/to and version number with the actual placement of the tar.gz file).

cd /usr/local
tar -xvzf /path/to/motion-3.2.X.tar.gz

You will now have created a directory called motion-3.2.X. You can rename it to motion (mv motion-3.1.X motion). I recommend creating a symbolic link to the current version. This way you can more easily experiment with different version simply by changing the link.

ln -s motion-3.2.X motion

Now change to the new directory.

cd motion

Run configure. You can start with the defaults. If you need to modify the installation parameters you can read the next section.

./configure

Build the code

make

Install the code, manual page, etc

make install

In /etc/motion/etc you will find a file called motion-dist.conf. If it is the first time you install Motion - rename this file to motion.conf and edit as a minimum the settings: videodevice, input, norm, frequency, width, height and target_dir. That should get you going.

Run the program. To enable more features you must modify the config file.

motion

Installation on Debian based distributions

Motion can be found in the repositories of several debian based distributions such as Ubuntu etc.

Open up a terminal window and type:

sudo apt-get install motion

The debian packages install the Motion config file in /etc/motion/motion.conf which is the correct location when Motion runs as a daeson under a system user. If you want to run Motion under your own username you need to 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.)

sudo cp /etc/motion/motion.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. Change directory to the location of the motion.conf and run

sudo nano motion.conf

After you you have done so, start motion in the terminal simply by typing:

Note: If you're using SuSE 9.2, you might want to ADDITIONALLY have a look at Compiling on SuSE 9.2. As mentioned on that page as well, you will still need to read the instructions here as well.

Before you start you may need to install a number of shared libraries that Motion uses. If they are missing the feature will simply normally not be included. Most of these libraries can be found on the CDs of your distribution. A few will have to be downloaded from the Internet. Note that 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 other programs from source that uses these pre-compiled 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 contains the header files (xxx.h) that Motion needs to build with the shared libraries. 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.

This is a list of shared libraries used by Motion and the RPM packages that provides them.

For generating mpeg films with ffmpeg you need this library:
(See also the section Generating MPEG films with ffmpeg for how to install ffmpeg and libavformat/libavcodec)Motion must be installed with revision 0.4.8 or 0.4.9pre1 of ffmpeg. Motion will also work with later CVS snapshots of ffmpeg but the API of the ffmpeg libraries changes all the time and without warning. If you have problems compiling Motion or with running an RPM of Motion you may try with an older CVS snapshot of ffmpeg. The Motion developers will like to know when ffmpeg changes and breaks Motion so we can fix it. Please file a bug report then with the exact date of the ffmpeg CVS version you have trouble with.

Debian has not provided deb packages for ffmpeg due patent issues. However this is about to change so checkout for availability of newer versions of debian ffmpeg debs. You can build yourself from source or from Christian Marillat website or apt repository.

Configure is script that you run to setup the build environment for the C-compiler. It generates the "Makefile" which the program "make" uses to compile and install the software.

To run configure your current directory must be the motion directory. You type

./configure

You can add the parameter ./configure --help to get help on the different switches.

This is walk through of the options.

Option

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

--help=recursive

display the short help of all the included packages

-V, --version

display version information and exit

Gives no useful information

-q, --quiet, --silent

do not print `checking...' messages

Not very useful. Output to screen is only a few lines anyway.

--cache-file=FILE

cache test results in FILE. [disabled]

No function

-C, --config-cach

alias for `--cache-file=config.cache'

No function

-n, --no-create

do not create output files

Used for testing if other switches produce error - without writing anything to the disk

--srcdir=DIR

find the sources in DIR. [configure dir or `..']

DIR is a directory path. Editor recommends having the current directory being the motion installation directory and not using this switch. Then it defaults to the same directory as where the configure script is which is the current directory.

Installation directories:

--prefix=PREFIX

install architecture-independent files in PREFIX [/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-version, configuration file in /usr/local/etc, and some examples config files in /usr/local/examples/motion-versionEditor recommends keeping this default setting. 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. Ignore it.

--libexecdir=DIR

program executables [EPREFIX/libexec]

Not used by motion. Ignore it.

--datadir=DIR

read-only architecture-independent data [PREFIX/share]

Not used by motion. Ignore it.

--sysconfdir=DIR

read-only single-machine data [PREFIX/etc]

This is where motion both installs the default configuration file and also where it later searches for it. 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 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.conf file that you have edited and experimented with for hours. Make sure to keep a copy in a safe place. Alternatively, copy the working file to the motion base install directory. Then make install will simply copy the same file back again.

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 V4L 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 (optional). If this is not specified motion will try to find the library /usr/lib/libjpeg-mmx.a /usr/local/lib/libjpeg-mmx.a.

Considered experimental

--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 do not need to specify the directory prefix. Configure will 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). For more information on FFmpeg see the FFmpeg project home page. FFmpeg is a package that enables streamed video mpeg signal from your web camera to a browser. Editor recommends installing ffmpeg from source and in the directory /usr/local/ffmpeg and build ffmpeg with ./configure --enable-shared. This places libraries in /usr/local/lib and headers in /usr/local/include.

--without-ffmpeg

Do not compile with ffmpeg

Use this if you do not want to compile with ffmpeg. If ffmpeg is not installed you do not need to specify that Motion must 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.

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

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

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

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

Developers options

--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. For more information about these flags, see CompileWithDeveloperFlags

When you run make, all the C-source files are automatically compiled and linked. Just look out for error messages.

Make uses a file called "Makefile" which is generated by the "configure" script you just ran. If you have special needs you can manually edit this file. Next time you run configure a new Makefile will be generated and your changes are lost.

Attention!

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

make install simply copies all the nice files that were generated during the compilation/linking that make did.

Makes the directories (if they do not already exist)(path shown are the defaults): /usr/local/bin, usr/local/man/man1, /usr/local/etc, /usr/local/share/doc/motion-3.2.X, and /usr/local/share/doc/examples/motion-3.2.X.

Copies the following files from the base motion directory (assuming the default PREFIX /usr/local was used when running configure - otherwise adjust to the actuals you chose)

Note that the any existing files are overwritten. 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.

If you are upgrading from motion 3.0.X or from an older version of 3.1.X you should note that many options have been removed from version 3.1.13 and forward and many new have arrived. You still have most of the old features. The options have been changed for two reasons. New more flexible features and to simplify getting started with Motion. With 3.2.1 the changes are significant. You should also note these major differences.

The use of thread files has completely changed. Read the section "The Config Files" carefully.

Minimum_motion_frames feature prevents short noise events from being saved (3.1.14)

If you use the database features you need to note that from version 3.1.15 and forward the fields have been redefined. Removed are second, minute, hour, day, month and year. Instead these six have been replaced by a real timestamp field called time_stamp. The relatively new field 'type' has been renamed to 'file_type' to avoid reserved SQL words. A new field 'text_left' has been added which stores the text given by the config option text_left. And last a field called 'camera' has been added which stores the thread number.

From 3.1.15 the ffmpeg feature now also supports mpeg4 and msmpeg4. The build process of Motion now use ffmpeg libraries as shared libraries. The --with-libavcodec has been replaced by a --with-ffmpeg which only needed to specify if you are installing ffmpeg from sources in a non-standard location. If you have installed ffmpeg from sources already you will need to rebuild by running (from within the ffmpeg source file root) ./configure --enable-shared followed by make and make install. If you had installed ffmpeg from a binary RPM or deb you probably don't have to do anything.

Rotate feature was introduced in 3.1.15

Berkeley mpeg feature has been removed in 3.1.18 (use ffmpeg - it is much better)

Incomplete prediction feature was removed in 3.1.18. (lack of interest in finishing it)

Smart Mask feature introduced in 3.1.18

output_normal can now also have the value "first" which means only save first jpg from each event (3.1.18)

ffmpeg-0.4.9 is now supported. Motion detection mpegs can no longer be saved as mpeg1 (ffmpeg does not support non-standard framerates in 0.4.9) (3.1.18)

Motion now supports most (not all) mjpeg streaming cameras (3.1.18).

output_normal can now have values "first" or "best". It is used when you need to present a link to an mpeg movie shown as a single jpeg image. "First" saves the first picture frame in the new event. "Best" saves the picture frame with most motion content (most changed pixels) when the event is over. "on" still saves all motion detection picture frames plus pre and post captured images. With "best" you can set jpeg_filename = "preview" and it gets the same filename as the mpeg file but with extension .jpg. Option "locate" can also take the value "preview" which makes it only draw a rectangel on the jpeg but not on the mpeg movie. (3.2.1)

The xmlrpc remote control interface is replaced by a much nicer http remote control interface. (3.2.1)

All the options that calls external programs have been made much more generic. New onxxxx options have been added. Execute, sms and mail have been replaced by the generic on_event_start. (3.2.1)

New setup mode makes setting all the detection options much easier.

netcam now also supports proxies (3.2.2) and ftp (3.2.4)

text on the pictures can be set to double size (3.2.2)

Tracking with Logitech Sphere/Orbit improved (3.2.4)

SQL database feature is now fully configurable so you can control which fields you have in the database.

Many new conversion specifiers have been added which can be used both in filenames, commands, text, and SQL database features (3.2.2-3.2.4)

Stepper motor tracking feature extended to also include a Y axis (3.2.5)

ffmpeg_filename has been renamed to movie_filename to prepare for alternative implementation to mpeg files made with ffmpeg (3.2.5)

New feature: ffmpeg_deinterlace which can de-interlace using the ffmpeg libs (3.2.5)

New feature: minimum_frame_time which enables Motion to run at frame rates below 2. minimum_gap feature was removed since this was useless and the new minimum_frame_time feature replaces it with much better function. (3.2.7)

New feature: process_id_file which writes a PID file when started and removes it when stopped (3.2.7)

V4L2 support with many new supported palettes : V4L2_PIX_FMT_SBGGR8, V4L2_PIX_FMT_SN9C10X, V4L2_PIX_FMT_JPEG, V4L2_PIX_FMT_UYVY (3.2.8)

The table below shows the new options in the left column, and obsolete options in the right column. If the there are options on both sides in a row it means that the options in the left column replaced the options in the right column.