Time-lapse photography

By Russell Barnes. Posted

Make a device to capture photographs at regular intervals for a time-lapse, then turn these images into a video

Time-lapse photography reveals exciting things about the world which you wouldn’t otherwise be able see. Things that happen too slowly for us to perceive: bread rising and plants growing; the clouds, sun, moon, and stars crossing the sky; shadows moving across the land. In this tutorial, we’ll be making a Raspbian-based device that lets you watch things that are too slow to observe with the naked eye. To do this, we will capture lots of still photographs and combine these frames into a video with FFmpeg/libav, which can then be accessed via a web browser.

The full article can be found in The MagPi 39 and was written by James Singleton

You'll need

Raspberry Pi Camera Module

STEP-01

Connect the Camera Module

First, connect the camera module to the Raspberry Pi with the included ribbon cable. Locate the correct socket; it’s on the top of the Raspberry Pi circuit board and is the one furthest away from the micro-USB power connector. The socket is handily labelled ‘CAMERA’ on the newer Raspberry Pi models. Lift up the outside of the socket to release the clamp, then insert the ribbon cable with the metal contacts facing towards the micro-USB power connector. Finally, hold the ribbon cable in position and push the outside of the socket back down to clamp the cable in place.

STEP-02

Enable and test the camera

Power the Raspberry Pi up. You now have a choice: boot to the command line, open a terminal window, or establish a secure shell (SSH) connection. Enable the camera by running this command from a terminal to launch the Raspberry Pi configuration tool:

$sud†o raspi-config

Then select the 'Enable Camera' option. You can test the camera by running the following command:

raspistill -o testimage.jpg

The red LED on the camera module should light up for 5 seconds and a JPEG image will be saved to the current directory. If the camera is mounted upside down, then you can use the vertical and horizontal flip command-line switches (-vf and -hf).

STEP-03

Install and configure software

Install a web server to access your images remotely. Run this command to install Apache:

$ su†do apt-get install apacŠhe2

Remove the default page to see the contents of the directory:

$ sud†o rm /var/www™™™/in†dex.hŠtml

Visit the IP address of your Pi (e.g. http://192.168.1.45 - you can find this by using ifconfig) and you should see an empty directory listing. If you run the following command and refresh the page, you should see an image file listed. You run this as a superuser so you can write to the directory.

$ sud†o raspistill -o /var/™™www™/testimage.jŒpg

Flick on the file link and you’ll see the image in your browser.

STEP-04

Capture the images

Set up your scene and check the positioning of the camera.

$ sud†o raspistill -w 1920 -h 1080 -o /var/www/testimageFullHD.jpg

The width and height have been changed to capture a smaller image in 16:9 aspect ratio. This makes things easier later. The top and bottom are cropped, so make sure that your subject is in frame. Run this
to start the capture:

$ sudo raspistill -w 1920 -h 1080 -t 10800000 -tl 1000 -o /var/www/frame%04d.jpg &

This takes a photograph every ten seconds (10,000 milliseconds) for three hours (10,800,000 milliseconds). The ampersand (&) at the end runs the process in the background.

STEP-05

Prepare to make the video

You can render the video on the Raspberry Pi, but it’ll be very slow. A better way is to transfer the files to a more powerful computer. In any case, you’ll need to install the tools on the rendering machine; for the Pi, enter:

$ sudo apt-get install libav-tools

This installs a fork of FFmpeg, but you can also use the original FFmpeg. To copy the images to a remote machine, you can download them from the web server using wget or curl. For example:

$ wget -r -A jpg http://192.168.1.45

Or if you don’t have wget…

$ curl http://192.168.1.45/frame[0001-0766].jpg -O

Change the IP address and numbers accordingly.

 The conversion to video is done in the command line

STEP-06

Make the video

The final step is to make the video. Run this command to start the rendering process:

$ sudo avconv -i /var/www/frame%04d.jpg -crf 4 -b:v 10M /var/www/video.webm &

When this has finished, you’ll be able to view the video in your browser. The default frame rate is 25fps. This compresses three hours of frames at ten-second intervals to about forty seconds of video. You can adjust this with the -framerate command-line option. The bitrate (-b„) has been set high, and the Constant Rate Factor (-crf) low, to produce a good-quality video.

From The MagPi store

Subscribe

Subscribe to the newsletter

Get every issue delivered directly to your inbox and keep up to date with the latest news, offers, events, and more.