This project starts with an up-to-date installation of Raspberry Pi OS (formerly Raspbian). The code we're using to initiate the time-lapse runs in a terminal window. You can access this using the desktop or remotely with SSH.
If you're not sure where to get started, check out our guide on how to install or update Raspberry Pi OS—the latest OS.
If you're using a monitor and keyboard for this project, connect them now.
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 Raspberry Pi OS. 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.
Enable the camera in Raspberry Pi OS
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 the camera.
Headless users enter
sudo raspi-config. Under Interfacing Options, enable the camera. You will be prompted to restart the Raspberry Pi.
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 Raspberry Pi OS 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
You can read more about ffmpeg features on the official ffmpeg website here.
To save your work, you'll need to copy the video file from the Raspberry Pi to your own computer. Visit our guide on how to transfer files to the Raspberry Pi.
Congratulations! You created a time-lapse video on the Raspberry Pi.
Converting to GIF
If you'd like, you can convert your video to a GIF using a free tool such as Giphy—though this will reduce the number of frames.