Creating a timelapse video using mencoder and ffmpeg on a Mac

The problem: Take 1500 images captured from my Raspberry Pi and turn them into a 1080 HD video suitable for upload to YouTube, Facebook, and Vimeo.

The solution: Install ffmpeg and/or mencoder and use either tool to from the Terminal on my mac to compile the images into a suitable video format.

To install the command line tools ffmpeg and mencoder I followed this tutorial from aktagon.com which points you to the binaries available from Mac OSX port website ffmpegx.com, which in turn points you to a few other sourceforge websites to download what you need. Once your set and you can run ffmpeg and mencoder from the command line, you’re ready to go.

The first method I tried was using ffmpeg. I tried this originally with a smaller resolution timelapse (720 HD) and it compiled quickly and easily with a relatively small filesize. Thanks to Greg Heartsfield for the instruction on this approach.

ffmpeg -r 25 -s hd720 -vcodec libx264 -b 1000k timelapse.mp4 -i image%04d.jpg

This roughly translates as: use ffmpeg, with a frame rate of 25fps, with settings preset ‘hd720’, with the H.264 codec, to encode a video with a bit rate of 1 Mbit/s called ‘timelapse.mp4’ using jpg files that follow a image0001, image0002, image0003 etc schema.

However, my timelapses weren’t consistent with this approach, and on some I got tearing and grey blocks across the screen. It may be my ageing MacBook was to blame, but instead I sought an alternative approach. So after failing to compile the video using mencoder with the H.264 codec from this post on a Ubuntu forum, I settled on this PasteBin code from a RaspberryPi For Beginners YouTube:

The first line of the code is a handy trick to list all the jpg files of the current directory and save them to a text file. The second line I’m less certain of as I’m unfamiliar with mencoder, and with the success of this encode my desire to trawl Google was somewhat diminished. However, it should be said that this method took a lot longer to encode than ffmpeg and playback was still jerky in places – but I’m definitely putting that down to the MacBook. I would have also have liked to have used the H.264 codec but I couldn’t get the code I’d found elsewhere to work…

Do let me know of any improvements to the code above, or alternative/more reliable methods for encoding jpgs into a timelapse video.

Leave a Reply

Your email address will not be published. Required fields are marked *