Assemble images to webm timelapse video

The first thing you want to make a timelapse video is a time ordered list of images. Most cameras and camera-apps for smartphones will output a list like this:

1329060850643-orig.jpg
1329060910843-orig.jpg
1330697938415-orig.jpg
1342539209542-orig.jpg
1342979413084-orig.jpg
1342979661474-orig.jpg

Since we want 1920×1080 images and since avconv requires an ordered list with sequential numbers, we’ll use a small script to go over the files and crop and rename them:

#!/bin/bash

mkdir 1920 2>/dev/null

count=0

for IMG in *.jpg ; do
        NEW=$(printf "FRAME_%05d.jpg" $count)
        ((count++))
        convert -crop 1920x1080+0+0 -gravity center $IMG 1920/$NEW
done

You may want to change the convert -crop settings to get better results and/or resize/resample the image before cropping.

The next step will assemble the images into a webm video:

CPUS=$(( $(grep bogo /proc/cpuinfo |wc -l) - 1 ))
avconv -i 1920/FRAME_%05d.jpg -threads $CPUS -s 1920x1080 -preset libvpx-1080p -b 4800k -pass 1 -an -f webm -y "timelapse.webm"
avconv -i 1920/FRAME_%05d.jpg -threads $CPUS -preset libvpx-1080p -b 4800k -pass 2 -an -f webm -y "timelapse.webm"