Home | About | Apps | Rss

FFMPEG: Create video from sequence of Images

29 May 2014

I was recently working on creating a timelapse video from about 90 images, each of which is a 3-6 second exposure, which I shot during one of my bike trips.

rename files

The images in JPG format, shot on 5D-Mark2, needed renaming to ‘img_%d.jpg’ format, which I quickly did with a simple python script

>>> import os
>>> from glob import glob
>>> for i, f in enumerate( glob('*.jpg') ):
...     os.rename( f, 'img_%d.jpg' % i )


The images were all of 5616x3714 resolution. Using this one liner I bought it down to 1280x853 and moved them to a folder r1280_seq0

for each in *.jpg; do
> convert $each -resize 1280x -quality 85% "r1280_seq0/$each"
> done


I needed ffmpeg which I setup using brew

$ brew install ffmpeg

convert to video

And for actual conversion, here is how I did it

$ffmpeg -r 10\
	-i img_%d.jpg\
	-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"\
	-pix_fmt yuv420p\

Notes & Pitfalls::

  • frame rate - is set using the -r flag. I wanted 10fps above.

  • height not divisible by 2 - This is a common issue when images are not of even dimensions. Using the flag -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" fixes this problem by resizing video to an even numbered dimension.

  • Blank video - Some older version of video players require some additional encoding information. This is achieved using -pix_fmt yuv420p

  • Frame rate - it can be set using the -r flag


Using Attributed Strings on iOS | | List directories in python