motion notes

Revision as of 12:06, 29 September 2017 by Root (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Beware of 800x600 resolution. Some versions of Motion have a bug that causes it to error out if the resolution is not a modulo of 16.


Edit the file /etc/motion/motion.conf. Below are the settings are most often change. I found that threshold is the most difficult to estimate. Every time I do a project I found that I kind of just have to do a few test runs with different threshold values until I find a value that works. The threshold values can be orders of magnitude different between different conditions.

videodevice /dev/video1
# HD 1080p resolution is 1920*1080 (2073600 pixels, or 2.1 megapixels)
# Logitech c910/c920 max resolution 2304 * 1296
# Note that some versions of Motion have a bug that requires the height to be a modulo of 16.
# There is a hack around this bug. Set the resolution to 1920x1200. The images will actually be
# captured at 1920x1080, but this will satisfy Motion.
# So, why will the camera capture at 1080? I'm not sure. 
# I suspect it just defaults to the nearest workable resolution.
width 1920
# Hack around the Motion modulo 16 bug.
height 1200

# Threshold for number of pixels that triggers motion detection (default: 1500).
# This sets the threshold to 10% of all pixels, which is a massive change in most conditions.
# This will make motion detection fairly insensitive and immune the minor movements.
# This is not a good setting for distant objects as they may never register as high as 10%.
# 1920 * 1080 = 2073600 pixels
# 2073600 * 10% = 207360
threshold 207360
noise_level 64

# %v is the event number.
movie_filename %Y%m%d%H%M%S-%v
timelapse_filename %Y%m%d-timelapse
gap 10
pre_capture 1
post_capture 1

text_right %Y-%m-%d\n%T-%q
# %v is the event number. %q is the frame number.
jpeg_filename %Y%m%d%H%M%S-%v-%q
snapshot_filename %Y%m%d%H%M%S-snapshot
snapshot_interval 1
#snapshot_interval 60
framerate 30

# jpeg quality
quality 95
# Valid values: 0 (default = no rotation), 90, 180 and 270.
rotate 0
minimum_motion_frames 2
text_right %Y-%m-%d\n%T-%q
text_changes on
text_double on

configuration with action scripts triggered on events

This configuration will turn lights on or off when motion is detected. This assumes that the camera can see in light conditions when the light is off.

# Don't set 800x600 due to the Motion modulo 16 bug.
width 640
height 480
#movie_filename %Y%m%d-%H%M%S-%v
#timelapse_filename %Y%m%d-timelapse
gap 3
pre_capture 0
post_capture 0
text_right %Y%m%d-%H%M%S-%v-%q
# %v is the event number. %q is the frame number.
jpeg_filename %Y%m%d-%H%M%S-%v-%q
snapshot_filename %Y%m%d-%H%M%S-snapshot
snapshot_interval 0
#snapshot_interval 60
framerate 1
videodevice /dev/video1
# Threshold for number of pixels that triggers motion detection (default: 1500)
# 10% is a massive change.
# 640*480=307200
# 307200 * 0.05 = 15360
threshold 15360
# jpeg quality
quality 95
# Valid values: 0 (default = no rotation), 90, 180 and 270.
rotate 0
# Motion events and end cause a light to turn on and off.
on_event_end br --port=/dev/ttyUSB0 --house=A --off=1
on_motion_detected br --port=/dev/ttyUSB0 --house=A --on=1

ERROR: Error opening file ...: Invalid argument and ffopen_open error creating (timelapse) file [...]: Invalid argument

This is caused by broken support for linking the old ffmpeg to the new libav-tools.

You can try to install the old ffmpeg tools.

add-apt-repository ppa:mc3man/trusty-media
apt-get update
apt-get install gstreamer0.10-ffmpeg

If that does not work then you can disable all the video creation options in motion.conf, such as timelapse. Hopefully this ffmpeg confusion will get sorted out someday.