sudo apt-get install motionBefore 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.confAfter you you have made all the appropriate adjustments to the configuration file, close it. Then start motion in the terminal simply by typing:
sudo apt-get install autoconf automake build-essential pkgconf libtool libzip-dev libjpeg62 libjpeg62-dev git libavformat-dev libavcodec-dev libavutil-dev libswscale-dev
git clone https://github.com/Motion-Project/motion.git
sudo apt-get install autoconf automake build-essential pkgconf libtool git libzip-dev libjpeg62 libjpeg62-dev
sudo apt-get install libavformat-dev libavcodec-dev libavutil-dev libswscale-dev
sudo apt-get install mysql-server libmysqlclient-dev
sudo apt-get install postgresql libpq-dev
sudo apt-get install sqlite3
sudo apt-get install libjpeg-turbo8 libjpeg-turbo8-dev
sudo apt-get install libsdl1.2-dev
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++
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
Not known by author
Not known by author
Not known by author
autoreconfIf 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 -fThe -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
./configureYou can add the parameter
./configure --helpto 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-gnueabihfFor a long term option, you can edit the file
$HOME/.bashrcand within it place the following two lines at the end
export PKG_CONFIG_PATHThis 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.
Defaults for the options are specified in brackets [ ]
|-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.|
|--prefix=PREFIX|| install architecture-independent files in PREFIX
| The default /usr/local means that
The executable binary "motion" is installed in /usr/local/bin
The manual page in /usr/local/man/man1
The document files in /usr/local/docs/motion
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.
|--exec-prefix=EPREFIX|| install architecture-dependent files in EPREFIX
| 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
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.|
|--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.|
makeFor FreeBSD distributions use
gmakeThe 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 -ltheoradecOnce the makefile has completed correctly, it will report 'build complete'. If you have run
makebefore, you should run a
make cleanbefore running
makeagain. This cleans out all the object files that were generated the previous time you ran
make. If you do not run
make cleanfirst 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 cleanfirst the ffmpeg feature does not get compiled into the Motion binary. First time you build motion run
make install. If you need to build it again (to run with different configure options) run
make installto install the files. For FreeBSD systems, use
gmake installThese commands create the required directories and copy the files into the following locations. (default directories):
make uninstallAnd 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.
make uninstallhas already been described above.
make cleanbefore you run
makeif you change the configuration (like adding features such as ffmpeg) and rebuild motion.
-c pathnameMotion 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:
stream_port 8082Motion reads its configuration parameters in the following sequence. If the same parameter exists more than one place the last one read wins
motion [ -hbnsm ] [ -c config file path ] [ -d level ] [ -k level ] [ -p process_id_file ] [ -l log_file ]
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:
|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.|
/var/log/messages(e.g. RedHat/Fedora) or
inputmust be set to the value -1 for USB cameras. Network cameras are set up via the
netcam_urlparameter. 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_urlfor additional options. Raspberry Pi cameras are set up via the
mmalcam_nameparameter. 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
frequencyto 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).
|Version 3.2||Version 3.4||Current Version|
|%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|
frequencyoptions 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_framesnumber 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_skipnumber of frames are skipped to allow the device to settle. The last option
switch_filteris 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.
rotateoption, 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)
setup_mode. That way you can easily adjust smart_mask_speed. The
mask_fileoption 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.
post_capturewhich does not cost any performance hit or RAM space.
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 11Note 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.
tar -xvzf /path/to/vloopback-1.1-rc1.tar.gzYou 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 vloopbackNow change to the new directory
cd vloopbackBuild the code
makeThere 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.
ln -s /usr/src/linux-2.4.18-4 /usr/src/linux
#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=4When 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
<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.mjpgMotion 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_portis 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_localhostmust 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/nullIf 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.