2009-06-28

Save video from webcam images

It was 7 years ago, when I played with saving my web camera images and creating time-lapse videos from them on Windows. Later on, after more years I made a Youtube video with sound from those small clips (of course under Linux, with the Kdenlive program). It can be viewed here: My old timelapse


Now I thought it would be nice to collect the images from a few webcams at beautiful places, and create time-lapses. So I wrote a webcam script to save each images into a directory named by the current date, and with jpg files named from the current time:
#!/bin/bash
DIR=/path_to_webcams/webcam_name
DIR2=`date '+%Y-%m-%d'`
FILE=`date '+%H%M'`
mkdir $DIR/$DIR2
wget -o /dev/null -O $DIR/$DIR2/$FILE.jpg http://url-to-the-webcam-image

Then placed a cron job into the /etc/crontab (called in every 2 minutes):
*/2 * * * * root /root/webcam_script.sh

While the computer on (this is on all time) it collects the images. Then the next step is to create a time-lapse video from the images. This script creates an avi video - without sound - from them, execute from the directory of the images (needs mencoder to be installed):
#!/bin/bash
ls -1tr > files.txt
mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:mbd=1:vbitrate=6000 -o video.avi -mf type=jpeg:fps=25 mf://@files.txt
rm files.txt


Now you can edit your time-lapses using Avidemux, Kdenlive or any other application. Enjoy your time-lapse videos!

No comments:

Post a Comment