How to create time lapse video using a webcam

Simple Time-Lapse

Time-lapse animations have always fascinated me. With a time-lapse you can make things visible to the human eye that are normally happening too slow. The movement of stars in the sky or the process of putting up a house are very interesting to look at when the clock has been accelerated.

Apart form creating time-lapse animations using my own pictures I also found it worthwhile to create them from web-cam images. A webcam near the place I live provides images of quite high resolution. With the little script below, I was able to create this video: Fog over Dornbirn

I found that for videos that include clouds it is ok to take a frame every 5 seconds or so. As I don’t have the time and patience to save the webcam images manually, I created this bash script which was improved by Jürgen Hofer subsequently:

# !/bin/bash
# copyright Philipp Salzgeber - www.salzgeber.at
# adapted by j! for cleaner results
# first cmd line parameter is the delay in seconds (optional, default is 60)
# script stops if there is the file 'killme' in directory (for remote stop via dropbox)

divider=${1-60}
url=http://karren.protask.at/record/current.jpg

let "pause= $divider * 90 / 100"
while [ ! -f ./killme ]; do 
 #wait for zero crossing
 secs=$(date -u +%s)
 let "mod= $secs % $divider"
 while [ $mod -ne 0 ]; do
 secs=$(date -u +%s)
 let "mod= $secs % $divider"
 done;
 # create a filename with date and time portion
 filename=$(date -u +"%Y%m%d_%H_%M_%S").jpg
 # use wget to download the current image from the webcam
 wget -nv $url -O $filename
 # wait
 sleep $pause;
done;
echo exit condition found

Download the script here: timelapse.sh

Of course you have to replace the url with a meaningful one.

To be able to use the power of bash on my windows machine, I installed cygwin, which creates a linux-like environment, with the ability to use many of the linux command line tools. To be able to use wget you have to manually install it by selecting it from the available packages during the install process.

To create the final movie, I import the images in to picasa, sort the folder by name to make sure they are in the right order, select all of them and click the “Movie” button. Select “time-lapse” for the transition and you are ready to create the video.

Since the start of the eruption of the Eyjafjallajökull volcano, I assembled quite a few time-lapse animations using the vodafone webcam. Some videos were created like the one above, by downloading the current image every few seconds.

Downloading the vodafone webcam archive

But the vodafone webcam has an archive of images for every minute of a given day, that means, you can create such time-lapse animations after the fact, you just have to harvest the folders and download the individual images one-by-one.

As a complication, the images are actually two images stored side-by-side:

To be able to use the image in Picasa you first have to cut in two halves. At first I did that using batch conversion in IrfanView, but in the end I came up with a script that does also the slicing of the image. To be able to do that I had to install ImageMagick in cygwin by selecting it in the cygwin setup.

There was a problem with the installation of ImageMagick, see the instructions below on how to resolve the issue.

This is the bash script that downloads all the images for a given day from the vodafone server. You must provide a day, and you can provide a month and a year, if no month and year are given they are determined based on the current date. The script writes the downloaded images in a folder which is named for the current date. In this folder two sub-folders are created which contain the left and right part of the image, already cropped to the 16:9 aspect ratio necessary for creating HD videos in youtube.

# !/bin/bash
# 
# if no day is provided print out usage
if [ -z "$1" ]; then 
  echo "usage: $0 day [month] [year]"
  exit
else
  d=$1
fi
# if no parameter is provided for the month, use the current month
if [ -z "$2" ]; then
  m=$(date -u +"%m")
else
  m=`(printf "%02i" $2)`
fi
# if no parameter is provided for the year, use the current year
if [ -z "$3" ]; then
 y=$(date -u +"%Y") 
else
  y=$3
fi
 
# assemble the directory name
dirname=${y}${m}${d}
# create sub-directories for the cropped versions of the image
mkdir -p ${dirname}/right/
mkdir -p ${dirname}/left/
# loop through the hours of the day
for j in {0..23}
  do
  # prepend a leading zero to the hour
  hour=`(printf "%02i" $j)`
  # loop through the minutes of the hour
    for i in {0..59}    
       do
       # prepend a leading zero to the minute
       minute=`printf "%02i" $i`
       # assemble the filename
       filename=${y}${m}${d}${hour}${minute}
       # use wget do download the image
       wget http://extras.vodafone.is/trailers/fimmvorduhals/mx10-4-235-80/${y}/${m}/${d}/$hour/$minute.jpg -O ${dirname}/${filename}.jpg  
       # crop the right-hand side of the image in 16:9 aspect ratio
       convert -crop 1024x576+1025+0 ${dirname}/${filename}.jpg ${dirname}/right/right_${filename}.jpg
       # crop the left-hand side of the image in 16:9 aspect ratio
       convert -crop 1024x576+0+0 ${dirname}/${filename}.jpg ${dirname}/left/left_${filename}.jpg
       done   
  done

Download the script here: day.sh

Sample Video

This is a video created with the above script:

ImageMagick installation issues

To install ImageMagick in Cygwin search for the Word ImageMagick in the select packages view and clck on the package to include it in the install.

But when I tried to run a convert command, I got the following error:

$ convert
/usr/bin/convert.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory

After some searching on the web, I found out that some libraries were probably missing, luckily there is a way to check for missing dlls using the command cygcheck:

$ cygcheck convert
Found: C:cygwinbinconvert.exe
Found: C:cygwinbinconvert.exe
Found: C:WINDOWSsystem32convert.exe
C:cygwinbinconvert.exe
  C:cygwinbincygwin1.dll
    C:WINDOWSsystem32ADVAPI32.DLL
      C:WINDOWSsystem32KERNEL32.dll
        C:WINDOWSsystem32ntdll.dll
      C:WINDOWSsystem32RPCRT4.dll
        C:WINDOWSsystem32Secur32.dll
  C:cygwinbincyggcc_s-1.dll
  C:cygwinbincygMagickCore-1.dll
cygcheck: track_down: could not find cyggomp-1.dll

    C:cygwinbincygX11-6.dll
      C:cygwinbincygxcb-1.dll
        C:cygwinbincygXau-6.dll
        C:cygwinbincygXdmcp-6.dll
    C:cygwinbincygXext-6.dll
    C:cygwinbincygbz2-1.dll
    C:cygwinbincygfontconfig-1.dll
      C:cygwinbincygexpat-1.dll
      C:cygwinbincygfreetype-6.dll
        C:cygwinbincygz.dll
      C:cygwinbincygiconv-2.dll
cygcheck: track_down: could not find cygltdl-7.dll

cygcheck: track_down: could not find cygtiff-5.dll

    C:WINDOWSsystem32GDI32.dll
      C:WINDOWSsystem32USER32.dll
  C:cygwinbincygMagickWand-1.dll

To fix the issue I had to run the cygwin setup.exe again and install the following libraries:

  • libltdl7
  • libtiff5
  • libgomp1