In this page I describe how to produce time-lapse movies using gphoto2. Everything started when a friend lent me his old Canon Powershot A40 digital camera. I then started experimenting with ghpoto2 to capture image and produce time-lapse movies of the clouds; there are plenty of such movies on YouTube, and I wanted to do my own.
This is the list of the required software:
First, you need to acquire the snapshots somehow. gphoto2 can remotely control some digital cameras. The idea is to sit the camera on a tripod and let gphoto2 take pictures at regular intervals. gphoto2 allows the user to control different aspects of the camera (exposure time, aperture and so on). If you are using a Canon PowerShot A40, you must first put the camera in "Play" mode using the round selector on the back. Only in Play mode this camera can be remotely controlled.
Unfortunately, not all cameras can be remotely controlled. For those which can, it is possible to check which capabilities are supported using this command:
The Canon PowerShot A40 display the following capabilities:
/main/camera/model /main/camera/owner /main/camera/capturesizeclass /main/camera/iso /main/camera/shutterspeed /main/camera/zoom /main/camera/aperture /main/camera/resolution /main/camera/focusmode /main/camera/flashmode /Main/camera/beep /main/camera/datetime /main/camera/setcameratime /main/camera/firmwareversion /main/camera/driver /main/Driver/list_all_files
Unfortunately, it is not possible to remotely control all aspects
of the A40; for example, shutterspeed and
aperture can not be changed. This seems a limitation of
the camera rather than gphoto2, as even the proprietary Canon Remote
Capture application can not change these parameters. To change the
value for a configuration parameter, you can use the following:
where name is the name of a parameter (e.g.,
/main/camera/flashmode) and value is one of the
admissible values for it. You can figure out which are the admissible
values by issuing this command:
If your camera supports remote capture, you should be able at least to do the following:
The --capture-image-and-download flag instructs gphoto2
to capture an image using the current camera settings and download it
to the host PC. The --filename flag sets the filename for
the image which will be saved on the local directory. In this case,
each captured image will be named YYYYMMDDhhmmss.jpg,
where YYYY is the year, MM is the month and
so on. For example, 20080608080742.jpg is the name of
the snapshot taken on june 8, 2008 at 08:07:42AM. Using this naming
scheme has the advantage that the lexicographic order of the file
names is the same as the chronological order in which the images were
taken. This will help mencoder to assemble the images in the right
order.
This is the list of values which are currently accepted by some of the configuration variables for the Canon PowerShot A40. Note that your camera might have different names for the configuration variables, and these might take different values.
/main/camera/iso Choice: 0 ISO 100 Choice: 1 ISO 125 Choice: 2 ISO 160 Choice: 3 ISO 200 Choice: 4 ISO 250 Choice: 5 ISO 320 Choice: 6 ISO 400 Choice: 7 ISO 500 Choice: 8 ISO 640 Choice: 9 ISO 800 Choice: 10 ISO 1000 Choice: 11 ISO 1250 Choice: 12 ISO 1600 Choice: 13 ISO 3200 Choice: 14 Unknown /main/camera/zoom Choice: 0 No zoom Choice: 1 1 Choice: 2 2 Choice: 3 3 Choice: 4 4 Choice: 5 5 Choice: 6 6 Choice: 7 7 Choice: 8 8 Choice: 9 Zoom 9 (max) Choice: 10 Unknown /main/camera/resolution Choice: 0 RAW Choice: 1 Small Normal JPEG Choice: 2 Small Fine JPEG Choice: 3 Medium Normal JPEG Choice: 4 Medium Fine JPEG Choice: 5 Large Normal JPEG Choice: 6 Large Fine JPEG Choice: 7 RAW + Small Normal JPEG Choice: 8 RAW + Small Fine JPEG Choice: 9 RAW + Medium Normal JPEG Choice: 10 RAW + Medium Fine JPEG Choice: 11 RAW + Large Normal JPEG Choice: 12 RAW + Large Fine JPEG /main/camera/focusmode Choice: 0 Auto focus: one-shot Choice: 1 Auto focus: AI servo Choice: 2 Auto focus: AI focus Choice: 3 Manual focus /main/camera/flashmode Choice: 0 Flash off Choice: 1 Flash on Choice: 2 Flash auto Choice: 3 Flash red eye removal Choice: 4 Flash on (assist light fires) /Main/camera/beep Choice: 0 Beep off Choice: 1 Beep on
The specific capture command which I used with the Canon A40 was the following:
the meaning of each parameter being:
--set-config beep=0--set-config flashmode=0--set-config resolution=3-I 20-F 3150In general, to get a smooth video you should use a small value of
the -I parameter. For my A40 it was not reasonable to set
an interval less than 10 seconds, as taking the picture and
downloading it to the host took around 6 seconds.
This is a sample picture taken on 2008-06-08 at 09:59:22
Sometimes it is useful to overlay the timestamp to each frame, so
that the movie will contain a visual indication of the capture
times. Labeling images is quite easy to do using just ImageMagick and a little bash
scripting. Create a script named label_image.sh with the
following content:
Invoking label_image.sh 20080608095922.jpg will create a
new image caption_20080608095922.jpg with the timestamp
on the lower right corner, like this:
Now that you have a directory full of pictures, it is possible to make a movie from them using MEncoder. The command I used is the following:
This produces an mpeg4 stream inside an AVI container. The output framerate is 12fps, and each image is rescaled at 640×480 resolution before encoding. This command will produce a high-quality, LARGE file. Just to give you an idea, encoding 3150 frames will produce a movie of 192289210 bytes (see later).
To produce a FLV movie you can use the following command
This produces a lower quality movie at qvga resolution (320x240),
but with a significant reduction in file size (movie.flv
takes only 6618134 bytes). You can view the resulting movie using a
FLV-capable movie player, such as MPlayer or VLC. It is
also possible to embed the .flv movie in a web page using Flowplayer, an open-source Flash
movie player. You can see the result here:
The video quality can be improved by using a higher bitrate; this
can be done with the -b brate flag of FFmpeg,
where brate is the bitrate in bits/second (default is
200kb/s).
The following table summarizes the space requirements of different movie formats at different bitrates.
| Encoding | File size (bytes) | Quality |
|---|---|---|
| Raw images: 3150 medium quality JPEGs, 1024×768 each | 363355038 | Original |
| mencoder "mf://*.jpg" -mf fps=12:type=jpg -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:vbitrate=7000 -vf scale=640:480 -oac copy -o movie.avi | 192289210 | Excellent |
| ffmpeg -i movie.avi -s qvga movie.flv (default bitrate 200kb/s) | 6618134 | Good (small picture) |
| ffmpeg -i movie.avi -s qvga -b 150000 movie.flv | 5036483 | Fair |
| ffmpeg -i movie.avi -s qvga -b 100000 movie.flv | 3494717 | Poor |
Sadly, my friend's trusty A40 broke down, so I tried to experiment using a webcam to capture snapshots. A webcam has a much more simple electronics than a digital photo camera, and has no moving parts. For this reason, it represents a good candidate for taking plenty of pictures reliably. Moreover, with a webcam you are able to achieve a higher capture rate.
Unfortunately, it turns out that cheap webcams often provide poor image quality. One of the webcams I tested (a Creative Live! Cam Optia) is useless for taking outdoor pictures, as it produces overexposed images. Probably the webcam sensor is somewhat optimized for low light conditions, as in fact it produces good images with very dim light.
At the time I wrote this page, I tested the following webcams:
I used fswebcam to acquire a snapshot every 10 seconds.
The Logitech Quickcam Pro 9000 is the best one in term of image quality, and in my opinion it is strongly recommended for taking outdoor pictures. Moreover, Logitech is actively supporting open source development on their cameras via the QuickCam Team web site. Unfortunately it appears that newer QuickCam Pro 9000 models are affected by a firmware problem which might make them unstable under Linux. Check out the Linux Compatibility List for updates.
The Creative Live! Cam Optia produces severely overexposed outdoor images, but nevertheless works fine in dim light conditions. I do not recommend it for outdoor use. The old Trust webcam has overexposure problems as well, but the images are not as overexposed as the ones produced by the Optia. Unfortunately, the image quality of the pictures taken by the SpaceCam 300 is very bad: images are blurred regardless how you adjust the focus ring.
The following two pictures were taken with a Panasonic Lumix FZ7 digital photo camera (left) and with the Creative Live! Cam Optia (right). As you can see, the picture taken with the Creative Live! Cam lacks any detail in the bright areas.
The following two pictures were taken with the Logitech Quickcam Pro 9000 (left) and Creative Live! Cam Optia (right). Both snapshots were taken exactly at the same time.
As can be seen, there are no visible features in the image taken with the Creative Live! Cam Optia webcam. Also, note that the image is somehow yellowish (the yellow tint can be improved by playing with the gamma correction control of the camera). Also, there are currently problems setting the exposure manually on the Live! Cam Optia; manual exposure works fine under Windows, but also with minimum exposure values the image is overexposed anyway, exactly as the snapshots above.
Later, I bought a Logitech Quickcam E3500, which is a cheap UVC-compliant camera which produces reasonable images at 640×480 resolution. More information are available on a separate page.