How to create full HD time lapses with Python, ImageMagick and libav

I found myself in need of a small piece of code to create a time lapse movie from a couple of pictures I took a while ago ...

As it turns out my favorite tool to do that (ffmpeg) got forked and is now available on Debian Jessie as part of libav-tools, additionally you'd need ImageMagick's 'convert' command to process the images.

sudo apt-get install libav-tools imagemagick

This includes the command avconv, which replaces ffmpeg.

I placed all the photos I wanted into a separate folder and executed this small Python snippet in that folder:

 :::python
 import os
 ll = !ls
 for i,e in enumerate(ll):
     os.system('convert '+e+' -scale 1620x1080 img_scaled_%03d.jpg' % i)

You should note, that because my pictures had an aspect ratio of 3:2, the size of the scaled image is 1620x1080 to get full HD horizontal line resolution (1080p).

Now it's time to stitch it all together with avconv:

avconv -framerate 10 -i img_scaled_%03d.jpg -c:v libx264 -r 30 -pix_fmt yuv420p mytimelapse.mp4

I used a frame rate of 10 pictures per second, but the video will have 30 frames per second, meaning that 3 consecutive frames will be the same. As I'm converting this using a x264 codec, this shouldn't effect file size too much, but maybe produce a smoother rendering... Not sure about this one ...

Acknowledgements:

I used snippets from around the web, e.g. from ffmpeg howto pages here .