Motion Guide - Installation
This topic consists of the following subtopics:
MotionOverview,
KnownProblems,
InstallOverview,
PrepareInstall,
ConfigureScript,
MakeInstall,
UpgradingFromOlderVersion,
ErrorLogging.
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.
- Execute external program when a picture is saved.
- Execute external program when a movie file is created (opened)
- Execite external program when a movie file is ending (closed)
- Motion tracking
- Live streaming webcam (using multipart/x-mixed-replace)
- Take automated snapshots on regular intervals
- Take automated snapshots at irregular intervals using cron
- Feed events to an MySQL, PostgreSQL or SQLite3 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
- Highly configurable display of text on images.
- 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.
Documentation
You have the following sources of information:
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.
See also the
Frequently Asked Questions and
Bug Reports for known open bugs.
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.
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:
sudo motion
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
Library |
RPM Packages |
Debian Packages |
libm, libresolv, libdl, libpthread, libc, ld-linux, libcrypt, and libnsl |
glibc and glibc-devel |
libc6 , libc6-dev ,libglib1.2 |
libjpeg |
libjpeg and libjpeg-devel |
libjpeg62 and libjpeg62-dev ( optional libjpeg-mmx-dev ) |
libz |
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.
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.
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
./configure
You can add the parameter
./configure --help
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.
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)
- 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.
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.
- 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
/var/log/messages
(e.g. RedHat/Fedora) or
/var/log/syslog
and
/var/log/user.log
(e.g. Debian).
--
KennethLavrsen - 13 Aug 2005