Tag Archives: time-lapse

Capture a webcam image with a simple bash script

I did that a few months ago to make a poor man's time-lapse video. This one. I said I'd post how to do it somewhere. Here it is.

This is a bash script that will capture an image from a webcam or similar video acquisition device. Works on Linux only I guess. Makes use of gstreamer and video for linux.


#!/bin/bash

DEST_DIR="$HOME/Pictures/Webcam"

if [ ! -e $DEST_DIR ]; then
    mkdir $DEST_DIR
fi

DAY_DIR="$DEST_DIR/`date +'%Y%m%d'`"
if [ ! -e $DAY_DIR ]; then
    mkdir $DAY_DIR
fi

PIC_FILE="$DAY_DIR/webcam-`date +'%H%M%S'`.jpg"
gst-launch v4l2src num-buffers=1 ! jpegenc ! filesink location=$PIC_FILE

Save as ~/bin/camera-snapshot, and put it in crontab every minute if you want :)
After a while you will have a folder filled with pictures.

If you also want to assemble them into a movie file, use the excellent ffmpeg.