How to create a timelapse video with mencoder

While OSX 10.6 would come with the Pro version of Quicktime that can create timelapses via a fancy GUI etc. I’m currently running 10.5, so Quicktime Pro was out of the question. Of course, as an old Linux user I’m familiar with the command-line and have some experience in getting mplayer / mencoder to do what I want it to.

I’m using this to document my whole process. To see the final scripts / options / tools, you’ll need to skip to the end.

So Google to the rescue and I came up with a good starting point for creating the movie from my resized images. Santtu Pajukanta has a detailed description of how he created a timelapse.

However, since I didn’t want to package with Matroska because I wanted to later edit the videos I looked around a bit more and found some info on how to package it all into a mov-file. I basically adapted code from Trevor Shannon to do this.

At this point I had a scripted setup that took the FullHD sized images and made two passes over the data and created a timelapse movie. I also parametrised the framerate because at this point I was still playing around with different framerates to see which one would work the best. Unfortunately, the end result was quite poor in quality, so I went looking for more options on how to create the movie. I also had a hard time playing the movie in anything other than VLC on my Mac.

So some more digging around pointed me towards using MP4Box from the Debian package gpac to box the movie. I also adapted the three-pass approach used in ripping to encode the movie as well. Unfortunately again the end result wasn’t exactly what I needed. While the quality was good, end movie size was huge (around 500 MB for a minute of video) and playback wasn’t smooth on either Mac we have in the house (a two year old iMac 24 and year old MacBook).

So I started looking into the bitrate I was using and found the following formula:

optimal_bitrate = 50 * 25 * width * height / 256

For some reason this formula led to an impossible large bitrate that even mencoder complained about. Finally I settled for 80 000 kbit/s which seemed to do the trick well enough.

But now I still had video that was large and didn’t work smoothly. However, I figured that this was still raw footage and after editing each day’s video together in iMovie I’d get a usable result. And then I found out that the movies I’d made could not be imported into iMovie. At this point I’d already used a couple of weeks to create the various versions of the movies.

So, a bit more digging around Google and I finally found a email list posting that gave options on how to create a raw video with mencoder that can then be edited with iMovie. I adapted the command in the posting to suit the creation of a timelapse and ended up finally with:

mencoder ‘mf://1080p/*.JPG’ -ovc x264 -of lavf -lavfopts format=mp4 -x264encopts crf=18:nofast_pskip:nodct_decimate:nocabac:global_header:threads=4:subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b:threads=auto:bitrate=${BITRATE} -nosound -noskip -mf type=JPG:fps=${FPS} -o $FINAL

Note that this does not scale the images at all. I prescaled and cropped the images to 1920×1080 using other tools.

In the final version I used a bitrate of 80 000 and fps of 24. This resulted in around 500 – 600 MB videos for each day (around one minute of footage). I then imported these videos into iMovie and created some titles and credits and added some music to the whole thing. From iMovie I exported everything as a HD movie (720p) and the end result was a bit over eight minutes of footage and a file size of 596.1MB. More information on the final timelapse in this post.

All in all, it was a good learning experience and I noticed that iMovie won’t do if I want to create FullHD footage once I get the 7D. But that’s an issue that can be solved then.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.