Time lapse how to (Linux)

This, I hope, is the definitive version of the time-lapse how to. Having had earlier cracks at it, I think this one represents the refined source. Here’s the how to.

1. A capture script

#!/bin/bash

cd $HOME/captures

D1=`date +%Y-%m-%d`
D2=`date +%Y%m%d_%H-%M-%S`

# If the date directory does not exist, create it
if [ ! -d $D1 ] ; then
mkdir -p $D1
fi

#cd to this new directory
cd $HOME/captures/$D1

# fswebcam seems to solve the problems with streamer and vlc. The -S option
# is 'skip' which brilliantly discards the first N frames before
# saving the final one. The -r option is for 'resolution' i.e. size of
# recorded frame in pixels

fswebcam -d /dev/video0 -S 10 -r 320x240 $D2.jpg

Save this somewhere (remember where)
NB – if you want to use an external webcam, check if it is on video1 and alter the last line accordingly.

2. Edit your crontab
crontab -e
add a line like this one:
*/5 * * * * /PATH/TO/CAPTURE/SCRIPT.sh
(insert the real path to where you put the capture script after the space after the last star)

3. Pyrenamer is your friend
The nice script in capture.sh writes files with the current date and time. I copy the images I want into a folder within the date folder within captures and then rename these with pyrenamer, thus keeping an archive of the images should anything go wrong. You can also trim images you don’t want in the final film this way. Using the num3 option in pyrenamer, your images will end up sequentially numbered like 001.jpg, 002.jpg, 003.jpg…

4. Stitch together into a film with ffmpeg
cd to the directory with the sequentially numbered images
evoke ffmpeg like so
ffmpeg -r 8 -intra -qscale 1 -i %03.jpg NameOfFilm.mp4
the -r is the frame rate, -intra turns of motion detection, -qscale makes it best quality.

This entry was posted in Bash scripting, Code, Linux, Software, Webcam and tagged , , , . Bookmark the permalink.