How to make a Time-lapse video with linux

Posted on by
Basil growing: ninth day

Basil growing: ninth day

The time-lapse video are an excellent way to acquire a new time perspective of our environment. One of the most common uses is to observe the growth of plants, creating videos that compress days in just a few seconds. If you want to create your own time-lapse video below we explain how you can do so using a mobile phone Android as an IP camera and a Raspberry PI for storage and further processing of the video.

IP camera

To use an Android smartphone as IP camera configure it as explained earlier Android phone as wi-fi camera. In this way we will have a URL to which each time you access a picture will trigger, the address will look as follows:

http://IP:PORT/photoaf.jpg

Script

After setting the IP camera we will have to create a script to save the photo and and name it. In this case the script supports the use of username and password to access our IP camera, if we have configured so previously. Also we perform management errors by jpeginfo so if the picture is not correct it will be deleted and shoot again until it contains no errors.

#!/bin/bash
# Webcam URL
URL_WEBCAM="http://IP:PORT/photoaf.jpg"
# User
USER=""
# Password
PASS=""
# Output DIR
DIR="/home/MYNAME/Pictures/timelapse-photos/"

NAME=`date +%d-%m-%Y_%H:%M:%S`
wget --no-check-certificate --no-verbose --user $USER --password $PASS $URL_WEBCAM -O $DIR$NAME.jpg
jpeginfo -d $DIR$NAME.jpg
while [ ! -f $DIR$NAME.jpg ] ; 
    do 
        NAME=`date +%d-%m-%Y_%H:%M:%S`
        wget --no-check-certificate --no-verbose --user $USER --password $PASS $URL_WEBCAM -O $DIR$NAME.jpg
        jpeginfo -d $DIR$NAME.jpg
    done

Add to Crontab

To run our script periodically add to crontab. To do this you set how often want to take a picture. Keep in mind that we will use to make a video 24 frames per second, so that if we take a picture every 10 minutes, the resulting video will be 12 seconds per 24 hours. Depending on your needs you can make photos in other intervals. For them we edit crontab using the following command:

$ crontab -e
 And we add the following line to perform a photo every 10 minutes:
10 * * * * /home/MYNAME/scripts/timelapse.sh

Convert to video

Finally, once we have all the pictures we need to make the video do the following:

$ cd /home/MYNAME/Pictures/timelapse-photos/
$ ls > frames.txt
$ mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -o timelapse.avi -mf type=jpeg:fps=24 mf://@frames.txt

Once this is done we will have our time-lapse video.

Example video

Basil video growth for 10 days.

Comments are disabled