3 years ago

Time-lapse photography

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:

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

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:

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

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.

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.

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:

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:

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:

Or if you don’t have wget…

Change the IP address and numbers accordingly.

shell

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:

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.