Configuration

motion-pipeline settings file or module

motion-pipeline is configured via a Python settings file. This file is imported by settings.py and can be specified as either a dot-delimited importable python module or the absolute path to a Python source file on disk (if using a source file, it must be specified as an absolute path). The configuration file can be set either via the MOTION_SETTINGS_PATH environment variable or via the -c / --config options to most of the entrypoint scripts.

Note that this file is imported whenever motion sends an event to motion-handler. While it can include any Python code, it should be as simple and fast-loading as possible.

An example file is in the motion-pipeline source as settings_example.py; you should copy that file as an example and edit as necessary.

Configuration of Motion Itself

Configuration of motion itself involves setting the correct event handler commands to point to motion_handler.py and pass the required arguments. See the example below.

Example motion.conf

The only parts of motion.conf that are specific to motion-pipeline are the various on_* options that tell motion to execute our handler when various events occur:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

# Number of steps to make (stepper motor option) (default: 40)
track_stepsize 40


############################################################
# External Commands, Warnings and Logging:
# You can use conversion specifiers for the on_xxxx commands
# %Y = year, %m = month, %d = date,
# %H = hour, %M = minute, %S = second,
# %v = event, %q = frame number, %t = camera id number,
# %D = changed pixels, %N = noise level,
# %i and %J = width and height of motion area,
# %K and %L = X and Y coordinates of motion center
# %C = value defined by text_event
# %f = filename with full path
# %n = number indicating filetype
# Both %f and %n are only defined for on_picture_save,
# on_movie_start and on_movie_end
# Quotation marks round string are allowed.
############################################################

# Do not sound beeps when detecting motion (default: on)
# Note: Motion never beeps when running in daemon mode.
quiet on

# Command to be executed when an event starts. (default: none)
# An event starts at first motion detected after a period of no motion defined by event_gap
on_event_start /usr/local/share/motion-pipeline/motion_pipeline/motion_handler.py --config=/etc/motion/mysettings.py --action=event_start --date="%Y-%m-%d %H:%M:%S" --event_id=%v --frame_num=%q --cam=%t --changed_px=%D --noise=%N --text_event="%C" --motion_width=%i --motion_height=%J --motion_center_x=%K --motion_center_y=%L --cam-name="%$" --threshold=%o --labels=%Q --fps=%{fps} --host=%{host}

# Command to be executed when an event ends after a period of no motion
# (default: none). The period of no motion is defined by option event_gap.
on_event_end /usr/local/share/motion-pipeline/motion_pipeline/motion_handler.py --config=/etc/motion/mysettings.py --action=event_end --date="%Y-%m-%d %H:%M:%S" --event_id=%v --frame_num=%q --cam=%t --changed_px=%D --noise=%N --text_event="%C" --motion_width=%i --motion_height=%J --motion_center_x=%K --motion_center_y=%L --cam-name="%$" --threshold=%o --labels=%Q --fps=%{fps} --host=%{host}

# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
# To give the filename as an argument to a command append it with %f
on_picture_save /usr/local/share/motion-pipeline/motion_pipeline/motion_handler.py --config=/etc/motion/mysettings.py --action=picture_save --date="%Y-%m-%d %H:%M:%S" --event_id=%v --cam=%t --text_event="%C" --filename="%f" --filetype=%n --cam-name="%$" --threshold=%o --labels=%Q --fps=%{fps} --host=%{host}

# Command to be executed when a motion frame is detected (default: none)
; on_motion_detected value

# Command to be executed when motion in a predefined area is detected
# Check option 'area_detect'.   (default: none)
; on_area_detected value

# Command to be executed when a movie file (.mpg|.avi) is created. (default: none)
# To give the filename as an argument to a command append it with %f
; on_movie_start value

# Command to be executed when a movie file (.mpg|.avi) is closed. (default: none)
# To give the filename as an argument to a command append it with %f
on_movie_end /usr/local/share/motion-pipeline/motion_pipeline/motion_handler.py --config=/etc/motion/mysettings.py --action=movie_end --date="%Y-%m-%d %H:%M:%S" --event_id=%v --cam=%t --text_event="%C" --filename="%f" --filetype=%n --cam-name="%$" --threshold=%o --labels=%Q --fps=%{fps} --host=%{host}

# Command to be executed when a camera can't be opened or if it is lost
# NOTE: There is situations when motion don't detect a lost camera!
# It depends on the driver, some drivers dosn't detect a lost camera at all
# Some hangs the motion thread. Some even hangs the PC! (default: none)
on_camera_lost /usr/local/share/motion-pipeline/motion_pipeline/motion_handler.py --config=/etc/motion/mysettings.py --action=cam_lost --date="%Y-%m-%d %H:%M:%S" --cam=%t --cam-name="%$" --host=%{host}