Wednesday, 8 January 2014

Timelapse with Rapberry Pi camera module

As I have mentioned before I always wanted the camera module for the Raspberry Pi. Until now I had only tried out timelapse using my laptop web camera, and that gave me really crappy images. Now I have the camera module to play with and the images are way better. This is timelapse from 12:00 31. Des 2013 to 12:00 1. Jan 2014 shows 24 Hours in 5 minutes and 26 sec. including some fireworks.

This script will take image every 5 seconds 1440 times leaving you with just enough to create 60 sec timelaps video using 24 fsp

# Timelapse controller for USB webcam
while [ $x -le 1440 ]; do                                                       
filename=$(date -u +"%Y%m%d-%H%M-%S").jpg                                       
raspistill -o $DIR/$filename -w 1280 -h 960 -n -t 1000
x=$(( $x + 1 ))
sleep 5;

Now you have 1440 images or the number you entered and next step is to create the video. Copy the images to your computer using scp or rsync, you can add that to your script if the Raspberry pi is connected to network. When you have all your images on your computer you can render video with mencoder. Install mencoder if needed.

sudo apt-get install mencoder

ls $DIR/*.jpg > list.txt
mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=640:480 -o $DIR/$(date -u +"%Y%d%m-%H%M-%S").avi -mf type=jpeg:fps=24 mf://@list.txt
rm list.txt

All ideas about improving this code are welcome.