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
cd /usr/local/ffmpeg
./configure --enable-shared
make
make install
This creates the
libavcodec.so and
libavformat.so libraries under
/usr/local/lib and header files under
/usr/local/include/ffmpeg.
You probably need to do one more step.
Make sure you have 'root' privileges for the next steps.
Open the file
/etc/ld.so.conf in your favorite text editor.
Add this line of text if it is not already there - otherwise go to the next step (ldconfig).
/usr/local/lib
Run the command
ldconfig.
Motion should now be able to find the shared libraries for ffmpeg (
libavcodec.so and
libavformat.so) in
/usr/local/lib.
You can also find a pre-compiled binary package (e.g. rpm or deb) and install this. Normally an rpm will place the
libavcodec.so under
/usr/lib.
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
./configure,
make and
make install.
(Note that with earlier versions of motion you had to specify the location of libavcodec. Now configure searches for the shared library in
/usr/lib and
/usr/local/lib by default.)
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.
ffmpeg_bps
- Type: Integer
- Range / Valid values: 0 - 9999999
- Default: 400000
- Option Topic
Bitrate of mpegs produced by ffmpeg. Bitrate is bits per second. Default: 400000 (400kbps). Higher value mans better quality and larger files. Option requires that ffmpeg libraries are installed.
To use this feature you need to install the
FFmpeg Streaming Multimedia System.
Experiment to get the desired quality. The better quality the bigger files. This option is ignored if ffmpeg_variable_bitrate is not 0 (disabled).
ffmpeg_cap_motion
- Type: Boolean
- Range / Valid values: on, off
- Default: off
- Option Topic
Use ffmpeg libraries to encode motion type mpeg movies where you only see the pixels that changes.
Works like ffmpeg_cap_new but outputs motion pixel type pictures instead.
This feature generates the special motion type movie 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. The filename given is the same as the normal mpegs except they have an 'm' appended after the filename before the .mpg. E.g. 20040424181525m.mpg
To use this feature you need to install the FFmpeg Streaming Multimedia System
ffmpeg_cap_new
- Type: Boolean
- Range / Valid values: on, off
- Default: off
- Option Topic
Use ffmpeg libraries to encode mpeg movies in realtime.
Generates a new film at the beginning of each new event and appends to the film for each motion detected within the same event. The current event ends when the time defined by the 'gap' option has passed with no motion detected. At the next detection of motion a new mpeg film is started.
To use this feature you need to install the
FFmpeg Streaming Multimedia System
Must not be included in config file without having ffmpeg installed.
ffmpeg_deinterlace
- Type: Boolean
- Range / Valid values: on, off
- Default: off
- Option Topic
Use ffmpeg to deinterlace video. Necessary if you use an analog camera and see horizontal combing on moving objects in video or pictures.
To use this feature you need to install the
FFmpeg Streaming Multimedia System
Must not be included in config file without having ffmpeg installed.
ffmpeg_timelapse
- Type: Boolean
- Range / Valid values: 0 - 2147483647
- Default: 0 (disabled)
- Option Topic
Create a timelapse movie saving a picture frame at the interval in seconds set by this parameter. Set it to 0 if not used.
This feature uses ffmpegs libavcodec to encode a timelaps 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)
ffmpeg_timelapse_mode
- Type: Discrete Strings
- Range / Valid values: hourly, daily, weekly-sunday, weekly-monday, monthly, manual
- Default: daily
- Option Topic
The file rollover mode of the timelapse video.
Note that it is important that you use the conversion specifiers in ffmpeg_filename that ensure that the new timelapse file indeed is a new file. If the filename does not change Motion will simply append the timelapse pictures to the existing file.
The value 'Manual' means that Motion does not automatically rollover to a new filename. You can do it manually using the http control interface by setting the option 'ffmpeg_timelapse' to 0 and then back to your chosen value. Value 'hourly' rolls over on the full hour. Value 'daily' which is the default rolls over at midnight. There are two weekly options because depending on where you come from a week may either start on Sunday or Monday. And 'monthly' naturally rolls over on the 1st of the month.
ffmpeg_variable_bitrate
- Type: Integer
- Range / Valid values: 0, 2 - 31
- Default: 0 (disabled)
- Option Topic
Enables and defines variable bitrate for the ffmpeg encoder. ffmpeg_bps is ignored if variable bitrate is enabled. Valid values: 0 (default) = fixed bitrate defined by ffmpeg_bps, or the range 2 - 31 where 2 means best quality and 31 is worst.
Experiment for the value that gives you the desired compromise between size and quality.
ffmpeg_video_codec
- Type: Discrete Strings
- Range / Valid values: mpeg1 (ffmpeg-0.4.8 only), mpeg4, msmpeg4, swf, flv, ffv1, mov
- Default: mpeg4
- Option Topic
Codec to be used by ffmpeg for the video compression. Timelapse mpegs are always made in mpeg1 format independent from this option.
- mpeg1 - gives you mpeg1 files with extension .mpg. It is only supported by the old ffmpeg version 0.4.8. The ffmpeg team decided no longer to support non-standard framerates for mpeg1 from ffmpeg version 0.4.9pre1.
- mpeg4 - gives you mpeg4 files with extension .avi
- msmpeg4 - also gives you mpeg4 files. It is s recommended for use with Windows Media Player because it requires with 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 (since 3.2.10).
This option does not affect the timelapse feature. Timelapse is always recorded in mpeg1 format because we need to be able to append to an existing file. mpeg4 does not easily allow this.
See also the section
Advanced Filenames where the two additional options
ffmpeg_filename and
timelapse_filename are defined.
If you want to use this feature you can read about the
FFmpeg Streaming Multimedia System
--
KennethLavrsen - 18 Dec 2005