Monday, December 05, 2011

Time Lapse with ffmpeg

Because I do it too infrequently to remember, here's how to put together time lapse/stop motion/animation with ffmpeg.

Firstly renumber you images*. Make sure that this script won't overwrite anything.

x=1; for i in *.JPG; do counter=$(printf %04d $x); mv "$i" img"$counter".JPG; x=$(($x+1)); done

Then put the images together.

ffmpeg -ss 1 -t 70 -i music.mp3 -r 15 -i img%04d.JPG -b 15M -s 1440x1080 out.avi

The ffmpeg documentation mentions using the "image file demuxer" -f image2 before the input image file name template, but I haven't found that necessary.

Remember that ffmpeg options act on the next input or output, so for example you can set the frame rate of the animation by using -r x before the input image parameter or set the frame rate of the resultant video by using the same switch before the output filename.

In the above example we also add a sound track, starting 1 second into the track and cut after 70 seconds.

* You're images must be numbered sequentially starting at 1.

No comments:

Post a Comment