Motion Guide - Basic Features
NOTE THAT THIS GUIDE IS CURRENTLY BROKEN BECAUSE WE ARE IN THE MIDDLE OF A MAJOR REWRITE FOR MOTION 4.0
This topic consists of the following subtopics:
Before you can start using motion you need to know some basics about your camera.
Either you have a camera connected directly to your computer. In this case it is a video4linux type of camera. Or you connect to a network camera using a normal web URL.
video4linux (V4L) devices
You need to install your camera with the right driver. It is out of scope of this document to tell you how to do this and it depends on which type of camera.
Once installed the camera(s) will have the device names /dev/video0, /dev/video1, /dev/video2...
FreeBSD has a different naming of devices. When you build Motion for FreeBSD the default device name is /dev/bktr0. Under FreeBSD a TV card has a special device for controlling the tuner (e.g. /dev/tuner0). The option tunerdevice is only valid when Motion is built and running under FreeBSD. For Linux do not include this option in the config file (remove or comment out).
take a lot of bandwidth. A USB camera connected to a USB 1.1 port or hub consumes all the bandwidth. Even with a small framesize and low framerate you should not expect to have more than one camera per USB 1.1 controller. If you need more than 1 USB camera add extra USB PCI cards to your computer. There exists cards that have 4 inputs each with their own controller and with full bandwidth. Many 4-input cards only have 1 controller. USB cameras do not have the feature of selecting input channels. To disable the input selection the option input must be set to the value 8 for USB cameras.
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 8 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 thread config files with the same videodevice name but different input numbers Motion automatically goes into round robin mode. See the round robin
section for more information. Many TV tuner cards have the input channels: TV Tuner = 0, Standard composite video = 1, S-VHS = 3. Other have TV=0, composite video 1= 1, composite video = 2, S-VHS = 3. 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 (phono socket) and perhaps also a S-VHS 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 Camstream or xawtv to experiment with the values.
If you use the TV tuner input you also need to set the frequency of the TV channel using the option frequency
. Otherwise set 'frequency' to 0.
Finally you need to set the TV norm. Values: 0 (PAL), 1 (NTSC), 2 (SECAM), 3 (PAL NC no colour). Default is 0 (PAL). If your camera is a PAL black and white you may get a better result with norm=3 (PAL no colour).
If the netcam_url
option is defined all the video4linux options are ignored so make sure the netcam_url option is commented out if you do not need it.
These are the parameters used for video4linux devices
Motion can connect to a network camera through a normal TCP socket. All you need to give it is the URL. The URL given must return either one single jpeg picture or an mjpeg stream. For the time being Motion cannot connect to a video stream such a mpeg, mpeg4, divx. The URL must return one single jpeg image or an mjpeg stream! You can connect through a proxy server.
Also watch out that you do not use a URL that create an HTML page with an embedded jpg. What must be returned is the jpg picture itself or the raw mjpeg stream.
When the netcam_url is defined all the video4linux options above are ignored!!
If the connection to a network camera is lost - Motion will reuse the last good image for approx 30 seconds. AFter 30 seconds the image is replaced by a grey image with a text telling that the signal is lost and when the connection was lost. This text and its date format is not configurable and there are no plans to make it configurable in order to keep the number config options under control.
Note that Motion requires that dimensions 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.
The network camera feature has been completely re-written in Motion 3.2.2. We believe the netcam feature is much more stable now that it was in previous versions. Motion tries to reconnect to the camera if the connection is lost. There is no official standard for mjpeg and we know that there are probably still some cameras that are not yet supported. If you run into a problem please file a Bug Report with as much information about the format as possible. A binary raw dump of the first 2-3 frames with headers and boundary strings is very useful. You can see how to make it on the special topic NetcamMjpegStreamDumps. When you have the file you can upload it to the same topic.
Round Robin feature
This feature is automatically activated where multiple threads are sharing the same video device (for example /dev/video0). Each thread can then set different input channels to change camera with the input
option or by tuning the tuner with frequency
Round Robin is not relevant for Network cameras or standard USB web cameras. The Round Robin feature is used with video capture cards which have multiple inputs per video chip.
Note that round robin is not the ideal way to run multiple cameras. When the capture card changes input it takes a little while 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 camera threads 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 affort 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.
These are the special Round Robin options
- If multiple threads use the same video device, they each can capture roundrobin_frames number of frames before having to share the device with the other threads.
- When another thread wants to watch another input or frequency or size the first roundrobin_skip number of frames are skipped to allow the device to settle.
- The last option switch_filter is supposed to prevent the change of camera from being detected as Motion. Its function is not perfect and sometimes prevents detection of real motion. You should start with having the option disabled and then try with the option enabled to see if you can skip less frames without loosing the detection of the type of motion you normally want to detect.
These are the options that controls the detection of motion. Further details follows after.
The following options controls how Motion generates images when detection motion.
Motion 3.2 introduces a new feature Setup Mode. This is a great new feature with really make tuning all the settings of Motion much more easy and transparent. In setup mode two things happen:
- With 'motion -s' Motion runs in console mode instead of daemon. It outputs a lot of useful information for each frame from the camera. Each message is prefixed by [number] where number is the camera number (thread number).
- When you look at the mjpeg webcam stream you see a black image with numbers. What you see is the number of changed pixels, number of labeled areas and noise setting. When something moves you see the pixels detected as Motion in black and white. The largest labelled area (assuming despeckle is enabled and with the 'l' at the end) is blue. It is only the blue areas which is counted as Motion. If smartmask is enabled you see this as red areas.
Here is a suggestion how to initially setup Motion.
- Disable despeckle (comment it out in motion.conf).
- Disable smartmask
- Enable both http control and webcam by setting port numbers. Example 8080 for control and 8081 for webcam.
- Start Motion in setup mode
- View the webcam stream. Either with Cambozola or with Firefox. http://localhost:8081/ Firefox often needs to reload the page before it works. Bug in Firefox. Internet Explorer cannot show the stream unless you make a webpage on your Apache with Cambozola applet.
- Open new browser window and connect to the http interface. http://localhost:8080/ . You can now control and change almost anything while Motion is running. You cannot resize the image. That was too hard to code. To disable a feature enter a space.
- Start by experimenting with noise level. Do this both during daylight and during darkness. You will be surprised to see how much noise a camera makes during night. Try using the automatic noise feature. It should work for most.
- Now try the despeckle feature. Enable it using the recommended default EedDl. If this is not enough experiment. Remember that the l must be the last letter. It is fun to play with.
- Set the threshold to what you want to trigger Motion.
In normal mode you can use the same setting with two browser windows and experiment with settings of the camera if needed.
From the web interface you can ask Motion to write all your changes back to the config files (motion.conf and thread config files). It will even tidy them up for you so they look nice.
There are two sets of options to adjust.
Normal picture frame
Motion type picture frame with despeckle. Note that the largest area is blue and only this is counted as Motion.
The Motion image shows how Motion maintains a "reference frame" which is not just the last picture frame but a matematical calculation of the past images. This enlarges real Motion and ensures that it is not easy to sneak in slowly.
The ffmpeg option can generate mpeg films very fast and "on the fly". This means that the mpeg film is growing each time motion is detected.
Some people on the Motion mailing list have had trouble building the ffmpeg package because they did not have the NASM assembler package installed. So pay attention to this if you run into problems.
ffmpeg exists as binary packages for most distributions including RPMs and debian packages.
Ffmpeg is an interesting project. The releases have not been very consistent over time. The official releases are out of date now. So we are forced to take our chance and checkout a version from their CVS server and hope that we are lucky in getting a version that works. See ffmpeg project page
. We encourage the maintaners of such an important project to introduce better release schedules in the near future for the benefit of opensource software.
In order to help people finding a version of ffmpeg that works we have started testing the Motion package with a selection of binaries and a CVS snapshot. The CVS source snapshot of ffmpeg which is certified with Motion is available on the Related projects file area on the Motion Sourceforge project
Motion works with the following versions of ffmpeg:
- ffmpeg-0.4.8. With this release Motion supports mpeg1, mpeg4 and msmpeg4. Lately newer distributions have problems building this 2003 release of ffmpeg so many of you no longer have this option.
- ffmpeg-0.4.9pre1. Is supported starting from Motion version 3.1.18. With this release Motion supports mpeg4 and msmpeg4 but not mpeg1. The reason is that the ffmpeg team has decided no longer to support non-standard framerates in their mpeg1 encoder library. Also ffmpeg-0.4.9pre1 gives people problems on newer distributions.
- ffmpeg from CVS. This may work. We cannot continuously monitor and try every time a new source file is checked into ffmpeg. You will have to try.
- ffmpeg RPMs. Currently each Motion release is tested with the current Livna ffmpeg rpm package for Fedora. See the Download Files page for direct links to the version which has been certified with the latest Motion release.
- ffmpeg debian binaries. Latest versions from the debian repository for Debian Sarge works fine with Motion.
- Certified ffmpeg CVS snapshot for latest Motion release is available from the Motion Sourceforge Related Projects file area
The timelapse feature always runs mpeg1 with both ffmpeg 0.4.8 and 0.4.9 and newer. Motion simply creates the timelapse film with a standard mpeg1 framerate. Note : maximum size for timelapse files is 2GB.
In principle Motion can be made to support many other formats. It requires additional coding in Motion. You are welcome to submit patches
. All ffmpeg related code is in the source file ffmpeg.c. It is not trivial to do because the ffmpeg libraries not documented at all. All you have is a couple of code examples.
To build ffpmeg from source follow these steps:
Download the ffmpeg and untar it to /usr/local/ffmpeg. Then it should be a simple matter of entering the ffmpeg directory and run the commands
This creates the
and header files under
You probably need to do one more step.
Make sure you have 'root' privileges for the next steps.
Open the file
in your favorite text editor.
Add this line of text if it is not already there - otherwise go to the next step (ldconfig).
Run the command
Motion should now be able to find the shared libraries for ffmpeg (
You can also find a pre-compiled binary package (e.g. rpm or deb) and install this. Normally an rpm will place the
There are various RPMs available from different repositories. Some need additional RPMs that are actually not needed by Motion but need to be installed to satisfy dependencies. The editor has tried different RPMs of ffmpeg-0.4.8 and they all seem to work.
Motion then need to be built by running
(Note that with earlier versions of motion you had to specify the location of libavcodec. Now configure searches for the shared library in
Note that if you install ffmpeg from source and already have ffmpeg installed from an RPM, the Motion configure may very well find the binary library from the rpm instead of the sources. Make sure to uninstall any old ffmpeg RPMs before you install ffmpeg from sources.
These are the config file options related to ffmpeg.
This feature uses ffmpegs libavcodec to encode a timelapse movie saving a picture frame at the interval in seconds set by this parameter. Setting this option to 0 disables it.
The feature gives your viewer the chance to watch the day pass by. It makes a nice effect to film flowers etc closeup during the day. Options like frame_rate, snapshot, gap etc have no impact on the ffmpeg timelapse function.
Note that the timelapse format is always mpeg1 independent of ffmpeg_video_codec. This is because mpeg1 allows the timelapse to stop and the file to be reopened and more film appended.
To use this feature you need to install the FFmpeg Streaming Multimedia System
(renamed from ffmpeg_timelaps to ffmpeg_timelapse in 3.1.14)
Supported formats are:
- mpeg4 or msmpeg4 - gives you files with extension .avi
- msmpeg4 is recommended for use with Windows Media Player because it requires no installation of codec on the Windows client.
- swf - gives you a flash film with extension .swf
- flv - gives you a flash video with extension .flv
- ffv1 - FF video codec 1 for Lossless Encoding ( experimental )
- mov - QuickTime ( testing )
- ogg - Ogg/Theora ( testing )
- mp4 - MPEG-4 Part 14 H264 encoding
- mkv - Matroska H264 encoding
- hevc - H.265 / HEVC (High Efficiency Video Coding)
Timelapse videos have two options.
- swf - Creates swf file with mpeg-2 encoding.
If motion is shutdown and restarted, new pics will be appended to any previously created file with name indicated for timelapse.
- mpeg4 - Creates avi file with the default encoding.
If motion is shutdown and restarted, new pics will create a new file with the name indicated for timelapse.
See also the section Advanced Filenames
where the two additional options ffmpeg_filename
If you want to use this feature you can read about the FFmpeg Streaming Multimedia System
Motion can also act like a traditional web camera.
See the also snapshot_filename
option in the section Advanced Filenames
Text features are highly flexible. You can taylor the text displayed on the images and films to your taste and you can add your own user defined text.
This is how the overlayed text is located.
You are allowed to put the text in quotation marks. This allows you to use leading spaces. By combining spaces and new lines '\n' you can place your text anywhere on the picture. Experiment to find your preferred look. When setting the text using http remote control the text must be URL encoded. The browser does this for you. If you need to set it with a command line tool, use a browser first and let it make the encoded URL for you. Then you can copy paste it to your script file or cron line or whatever you want to use.
Below are the options that controls the display of text. The 'locate' option is not a text feature but described here because it is related to information overlayed on the output images.
feature is special in that it defines the conversion specifier %C which can be used both for text display and for filenames.
Motion has a very advanced and flexible automated filenaming feature.
By using conversion specifiers
(codes that consist of a '%' followed by a letter) you can build up the filenames including sub directories for pictures and movies using any combination of letters, numbers and conversion specifiers which are codes that represents time, date, event number and frame numbers.
is the target directory for all snapshots, motion images and normal images. The default is the current working directory (current working directory of the terminal from which motion was started). You will normally always want to specify this parameter.
Note that the options
all allow specifying directories by using '/' in the filename. These will all be relative to
. This means in principle that you can specify
as '/' and be 100% flexible. It also means that Motion can write files all over your harddisk if you make a mistake. It is recommended to specify the
as deep or detailed as possible for this reason. And note that
does not allow conversion specifiers.
The conversion specifier %C which is defined by the option text_event
is interesting in connection with filenames because it can be used to create files and directories for each event in a very flexible way.
The convertion specifier %t (thread/camera number) is also very useful. Here is an example of filename definitions in motion.conf:
The smart thing is that this defines the filename of all your camera threads in motion.conf so you do not need to specify target dir and filenames in the thread config files. In the above example an mpegfile for camera thread 3 will be saved as a filename similar to
NOTE: Unless you use the
option to limit the number of shots to less then one per second - you must use the frame modifier %q as part of the
. Otherwise the pictures saved within the same second will overwrite each other. The %q in
ensures that each jpeg (or ppm) picture saved gets a unique filename.
Security Warning! Note that the flexibility of this feature also means you have to pay attention to the following.
These are the advanced filename options in motion.conf
- Anyone with access to the remote control port (http) can alter the values of these options and save files anywhere on your server with the same privileges as the user running Motion. Anyone can access your control port if you have not either limited access to localhost or limited access using firewalls in the server. You should always have a router between a machine running Motion with remote control enabled and the Internet and make sure the Motion control port is not accessible from the outside.
- Anyone with local access to the computer and edit rights to the motion.conf file can alter the values of these options and save files anywhere on your server with the same privileges as the user running Motion. Make sure the motion.conf file is maximum readonly to anyone else but the user running Motion.
- It is a good idea to run Motion as a harmless user. Not as root.
The table below shows all the supported Conversion Specifiers you can use in the options
you can additionally use '\n' for new line.
| Conversion Specifier
| The abbreviated weekday name according to the current locale.
| The full weekday name according to the current locale.
| The abbreviated month name according to the current locale.
| The full month name according to the current locale.
| The preferred date and time representation for the current locale.
| Text defined by the text_event feature
| The day of the month as a decimal number (range 01 to 31).
| Number of pixels detected as Motion. If labelling is enabled the number is the number of pixels in the largest labelled motion area.
| Modifier: use alternative format, see below.
| File name - used in the on_picture_save, on_movie_start, on_movie_end, and sql_query features.
| Equivalent to %Y-%m-%d (the ISO 8601 date format).
| The hour as a decimal number using a 24-hour clock (range 00 to 23).
| Width of the rectangle containing the motion pixels (the rectangle that is shown on the image when locate is on).
| The hour as a decimal number using a 12-hour clock (range 01 to 12).
| The day of the year as a decimal number (range 001 to 366).
| Height of the rectangle containing the motion pixels (the rectangle that is shown on the image when locate is on).
| The hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by a blank. (See also %H.)
| X coordinate in pixels of the center point of motion. Origin is upper left corner.
| The hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by a blank. (See also %I.)
| Y coordinate in pixels of the center point of motion. Origin is upper left corner and number is positive moving downwards (I may change this soon).
| The month as a decimal number (range 01 to 12).
| The minute as a decimal number (range 00 to 59).
| Filetype as used in the on_picture_save, on_movie_start, on_movie_end, and sql_query features.
| Noise level.
| Threshold. The number of detected pixels required to trigger motion. When threshold_tune is 'on' this can be used to show the current tuned value of threshold.
| Either 'AM' or 'PM' according to the given time value, or the corresponding strings for the current locale. Noon is treated as `pm' and midnight as `am'.
| Like %p but in lowercase: `am' or `pm' or a corresponding string for the current locale.
| Picture frame number within current second. For jpeg filenames this should always be included in the filename if you save more then 1 picture per second to ensure unique filenames. It is not needed in filenames for mpegs.
| Number of detected labels found by the despeckle feature
| The time in a.m. or p.m. notation.
| The time in 24-hour notation (%H:%M).
| The number of seconds since the Epoch, i.e., since 1970-01-01 00:00:00 UTC.
| The second as a decimal number (range 00 to 61).
| Thread number (camera number)
| The time in 24-hour notation (%H:%M:%S).
| The day of the week as a decimal, range 1 to 7, Monday being 1. See also %w.
| The week number of the current year as a decimal number, range 00 to 53, starting with the first Sunday as the first day of week 01. See also %V and %W.
| Event number. An event is a series of motion detections happening with less than 'gap' seconds between them.
| The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week. See also %U and %W.
| The day of the week as a decimal, range 0 to 6, Sunday being 0. See also %u.
| The week number of the current year as a decimal number, range 00 to 53, starting with the first Monday as the first day of week 01.
| The preferred date representation for the current locale without the time.
| The preferred time representation for the current locale without the date.
| The year as a decimal number without a century (range 00 to 99).
| The year as a decimal number including the century.
| The time-zone as hour offset from GMT.
| The time zone or name or abbreviation.
Motion has simple webcam server built in. The video stream is in mjpeg format.
Each thread can have its own webcam server. If you enable the webcam server (option webcam_port to a number different from 0) and you have more than one camera, you must make sure to include webcam_port in each thread config file and set webcam_port to different and unique port numbers or zero (disable). Otherwise each webcam server will use the setting from the motion.conf file and try to bind to the same port. If the webcam_port numbers are not different from each other Motion will disable the webcam feature.
Note: The webcam server feature requires that the option
is set to off
options are important to limit the load on your server and link. Don't set them too high unless you only use it on the localhost or on an internal LAN. The option
is equivalent to the quality level for jpeg pictures.
option prevents people from loading your Network connection by streaming for hours and hours. The options defines the number of picture frames sent as mjpeg Motion will allow without re-connecting (e.g. clicking refresh in the browser).
is a security feature. When enabled you can only access the webserver on the same machine as Motion is running on. If you want to present a live webcam on your web site this feature must be disabled.
The webserver generates a stream in "multipart jpeg" format (mjpeg). You cannot watch the stream with most browsers. Only certain versions of Netscape works. Mozilla and Firefox brosers can view the mjpeg stream but you often have to refresh the page once to get the streaming going. Internet Explorer cannot show the mjpeg stream. For public viewing this is not very useful. There exists a java applet called Cambozola
which enabled any Java capable browser to show the stream. To enable the feature to a broad audience you should use this applet or similar.
To use the webcam feature with Cambozola is actually very simple.
Create a html page in which you will want the streamed picture.
In the html page include this code
archive=cambozola.jar width="320" height="240" style="border-width:1; border-color:gray; border-style:solid;"> <param name=url value="http://www.myurl.com:8081"> </applet>
Where the width and height is the image size of the video stream.
Replace www.myurl.com:8081 by the real url and port number of your choice.
In the same directory you place the cambozola.jar file. No need to build the java applet from source. Simply use the applet in the package.
Enable the feature in motion.conf.
You can also view the live webcam stream using MPlayer
mplayer -demuxer lavf http://www.myurl.com:8081/stream.mjpg
Note that the
part is important, without it you will get a
LAVF_check: no clue about this gibberish!
error from libavformat.
Note that you can stream from multiple videos by having several applet viewers on each page (pointed to different url's, of course).
These are the special webcam parameters.
Motion can be remote controlled via a simple http interface. http is the language a normal web browser talks when it requests a web page. The web server answers back with some simple http headers followed by a webpage coded in HTML.
Most Motion config 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. So only your fantasy sets the limit to what you can change combining cron and the remote control interface for Motion.
So 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, Konquerer, Opera 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.
The details about how to control Motion via the URL is described in detail in the Motion http API
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 control_port
is 8080 and you browse from the same machine on which Motion runs simply look up http://localhost:8080/
and navigate around. Connecting from a remote machine is done by using a domain name (example http://mydomain.com:8080/
) or the IP address of the machine (example http://192.168.1.4:8080/
). The option control_localhost
must be off to allow connection from a remote machine.
If you want to use a script or cron to automatically change Motion settings while Motion runs you use a program that can fetch a webpage. We simply just throw away the html page that Motion returns. Programs commonly available on Linux machines are wget and lwp-request. Here is an example of how to start and stop motion detection via cron. These two lines are added to /etc/crontab.
0 9 * * * root /usr/bin/lwp-request http://localhost:8080/0/detection/start > /dev/null
0 18 * * * root /usr/bin/lwp-request http://localhost:8080/0/detection/pause > /dev/null
If you want to use the http remote control from your own software (for example your own PHP front end) you can set the new motion.conf option html_output off. Then Motion answers back with very basic text only and no html around it. A bit like the xmlrpc interface did.
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
What happened to XMLRPC?
XMLRPC is replaced by a simpler http remote control interface. It is still being worked on but it is absolutely useable now and much nicer to work with than xmlrpc. Another advantage is that you do not need to install xmlrpc libraries. It is all written in standard C.
Security Warning! Note that this feature also means you have to pay attention to the following.
These are the config file options that control Motion.
- Anyone with access to the remote control port (http) can alter the values of any options and save files anywhere on your server with the same privileges as the user running Motion. They can execute any command on your computer with the same privileges as the user running Motion. Anyone can access your control port if you have not either limited access to localhost or limited access using firewalls in the server. You should always have a router between a machine running Motion with remote control enabled and the Internet and make sure the Motion control port is not accessible from the outside.
- If you limit control port to localhost you still need to take care of any user logging into the server with any kind of terminal session.
- It is a good idea to run Motion as a harmless user. Not as root!!
These must be placed in motion.conf and not in a thread config file.
- 12 Apr 2005
Motion can execute external commands based on the motion detection and related events. They are all described in this section. The option
is also included in this section.
A redesign of the external commands was due. They were not very easy to understand, not all were flexible enough and some were missing. So a new external command feature set was made for 3.2.1 and on.
This is how the new script commands look like:
| Old Option
| New Option
| Argument Appended
| Start of event (first motion)
| End of event (no motion for gap seconds)
| Picture saved (jpg or ppm)
| Filename of picture
| Movie starts (mpeg file opened)
| Filename of movie
| Movie ends (mpeg file closed)
| Filename of movie
| Motion detected (each single frame with Motion detected)
Mail and sms has been removed because they were not configurable. If you want to send event-based mails or sms, just use one of those commands above and send the mail from that script. See What happened to mail and sms?
Security Warning! Note that this feature also means you have to pay attention to the following.
These are the options
- Anyone with access to the remote control port (http) can execute any command on your computer with the same privileges as the user running Motion. Anyone can access your control port if you have not either limited access to localhost or limited access using firewalls in the server. You should always have a router between a machine running Motion with remote control enabled and the Internet and make sure the Motion control port is not accessible from the outside.
- If you limit control port to localhost you still need to take care of any user logging into the server with any kind of GUI or terminal session. All it takes is a browser or single command line execution to change settings in Motion.
- It is a good idea to run Motion as a harmless user. Not as root!!
What happened to mail and sms?
The 6 new on_xxxxx options replace the former execute, mail and sms options.
They are quite generic and flexible. These small bash scripts gives to the same functionality as mail and sms BUT you have all the flexibility you want to extend the messages, change the 'from' email address etc.
Sending email at start of event
_Script written by JoergWeber
# Motion sample script to send an e-mail at start of an event.
# Replaces the former 'mail' option.
# Just define this script as 'on_event_start'-script in motion.conf like that:
# on_event_start send_mail "%Y-%m-%d %T"
#change to suit your needs:
#location of 'mail' binary
#Destination e-mail address
#Subject of the e-mail
#Don't change anything below this line
echo -e "This is an automated message generated by motion.\n\nMotion detected: $1\n\n" | $MAIL -s "$SUBJECT" $TO
Sending SMS at start of event
_Script written by JoergWeber
If you uncomment the line
you can combine both sending email and sms.
# Motion sample script to send an sms at start of an event.
# Replaces the former 'sms' option.
# Just define this script as 'on_event_start'-script in motion.conf like that:
# on_event_start send_sms "%Y-%m-%d %T"
# If you want to send an e-mail message here as well, just uncomment the last
# line of this script.
#change to suit your needs:
#location of 'sms-client' binary
#Destination sms number
#Don't change anything below this line
$SMS_CLIENT $TO "Motion detected $1"