Motion - Motion With F Fmpeg Discussion

Motion with FFmpeg

Introduction

This topic was started to host a discussion of Motion's support for FFmpeg. FFmpeg is a solution for encoding and decoding video and audio using a great number of different codecs and formats. Motion uses the FFmpeg libraries, libavcodec and libavformat, to generate mpeg movies using either MPEG1, MPEG4 or MSMPEG4 codec.

Motion supports the latest stable FFmpeg version, 0.4.8, but unfortunately not the latest unstable version, 0.4.9pre1. The reason is twofold:

  • The API for writing video frames using libavformat has changed. This is not a problem, though - it is easy to update Motion to use the new API.
  • Support for MPEG1 videos with non-standard framerates has disappeared. This is worse!

While MPEG4 supports basically any framerate, MPEG1 only supports a limited number of framerates. Motion users typically use (I think, at least) non-standard framerates, ranging from 2 to 25. FFmpeg version 0.4.8 contains a hack that accepts a non-standard framerate, but fills the video with empty frames in order to obtain a supported framerate. This hack has been removed in version 0.4.9pre1, because it was broken (it didn't work in certain situations).

MPEG1 vs. MPEG4

As mentioned above, MPEG4 supports basically any framerate, while MPEG1 supports only a limited set of framerates.

Another important difference between the codecs is that a MPEG1 video stream can be interrupted at any point and still be playable. MPEG4, on the other hand, requires a special trailer to be written to the video file, before it can be played.

There are, of course, many more differences than the two listed here. These are not important for the discussion, though, and will be disregarded.

Motion and Codecs

So, what does Motion use? There are two quite different cases:

  • Normal video output: In this case, Motion uses the codec provided in motion.conf, which is either MPEG1, MPEG4 or MSMPEG4. Framerate can be virtually anything.
  • Timelapse: In this case, Motion uses MPEG1. Framerate is hardcoded to 24, which is close to a standard MPEG1 framerate, 23.976.

The reasons for using MPEG1 for the timelapse feature are that the video must be possible to play after having been interrupted, Motion must be able to continue recording to an existing video file and timelapse recoding must be possible to pause and resume. These requirements cannot be met with MPEG4.

What's the Problem?

The problem is as follows: If we want to keep up with the evolution of FFmpeg, we have to accept the fact that the hack for supporting non-standard MPEG1 framerates disappears. If not, then we're fine. Thus, there are two possible ways out:

  1. Stick to FFmpeg 0.4.8. If this is the right way, then we should make the configure script warn if the FFmpeg version is too high.
  2. Adapt Motion to FFmpeg 0.4.9+. This way requires the following:
    • Since timelapse runs at a near-standard framerate, we can keep MPEG1 for the timelapse feature.
    • Drop the support for MPEG1 in the configuration file. In other words, only allow MPEG4 and MSMPEG4.

In case of (2), the question is if people are willing to abandon MPEG1 for normal videos.

Conclusions

It's possible to go in two different directions. Which one do you think is the right one?

-- PerJonsson - 08 Nov 2004

Comments and Discussion

I will support a solution where we:
  • Continue to support MPEG1 for the motion generated mpegs for ffmpeg-0.4.8
  • Discontinue support of MPEG1 for ffmpeg-0.4.9+
  • Continue timelapse support only in MPEG1 for both 0.4.8 and 0.4.9+
  • Maybe add additional codecs supported given that they support low framerates also.

I do not want Motion to get stuck on an old ffmpeg version. On the other hand I do not want Motion users that currently uses mpeg1 - maybe for professionel surveillance solutions - to be in a situation where they cannot upgrade Motion any longer. They should be able to upgrade Motion but stay with the ffmpeg-0.4.8 and do MPEG1. This may not be supported forever but at least 6-12 months more. And it does not cost anything. We just leave the old code there and add the new ffmpeg-0.4.9+ related code inside #ifdef statements.

As always I would love to hear user feedback on this plan. I always listen and consider any good feedback and proposals.

-- KennethLavrsen - 09 Nov 2004

The FFmpeg 0.4.9 patch has been updated according to the discussion above. It's available here: FfmpegPatch049

-- PerJonsson - 29 Nov 2004
Topic revision: r3 - 29 Nov 2004, PerJonsson
Copyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Please do not email Kenneth for support questions (read why). Use the Support Requests page or join the Mailing List.
This website only use harmless session cookies. See Cookie Policy for details. By using this website you accept the use of these cookies.