Time-lapse movie on Linux – How is it achieved ?

This post is for summarizing the information about the time-lapse movie I mentioned in my earlier posts titled Using a standard web camera to capture a time-lapse on Linux and Compiling UVC driver for Linux with still image support.

As it turns out this topic is one that was actually read by someone out there (based on two feedbacks I received), I decided to publish my findings.

Software required

Software used as the basis

I’ve tested several set of scripts and going through them, I eventually settled on using a very well written and  almost fully working set of scripts and instructions off the web somewhere. Unfortunately I didn’t keep track of my downloads, and there doesn’t seem to be much about the author in the files. The original source of the application is available at https://github.com/jaufrec/webcam.

The scripts are very versatile and provided support for:

  • Cron based photo capture using
    • GPhoto2
    • uvccapture
    • jpegpixi
  • Creation and automatic maintenance of thumbnails and static index pages for daily/monthly indexes
  • Creation of daily/monthly strips extracted from the original movie
  • Cron based creation of daily movies in low and high resolution modes, with and option of adding a second stream as picture-in-picture
  • Cron based creation of monthly movies

Modification to the original code

The scripts came almost as I wanted, the only problem with it was that it didn’t actually work on my setup. Neither of the capture modes listed above work on my environment, so I made several modifications to the scripts.

  • Added support for avconv/ffmpeg based capture.
  • Added detection of dark frames based on average saturation of the image. (crude and ugly, but easier to set up than checking for the sunrise/sunset times)
  • Removed (most of) the script that created the static pages and modified the web interface to dynamically create the index pages.
  • Modified the monthly movie creation to use a set of frames relative to the sunset time instead of using all the frames. This in my case produces a much smoother video.
  • Created a “forever” script that uses all the available frames and the logic above to create a movie.
  • Added two output formats OGV and MP4 so it can be used on more browsers.
  • The PHP scripts were updated to include both output formats in the HTML5 format.
  • Added running text to show capture time to the frames.
  • Added progress counter to all converting scripts to show progress

The original scripts contained really nice and well designed methods to use parametrized solutions. Unfortunately I had too little time to polish my changes, so some of the parameters are fixed.


The scripts run on Linux, initially I used Debian Testing distribution, but since I wanted to port the uvc driver’s still image patch to a more current kernel I upgraded to Ubuntu Raring. The scripts should be able to work on any distribution, provided it has all the basic Linux tools installed.

I used a simple web camera to capture images, but since I’m trying to make a time-lapse movie of the garden it doesn’t produce good enough images.

How to use the software

Getting the software

Either pull it from my github, or get the compressed version here.

Setting up capture

Get a source of images, such as a camera.  WebCam can collect images in any of four ways

  1. The GPhoto2 program. If you are lucky and have a camera that’s supported, that’s the best source for image capture.
  2. The Capture program.  To install on ubuntu:
    1. apt-get install libusb-dev pkg-config libgtk2.0-dev libreadline-dev
    2. download, compile, and install libptp2 from http://libptp.sourceforge.net:
      1. download and untar the tarball
      2. ./configure
      3. make
      4. make install
      5. ldconfig
    3. download, compile, and install capture from http://capture.sourceforge.net
      1. download and untar
      2. make
      3. make install
  3. Any source that puts new pictures into a directory.  For example http://www.airlink101.com/products/aic250.php
  4. When using a webcam it’s easiest to use ffmpeg/avconv to grab image from v4l2 streams. This will use a very low resolution though.

Setting up webserver

Set up a webserver with PHP.  On Ubuntu:
apt-get install lighttpd php5-cgi
lighty-enable-mod fastcgi
service lighttpd force-reload

Copy the php, png, and txt files from the tarball’s web directory to the webserver’s target directory.
The user that runs the scripts should have permission to write to a directory on the webserver.  The directory structure will be:

 index.php (provided in the package)
 index_day.php (provided in the package)
 index_day_video.php (provided in the package)
 index_month.php (provided in the package)
 title.txt (provided in the package - change it's content to your liking)
 basic.css (provided in the package)

All files and directories in this structure are automatically created by the scripts unless otherwise noted.
index.php should be customized by changing “webcam” to whatever directory name you are using.

4) Install avconv and other prerequisites:
On ubuntu,

sudo apt-get install avconv normalize-audio
libsox-fmt-all lame sox ttf-dejavu-extra

Test your configuration

Whatever capture method you choose make sure, that the user running the cron job has access the capture device and the target folder. The easiest way to ensure that is by running the cron commands before it’s installed as a cron job.

Use the command

sudo su - www-data -s /bin/bash

to switch to the user running the web server, and issue your selection of commands to test if the capture can actually take place. If at first you don’t succeed (and I’m pretty sure it won’t work out of the box) try running the program using the -v (verbose) switch and see what commands are executed and try issuing the commands manually to have them fixed.

After testing with root user always make sure the file permissions and file ownership is set up correctly and the temporary directories from /tmp/tmp.* are removed! This can save lots of time on the long run.

Set up cron jobs

Use the command

sudo su - www-data -c 'crontab -e'

to edit the crontab of the www-data user.

Add the capture.sh script regularly, e.g., every minute between 5 and 21. Use the flags to customize For example, put this in your cron:
* 5-21  *   *   *     /usr/share/webcam/capture.sh -c /bin/capture -q /bin/avconv
Add the daily_movie.sh script to run every hour when capture might take place.  For example:
3 6-22  *   *   *     /usr/share/webcam/daily_movie.sh -z 640x480 -o "" -m "your_music_dir" -f 15 -i 1 -1 -2 -3 -q
Add the monthly_movie.sh script to run once per day, right after midnight.  For example:
30 2  *   *   *     /opt/webcam/monthly_movie.sh -z640x480 -o "" -m "your_music_dir" -f 10 -i 1 -1 -q
Add the full_movie.sh script to run once per day, after the monthly movie is created.  for example:
35 2  *   *   *     /opt/webcam/full_movie.sh -z640x480 -m "your_music_dir" -f 30 -q
Make sure your movie generating cron scripts do not contain -v flag, as that will clog up your /tmp directory! Also to receive cron notifications make sure the -q (quiet) flag is added to hide the progress indicator.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.