Webcam Timelapse


I got a model kit that I expected would take several hours to build, and I thought making a timelapse of the build would be fun. After looking at a few commercial apps that could create a timelapse, I thought it might be easier to write a small script that does it. Below is what I came up with.

#!/usr/bin/env bash

# trap ctrl-c and call ctrl_c()
trap ctrl_c INT

function ctrl_c() {
    ffmpeg -framerate 15 -pattern_type glob -i "*.jpeg" -s:v 1280x720 -c:v libx264 -crf 17 -pix_fmt yuv420p timelapse.mp4
    exit 0

for i in $(seq -f "%05g" 1 10000)
    echo "Frame ${i}"
    streamer -s 1280x720 -f jpeg -o image${i}.jpeg
    sleep 5

This script depends on ffmpeg to generate the actual video, but implements capture using streamer in a loop. The 10000 loop length can be adjusted, as can the sleep value of 5 according to taste. It traps Ctrl-C, so you don't have to worry about the 10000 being exactly just needs to be long enough that it doesn't stop before you want it to.