Making time-lapse videos is one of fun things you can do with Raspberry Pi. I bet you have found many solutions somewhere out there for this technique. However I write this tutorial because my solution has many advantages that don't exist in other tutorials, for example:
- You can use Raspberry Pi camera module or a USB camera
- No programming skills required, just use existing applications/utilities
- Easy-to-find hardware, nothing special
- The most important advantage: hardware accelerated video encoding, so you don't need to transfer images to another computer to render video, just let Raspberry Pi do this hard work, and get your final video fast, even faster than what you can expect (using this tutorial, your Raspberry Pi itself can render video faster than a MacBook, really!)
- Easy to customize for your time-lapse settings
- And finally, reverse time-lapse, as a bonus
Let's start!
Introduction
Following Wikipedia, time-lapse photography is a technique whereby the frequency at which film frames are captured (the frame rate) is much lower than that used to view the sequence. When played at normal speed, time appears to be moving faster and thus lapsing. The idea to make a time-lapse video is so simple: instead of recording or capturing frames at normal rate (24, 25 or 30 fps are standards for cinema, PAL television or NTSC television), you capture frames at much lower rate, and then assembly them into a video at normal rate. Time-lapse technique is usually used to film events which last for a long time in reality.
As an example, suppose that we want to make a 1-minute time-lapse video for an event which lasts an hour in reality. We choose 24 fps for the video. So we need to capture 24 x 60 = 1440 frames (images). So the frame rate for capturing is 1440 frames/hour or 0.4 fps, i.e. we take an image after every 2.5 seconds.
The resolution for the video is determined by our camera's capability and also by our intention. Suppose that it is 1280x720.
Hardware requirement
About hardware, first, we need Raspberry Pi version B (version A may work, but you need a USB network adapter). Then, Raspberry Pi camera module is a good choice, but because we only use camera to capture still images at low frame rate, so a USB camera (webcam) is still OK. Many webcams can connect directly into Raspberry Pi's USB port, otherwise use an powered USB hub. This tutorial will cover both cases (Raspberry Pi camera module and USB camera).
If you need to film outdoor, a simple and economic solution to power up Raspberry Pi is 4 AA-size rechargeable batteries (each battery has 1.2V voltage) via GPIO pins (+5V and GND pins). I use 4 rechargeble batteries (2700mAh each) for my Raspberry Pi-powered mobile robot.
We need Internet connection to install some required software on Raspberry Pi before capturing images. Suppose that you have already accessed into Raspberry Pi (by using keyboard/monitor, or through ssh). If you use ssh, you can copy command lines in this tutorial and paste them into terminal.
And finally, SD card with installed Linux OS. I use Raspbian in this tutorial. The capacity for SD card depends on how long you want your video will be, its resolution and its frame rate (24/25 or 30 fps), so how many images you will capture and their resolution. If we choose uncompressed format for images (.ppm), each image will be (3 x width x height + 16) bytes, so about 2.8 MB for each 1280x720 image. If we choose compressed format (.jpeg in this tutorial), each image reduces to less than 100 KB. 4GB SD card is usually enough for most cases.
That's all about hardware.
Software preparation
We need to take 2 steps to make a time-lapse video directly on Raspberry Pi:
- Step 1: Capture still images at predetemined frame rate
- Step 2: Render still images into video file using Raspberry Pi's hardware video encoder
There are already many ways in many tutorials to do step 1. But step 2, no way found yet... until you read this tutorial

To do step 1, this tutorial will use raspistill for Raspberry Pi camera module or streamer for USB camera. raspistill is already included in Raspbian. So we install streamer:
Code: Select all
sudo apt-get install streamer
We need to add another repository for Raspbian to get OpenMAX plugin. Paste these 3 following commands into Raspberry Pi terminal:
Code: Select all
sudo sh -c 'echo deb http://vontaene.de/raspbian-updates/ . main >> /etc/apt/sources.list'
sudo apt-get update
sudo apt-get install libgstreamer1.0-0 liborc-0.4-0 gir1.2-gst-plugins-base-1.0 gir1.2-gstreamer-1.0 gstreamer1.0-alsa gstreamer1.0-omx gstreamer1.0-plugins-bad gstreamer1.0-plugins-base gstreamer1.0-plugins-base-apps gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-pulseaudio gstreamer1.0-tools gstreamer1.0-x libgstreamer-plugins-bad1.0-0 libgstreamer-plugins-base1.0-0
Code: Select all
gst-inspect-1.0 | grep omx
Code: Select all
omx: omxh264enc: OpenMAX H.264 Video Encoder
omx: omxvc1dec: OpenMAX WMV Video Decoder
omx: omxmjpegdec: OpenMAX MJPEG Video Decoder
omx: omxvp8dec: OpenMAX VP8 Video Decoder
omx: omxtheoradec: OpenMAX Theora Video Decoder
omx: omxh264dec: OpenMAX H.264 Video Decoder
omx: omxh263dec: OpenMAX H.263 Video Decoder
omx: omxmpeg4videodec: OpenMAX MPEG4 Video Decoder
omx: omxmpeg2videodec: OpenMAX MPEG2 Video Decoder
Step 1: Capture still images at predetemined frame rate
- For Raspberry Pi camera module:
As calculated in introduction part, for 1 hour (3600000 ms) we take a shot every 2.5 seconds (2500 ms), so
Code: Select all
raspistill -o timelapse%04d.jpeg -tl 2500 -t 3600000
- For USB camera:
Code: Select all
streamer -t 1440 -r 0.4 -s 1280x720 -o timelapse0000.jpeg
will create 1440 still images (from timelapse0000.jpeg to timelapse1439.jpeg)
Step 2: Render still images into video file using Raspberry Pi's hardware video encoder
Now you have still images. You don't need to transfer them to another computer. Raspberry Pi can do video encoding faster than that computer! Raspberry Pi CPU is weak, but Raspberry Pi GPU is strong.
Code: Select all
gst-launch-1.0 multifilesrc location=timelapse%04d.jpeg index=1 caps="image/jpeg,framerate=24/1" ! jpegdec ! omxh264enc ! avimux ! filesink location=timelapse.avi
In my test, rendering .avi file (1280x720, 24 fps, H264 codec) from 1500 images on a computer with Core Duo 2.0 GHz CPU, 1 GB RAM takes 4 minutes 15 seconds. The same on Raspberry Pi takes 2 minutes 15 seconds only!
Flush all data to SD card, to avoid data corruption:
Code: Select all
sync
You can put commands in step 1 and step 2 into a single .sh file to automate all the process.
Check out my time-lapse demo video from Raspberry Pi, you will see the time lapsing.
Bonus: Reverse time-lapse
- Make a new directory for images at reversed order:
Code: Select all
mkdir timelapse_reverse
Code: Select all
for i in {0..1439}; do ri=`expr 1439 - $i`; cp timelapse`printf %04d $i`.jpeg timelapse_reverse/timelapse`printf %04d $ri`.jpeg; done
Code: Select all
gst-launch-1.0 multifilesrc location=timelapse_reverse/timelapse%04d.jpeg caps="image/jpeg,framerate=24/1" ! jpegdec ! omxh264enc ! avimux ! filesink location=timelapse_reverse.avi
I hope this tutorial will help you deal some technical issues in making time-lapse video with Raspberry Pi. You can combine this tutorial with your own discoveries to make things better. You can film many interesting time-lapse videos, such as blossoming flower, growing tree, slow chemical reaction, butterfly transformation, moving clouds, moving snail... and much more, it's your creativity! Have fun to lapse time!