Using motion

From XPUB & Lens-Based wiki

motion is a commandline program for a surveillance webcam.

Installation

apt-get install motion


Manual: http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionGuideBasicFeatures

Command line opts

      -c     Full  path  and  filename  of  config  file. E.g. /home/kurt/motion.conf. Default is /usr/local/etc
             unless specified differently when building Motion. Many RPMs and debian packages will  most  likely
             use /etc or /etc/motion as default.
      -h     Show help screen.


Config settings

Events

      on_event_end string
             Values: Max 4095 characters / Default: Not defined
             Command to be executed when an event ends after a period of no motion. The period of no  motion  is
             defined by option gap. You can use Conversion Specifiers and spaces as part of the command.
      on_event_start string
             Values: Max 4095 characters / Default: Not defined
             Command  to  be  executed  when  an  event starts. An event starts at first motion detected after a
             period of no motion defined by gap. You can use ConversionSpecifiers and spaces as part of the com‐
             mand.
      on_motion_detected string
             Values: Max 4095 characters / Default: Not defined
             Command  to be executed when a motion frame is detected. You can use Conversion Specifiers and spa‐
             ces as part of the command.
      on_picture_save string
             Values: Max 4095 characters / Default: Not defined
             Command to be executed when an image is saved. You can use Conversion Specifiers and spaces as part
             of the command. Use %f for passing filename (with full path) to the command.

Output Options

      output_motion boolean
             Values: on, off / Default: off
             Output pictures with only the moving object. This feature generates the special motion type  movies
             where you only see the pixels that changes as a graytone image. If labelling is enabled you see the
             largest area in blue. Smartmask is shown in red.
      output_normal discrete strings
             Values: on, off, first, best / Default: on
             Normal image is an image that is stored when motion is detected. It is  the  same  image  that  was
             taken  by the camera. I.e. not a motion image like defined by output_motion. Default is that normal
             images are stored.
      target_dir string
             Values: Max 4095 characters / Default: Not defined = current working directory
             Target directory for picture and movie files.

Tuning & Timing

      threshold integer
             Values: 1 - 2147483647 / Default: 1500
             Threshold for declaring motion. The threshold is the number of changed pixels counted  after  noise
             filtering, masking, despeckle, and labelling.
      gap integer
             Values: 0 - 2147483647 / Default: 60
             Gap is the seconds of no motion detection that triggers the end of an event. An event is defined as
             a series of motion images taken within a short timeframe.

Camera & Image

      quality integer
             Values: 1 - 100 / Default: 75
             The quality for the jpeg images in percent.
      videodevice string
             Values: Max 4095 characters / Default: /dev/video0 (FreeBSD: /dev/bktr0)
             The video device to be used for capturing. Default  for  Linux  is  /dev/video0.  for  FreeBSD  the
             default is /dev/bktr0.
      width integer
             Values: Device Dependent / Default: 352
             The width in pixels of each frame. Valid range is camera dependent.


      rotate discrete strings
             Values: 0, 90, 180, 270 / Default: 0 (not rotated)
             Rotate  image  the  given  number of degrees. The rotation affects all saved images as well as mpeg
             movies.

Program Control

      control_localhost boolean
             Values: on, off / Default: on
             Limits the http (html) control to the localhost. This option must be placed in motion.conf and  not
             in a thread config file.
      control_port integer
             Values: 0 - 65535 / Default: 0 (disabled)
             Sets  the  port  number for the http (html using browser) based remote control. This option must be
             placed in motion.conf and not in a thread config file.
      daemon boolean
             Values: on, off / Default: off
             Start in daemon (background) mode and release terminal. This option must be placed  in  motion.conf
             and not in a thread config file.
      quiet boolean
             Values: on, off / Default: off
             Be quiet, don't output beeps when detecting motion.

Image Parameters

      Conversion Specifiers for Advanced Filename and Text Features
             The table below shows all the supported Conversion Specifiers you can use in the options text_left,
             text_right, snapshot_filename, jpeg_filename, ffmpeg_filename, timelapse_filename,  on_event_start,
             on_event_end, on_picture_save, on_movie_start, on_movie_end, and on_motion_detected.
             In text_left and text_right you can additionally use '0 for new line.
      %a     The abbreviated weekday name according to the current locale.
      %A     The full weekday name according to the current locale.
      %b     The abbreviated month name according to the current locale.
      %B     The full month name according to the current locale.
      %c     The preferred date and time representation for the current locale.
      %C     Text defined by the text_event feature
      %d     The day of the month as a decimal number (range 01 to 31).
      %D     Number  of pixels detected as Motion. If labelling is enabled the number is the number of pixels in
             the largest labelled motion area.
      %E     Modifier: use alternative format, see below.
      %f     File name - used in the on_picture_save, on_movie_start, on_movie_end, and sql_query features.
      %F     Equivalent to %Y-%m-%d (the ISO 8601 date format).
      %H     The hour as a decimal number using a 24-hour clock (range 00 to 23).
      %i     Width of the rectangle containing the motion pixels (the rectangle that is shown on the image  when
             locate is on).
      %I     The hour as a decimal number using a 12-hour clock (range 01 to 12).
      %j     The day of the year as a decimal number (range 001 to 366).
      %J     Height of the rectangle containing the motion pixels (the rectangle that is shown on the image when
             locate is on).
      %k     The hour (24-hour clock) as a decimal number (range 0 to 23);  single  digits  are  preceded  by  a
             blank. (See also %H.)
      %K     X coordinate in pixels of the center point of motion. Origin is upper left corner.
      %l     The  hour  (12-hour  clock)  as  a  decimal number (range 1 to 12); single digits are preceded by a
             blank. (See also %I.)
      %L     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).
      %m     The month as a decimal number (range 01 to 12).
      %M     The minute as a decimal number (range 00 to 59).
      %n     Filetype as used in the on_picture_save, on_movie_start, on_movie_end, and sql_query features.
      %N     Noise level.
      %o     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.
      %p     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'.
      %P     Like %p but in lowercase: `am' or `pm' or a corresponding string for the current locale.
      %q     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.
      %Q     Number of detected labels found by the despeckle feature
      %r     The time in a.m. or p.m. notation.
      %R     The time in 24-hour notation (%H:%M).
      %s     The number of seconds since the Epoch, i.e., since 1970-01-01 00:00:00 UTC.
      %S     The second as a decimal number (range 00 to 61).
      %t     Thread number (camera number)
      %T     The time in 24-hour notation (%H:%M:%S).
      %u     The day of the week as a decimal, range 1 to 7, Monday being 1. See also %w.
      %U     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.
      %v     Event number. An event is a series of motion detections happening  with  less  than  'gap'  seconds
             between them.
      %V     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.
      %w     The day of the week as a decimal, range 0 to 6, Sunday being 0. See also %u.
      %W     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.
      %x     The preferred date representation for the current locale without the time.
      %X     The preferred time representation for the current locale without the date.
      %y     The year as a decimal number without a century (range 00 to 99).
      %Y     The year as a decimal number including the century.
      %z     The time-zone as hour offset from GMT.
      %Z     The time zone or name or abbreviation.


Setting up an Apache Reverse Proxy to your motion webcam

Installing apache on a pi:

apt-get install apache2


   <VirtualHost *:80>
   # ... all the normal stuff
   # ADD THESE TWO LINES... make sure the port numbers match motion's settings
   ProxyPass /w http://localhost:8000
   ProxyPass /c http://localhost:8080
   </VirtualHost>

To enable reverse proxies in Apache

a2enmod proxy proxy_http