Motion Guide - Installation
This topic consists of the following subtopics:
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 either via the command line or via a set of configuration files (simple ASCII files that can be edited by any ASCII editor).
The output from motion can be:
- jpg files
- ppm format files
- mpeg 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 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. You will also find links to development versions. Snapshot releases are special test releases that are normally very stable. Every day a Motion Daily Source Snap
is created from the Motion Subversion
Motion was originally written by Jeroen Vreeken who still actively participates in the development of Motion and later Folkert van Heusden continued as a lead programmer with Kenneth Lavrsen responsible for Motion Guide, website and releases on Sourceforge.
From version 3.1.12 Motion is now project managed entirely by Kenneth Lavrsen, and the project now shift towards being developed by many contributers.
For support we encourage you to join the mailing list instead of writing to Jeroen, Folkert or Kenneth directly. 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.
Which version to download and use?
Versions 3.2.X are the current version. There is at the moment no development branch. The versions 3.1.X ended at 3.1.20 and there will be no more 3.1.X releases. If you use use a version older than 3.2.X you are encouraged to update.
Since 3.1.13 quite many options have been renamed to make setting up Motion easier. From 3.1.17-18 some unfinished features have been removed. The Berkeley mpeg feature is now removed because the ffmpeg feature is now mature and much better working. At version 3.1.18 a new network camera feature was introduced replacing the old cURL based netcam code and introducing support of mjpeg streaming cameras. However this new code was quite difficult to get stable. During the development of 3.2.2 the network camera code was totally rewritten again learning from our experience and now finally it seems to be stable.
Motion is included in Debian, while Ubuntu and RPM users can find binary packages on the Motion Sourceforge file download page.
What features does Motion have?
See more description at the Motion Homepage
- 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 (using multipart/x-mixed-replace)
- Real time creation of mpeg movies using libraries from ffmpeg
- Take automated snapshots on regular intervals
- Take automated snapshots at irregular intervals using cron
- Executing 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.
- Execute external program when a picture is saved.
- Execute external program when a movie mpeg is created (opened)
- Execite external program when a movie mpeg ends (closed)
- Motion tracking
- Feed events to an MySQL or PostgreSQL database.
- Feed video back to a video4linux loopback for real time viewing
- Web interface using Motion Related Projects such as motion.cgi, Kenneths Webcam Package, Kevins Webpage, X-Motion and many more.
- User configurable and user defined on screen display.
- Control via simple web interface.
- Automatic noise and threshold control
- Ability to control the pan/tilt of a Logitech Sphere (or Orbit) camera
- Highly configurable display of text on images.
- High configurable definition of path and file names of the stored images and films.
You can find more information and links at the Motion Homepage
Motion is originally developed for Linux and it is still mainly developed and supported for this platform. From version 3.1.15 an experimental port has been made by Angel Carpintero. Not all features of Motion are supported at this time and it still needs a lot of test time on different hardware. Angel is very interested in feedback. Join the Motion Mailing List and give your feedback there. Patches for bugfixes and for enabling the missing features are very welcome. The rest of this guide is still mainly targeted for Linux users. Follow this topic to Install FreeBSD
From Motion version 3.2.4 it is now also possible to build and install Motion under MacOSX
. Feature set it the same as for FreeBSD. See the MacOSX
topic for specific help how to install Motion and its dependencies on MacOSX
. Again this port has been contributed by Angel Carpintero.
You have the following sources of information:
Input devices: Here we are thinking about the cameras.
Motion supports video input from two kinds of sources.
Standard video4linux devices (e.g. /dev/video0). Motion has no drivers for cameras. Installing the camera itself is outside the scope of this document. But here are some nice links.
See also the Frequently Asked Questions
and Bug Reports
for known open bugs.
Kernel 2.6 and pwc.
Note that for kernel 2.6 there is a new release of the Philips WebCam (pwc) drivers 10.0.X. It is recommended to install this. At the time of this being written the 2.6.12+ kernels have a version of pwc built-in but it is a cripled version which can only support very small picture size. You can however download the latest source code of the pwc driver (at this time 10.0.11) and build it without having to rebuild your kernel. But you will need to have either the kernel sources or a special kernel-header package installed to compile it. See Installation of PWC
page which is also hosted in this wiki.
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.
Camera picture dimensions must be multiple of 16
Dimentions of camera image must have both height and width that are a multiple of 16. Thís is normally not a problem. All standard sizes like 640, 480, 352, 320, 288, 240, ...etc are multiples of 16. But if you intend to monitor a network camera which is saving jpeg images you may have to pay attention to the dimensions of the picture.
ffmpeg_filename has changed name to movie_filename
The 3.2.5 release contains a motion_guide and man page in which it was forgotten to change ffmpeg_filename to movie_filename. Please note that the option that defines the filenames for mpeg movies is now called movie_filename. This change is made because we may soon implement alternatives to ffmpeg and then ffmpeg_filename will be a bad name. This is fixed in release 188.8.131.52.
error: `time_current_frame' undeclared (first use in this function)
A bug in 3.2.5 and 184.108.40.206 where a bugfix related to snapshot feature has created a new bug when you compile Motion without ffmpeg libs installed. This is fixed in 3.2.6.
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.
Installation on Ubuntu
Motion is part of the Ubuntu repository. You can click either click here
to install it via the Ubuntu Software-Center.
Or open up a terminal window and type:
sudo apt-get install motion
Before we start configuring Motion, we 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:
(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:
sudo nano ~/.motion/motion.conf
After you you have done so, start motion in the terminal simply by typing:
A short overview of the steps to build and 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 with the actual placement of the tar.gz file).
- 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.
- Now change to the new directory
- Run configure. You can start with the defaults. If you need to modify the installation parameters you can read the next section.
- Install the code, manual page, etc
- 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.
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.
Motion will always need these libraries to be built and work
|| RPM Packages
|| Debian Packages
| libm, libresolv, libdl, libpthread, libc, ld-linux, libcrypt, and libnsl
|| glibc and glibc-devel
|| libc6 , libc6-dev ,libglib1.2
|| libjpeg and libjpeg-devel
|| libjpeg62 and libjpeg62-dev ( optional libjpeg-mmx-dev )
|| zlib and zlib-devel
|| zlib1g and zlib1g-dev
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.
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.
deb http://www.deb-multimedia.org stable main # ( etch )
deb http://www.deb-multimedia.org testing main # ( lenny )
deb http://www.deb-multimedia.org unstable main # ( sid )
Add the suitable line to your /etc/apt/sources.list and run this:
apt-get update ; apt-get -y install libavcodec-dev libavcodec0d libavformat-dev libavformat0d
For logging in MySQL
you need this library:
For logging in PostgreSQL
you need this library:
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
You can add the parameter
to get help on the different switches.
This is walk through of the options.
When you run make, all the C-source files are automatically compiled and linked. Just look out for error messages.
Make uses a file called "Makefile" which is generated by the "configure" script you just ran. If you have special needs you can manually edit this file. Next time you run configure a new Makefile will be generated and your changes are lost.
If you have run
before, you should run a
again. This cleans out all the object files that were generated the previous time you ran
. If you do not run
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
first - the ffmpeg feature does not get compiled into the Motion binary.
First time you build motion run
. If you need to build it again (to run with different configure options) run
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)
- 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-3.2.X
- Example configuration files "*.conf" to /usr/local/share/doc/examples/motion-3.2.X
- Configuration file "motion-dist.conf" to /usr/local/etc
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.
From the motion base installation directory you simply run
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.
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.
- make updateguide
- fetches a fresh new copy of this guide and place it in your motion source directory. Note that the pictures are not downloaded.
- make dist
- performs make clean, make distclean and make updateguide in one single operation.
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.
- The mask file format has changed. Read the section about "Mask File"
- Pre_capture feature introduced in 3.1.12
- Advanced filename feature enables very flexible filename definitions (3.1.13)
- onffmpegclose options enables running external scripts when mpeg file is closed (3.1.13)
- despeckle feature improves motion detection and noise immunity (3.1.13)
- 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)
- ffmpeg_video_codec allow swf (3.2.8)
- V4L2 fix support for : V4L2_PIX_FMT_MJPEG (3.2.9)
- ffmpeg_video_codec allow flv and ffv1(3.2.9)
- v4l2_palette: allow to choose preferable palette to be use by motion to capture from those supported by your videodevice.
- netcam_http: setup keep_alive , 1.1 or 1.0 http method to be used by netcam.
- on_camera_lost: Command to be executed when a camera can't be opened or if it is lost.
- AreaDetect, on_area_detected: Command to be executed by area_detect trigger.
- ConfigOptionNetcamTolerantCheck , netcam_tolerant_check less strict jpeg checks for network cameras with a poor/buggy firmware ( 3.2.11 ).
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.
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.
The syslog is in most Linux systems the file
(e.g. RedHat/Fedora) or
- 13 Aug 2005