Create Time Lapse with Raspberry Pi Camera: Simple Guide
Use the
raspistill command or Python picamera library to capture images at intervals, then combine them into a video with ffmpeg. For example, run raspistill -o img%04d.jpg -tl 10000 -t 60000 to take photos every 10 seconds for 1 minute, then use ffmpeg to create the time lapse video.Syntax
The basic command to capture images for a time lapse using the Raspberry Pi camera is:
raspistill -o img%04d.jpg -tl [interval_ms] -t [duration_ms]
Where:
-o img%04d.jpgsaves images with a 4-digit number sequence.-tl [interval_ms]sets the time lapse interval in milliseconds between shots.-t [duration_ms]sets the total duration to run the capture in milliseconds.
After capturing images, use ffmpeg to combine them into a video:
ffmpeg -framerate [fps] -i img%04d.jpg -c:v libx264 -r 30 -pix_fmt yuv420p timelapse.mp4
Where [fps] is frames per second for the output video.
bash
raspistill -o img%04d.jpg -tl 10000 -t 60000 ffmpeg -framerate 10 -i img%04d.jpg -c:v libx264 -r 30 -pix_fmt yuv420p timelapse.mp4
Example
This example uses Python with the picamera library to capture images every 5 seconds for 1 minute, then you can combine images into a video using ffmpeg.
python
import time from picamera import PiCamera camera = PiCamera() camera.resolution = (1920, 1080) interval = 5 # seconds count = 12 # total images (5s * 12 = 60s) for i in range(count): filename = f'image_{i:04d}.jpg' camera.capture(filename) print(f'Captured {filename}') time.sleep(interval) camera.close()
Output
Captured image_0000.jpg
Captured image_0001.jpg
Captured image_0002.jpg
Captured image_0003.jpg
Captured image_0004.jpg
Captured image_0005.jpg
Captured image_0006.jpg
Captured image_0007.jpg
Captured image_0008.jpg
Captured image_0009.jpg
Captured image_0010.jpg
Captured image_0011.jpg
Common Pitfalls
- Not setting the correct interval or duration causes too few or too many images.
- Forgetting to zero-pad filenames (
%04d) can causeffmpegto fail reading images in order. - Running the capture without sufficient storage space will stop the process.
- Not installing
ffmpegorpicameralibrary will cause errors. - Using
time.sleep()before the first capture delays the start; capture first then sleep.
python
Wrong way: import time from picamera import PiCamera camera = PiCamera() camera.resolution = (1920, 1080) interval = 5 count = 12 for i in range(count): time.sleep(interval) # sleep before capture causes delay filename = f'image_{i}.jpg' # no zero padding camera.capture(filename) print(f'Captured {filename}') camera.close() Right way: import time from picamera import PiCamera camera = PiCamera() camera.resolution = (1920, 1080) interval = 5 count = 12 for i in range(count): filename = f'image_{i:04d}.jpg' # zero padded camera.capture(filename) print(f'Captured {filename}') time.sleep(interval) camera.close()
Quick Reference
Summary tips for creating time lapse with Raspberry Pi camera:
- Use
raspistillfor quick command line capture. - Use Python
picamerafor more control and automation. - Set interval and duration carefully to control total images.
- Use zero-padded filenames for smooth video creation.
- Combine images into video with
ffmpegusing proper framerate.
Key Takeaways
Use raspistill or picamera to capture images at fixed intervals for time lapse.
Name images with zero-padded numbers to keep correct order for video creation.
Combine images into a video using ffmpeg with a chosen frame rate.
Test interval and duration settings to get desired time lapse length and smoothness.
Ensure sufficient storage and install required tools before starting.