Before you start - consider using ffmpeg instead. It is a much more up to date way to generate mpegs and ffmpeg has much more features.
It is being considered removing support for the mpeg_encode in a future version of Motion. If you would like to keep this feature in the future let us know on the Motion Mailing List.
To use this feature you need to install the
Berkeley mpeg_encode program.
The program is pretty old (1995) and there has been some problems with compiling the source code. There is a guy doing an exciting project called
AMIDE. This project includes the mpeg_encode program and it seems that the author of AMIDE has polished the old mpeg_encode a little bit calling it 1.5c. The author has placed 2 versions. A binary only RPM for the Intel 386 platform and two RPMs with full source. I installed just the binary RPM from the AMIDE site and it worked fine. The binary RPM contains only two files: mpeg_encode itself which it installs in /usr/bin and a manual page. Motion looks for the mpeg_encode in /usr/bin per default. You can change this by setting config file option mpeg_encode_bin.
The feature itself works like this:
Every time motion detects motion a jpg picture is stored. This happens at the framerate you have specified with the 'framerate' option (or at the interval set by the 'minimum_gap' option if different from zero). When the event is over (time defined by the 'gap' option) motion generates a small mpg film using mpeg_encode. This is important to notice when you test the feature the first time. You will have to wait the period defined by 'gap' before you see the mpg file on your disk. If you have used a small framerate or used the minimum_gap option the film is going to be over in a split second. For this feature to be useful you should let motion store pictures almost real time. To generate better films you can play with options like 'post_capture' which will take extra picture after a motion is detected to create better floating films and 'adjust_rate' which will try to generate a 25 fps film. To avoid your harddisk from getting full because a bird is hopping around on the lawn, there are two parameters you can use. 'jpg_cleanup' will delete all the jpg files once the mpeg has been generated. 'max_mpeg_time' limits the duration of an mpeg film to the number of seconds you specify.
The following motion.conf settings controls the Berkeley mpeg_encode feature and shows the typical setting one would choose
############################################################
# Film (mpeg) File Output - Berkeley mpeg_encode Based
############################################################
#Use mpeg_encode from berkeley to encode movies (default: off)
mpeg_encode on
#Path to the mpeg_encode binary (default: /usr/bin/mpeg_encode)
mpeg_encode_bin /usr/bin/mpeg_encode
#Adjust the number of frames for an mpeg movie (only mpeg_encode) to get 25fps (default: off)
adjust_rate on
#Delete jpeg images after they have been converted to movies by mpeg_encode (default: off)
#This option is only used when mpeg_encode is on
jpg_cleanup on
Important! The Berkeley mpeg_encode feature requires that the motion.conf options for target_dir and filenames follows some strict rules:
- Your target_dir option should be an absolute path (starting with /) when using mpeg_encode.
- The option berkeley_single_directory controls the directory structure below target_dir: 'on' = place mpeg_encode file in target_dir/YYYYMMDDHHMMSS-n, 'off' (default) = place files as target_dir/YYYY/MM/DD/SS-n.
- If you set berkeley_single_directory 'on', jpeg_filename must be %v-%Y%m%d%H%M%S-%q
- If you set berkeley_single_directory 'off', jpeg_filename must be %Y/%m/%d/%H/%M/%S-%q
The reason is that mpeg_encode needs to know where to find the jpegs and it depends on details in the filenames to build the mpeg.
These are the motion.conf options to watch out for.
#File path for motion triggered images (jpeg or ppm) relative to target_dir
#Default: %v-%Y%m%d%H%M%S-%q
#Default value is equivalent to legacy oldlayout option
#For Motion 3.0 compatible mode choose: %Y/%m/%d/%H/%M/%S-%q
#File extension .jpg or .ppm is automatically added so do not include this
#For use of Berkeley mpeg_encode this parameter but be set as follows:
#If berkeley_single_directory = on: %v-%Y%m%d%H%M%S-%q
#If berkeley_single_directory = off: %Y/%m/%d/%H/%M/%S-%q
jpeg_filename %v-%Y%m%d%H%M%S-%q
#Use single directory structure (For Berkeley mpeg_encode feature only)
#on = place mpeg_encode file in target_dir with name YYYYMMDDHHMMSS-n
#off (default) = place files as target_dir/YYYY/MM/DD/SS-n
berkeley_single_directory off
--
KennethLavrsen - 19 Sep 2004