How To Create a Raspberry Pi Time-Lapse Video or GIF

Time-lapse videos are really easy to create with a Raspberry Pi. The Raspbian operating system has almost everything we need to get the job done. All you need for this project is a Raspberry Pi, camera, and a subject to capture.

What is time-lapse?

Time-lapse refers to the process of capturing still images of a subject over a long period of time. By combining the images together, a video can be produced. Time-lapse videos can be used for monitoring plant growth, watching the seasons change, or even as security footage with low storage capacity.

Here's a sunset time-lapse recorded on the Raspberry Pi. This was created by capturing one image every 10 minutes.

If you're using a monitor and keyboard for this project, connect them now.

Enable SSH

If you're using a monitor, open the main menu from the taskbar and go to Preferences > Raspberry Pi Configuration. Under the Interfaces tab, enable SSH. If you're using a headless setup, visit our guide on how to enable ssh without a screen.

Connect to the internet

If you plan to access the Pi remotely, you'll need to connect to the internet. Plug in an ethernet cable if your project involves a wired connection. Wireless users can connect using the wireless icon from the taskbar in Raspbian. If you're using Wi-Fi on a headless setup, check out our guide on how to set up Wi-Fi on a Raspberry Pi without a monitor.

Log in to the Pi

Log in to the Raspberry Pi using a terminal window.

Mac users can use Terminal. We recommend Putty for Windows users. Connect to the IP address assigned to the Raspberry Pi and log in using your Pi credentials. Visit our guide on how to log in to a Raspberry Pi via SSH for more details on this process.

The Raspberry Pi is somewhat limited in its selection of supported cameras. Most compatible webcams require a powered USB hub. In this guide, I'll be using a camera designed specifically for the Pi. The Raspberry Pi has a specific port designated for the camera module. Turn off the Pi and plug the ribbon cable into the camera slot on the Pi. Visit our guide on how to connect a camera to the Raspberry Pi for more details on this process.

Time-lapse videos are created with individual stills. To capture our time-lapse frames, we'll be using the raspistill tool. This is built into Raspbian and doesn't require a special download. The following is an example of how to capture time-lapse images.

raspistill -t 10000 -tl 2000 -o pic%04d.jpg

10000 refers to the duration of the time-lapse capture, in this case, 10 seconds. 2000 determines how long the Pi will wait between each picture. In the example code above, the Pi will capture an image every two seconds for ten seconds.

The images will be saved as .jpg files. In the example, each picture will be named "Pic" with a number that increments with each frame. %04d places four 0's at the end. The first two images would be named Pic0000.jpg and Pic0001.jpg and so on. You can change this number to suit your project needs.

Once all of the images have been captured for your time-lapse video, they need to be strung together into one file. To create our time-lapse video, we'll be using Ffmpeg. Download the package using the following command:

git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg

Wait for the package to finish installing. The following command is an example of how to compile the final video:

ffmpeg -r 5 -i pic%04d.jpg -c:v libx264 video-file.mp4

Pic%04d.jpg refers to the image name you set in the previous step. If you changed this name before, change it here. The number after -r will determine how many frames are placed in each second of video. Choose a name for your time-lapse video by replacing the words video-file. Be sure to leave the .mp4 extension.

The Raspberry Pi single-board computer has had built-in Bluetooth connectivity since the release of the Raspberry Pi 3 in 2016, allowing you to connect wireless peripherals such as keyboards, game controllers, headsets, and more to your device.
If you don’t have a model of Raspberry Pi that has Bluetooth built-in, you can use a third-party USB adapter to add support. You may need to install additional software packages to do this, depending on the adapter you use.
If you're using using Raspberry Pi OS (previously Raspbian), then Bluetooth should be enabled by default, but you'll need to follow these additional steps to connect and set up your devices.
These instructions will work for Raspberry Pi OS users, including Raspberry Pi OS Lite, which lacks a graphical desktop environment by default.