How to Run a Timelapse Camera with Raspberry Pi
raspberry picameratimelapsepythonffmpegpicamera
Build a timelapse camera that captures frames on a schedule and assembles them into a video — perfect for 3D prints, plants, construction projects, or workshop timelapses.
Hardware
- Raspberry Pi (Zero 2W, 3, or 4)
- Official Raspberry Pi Camera Module (v2 or v3) or compatible CSI camera
- MicroSD card (32GB+ for long timelapses)
Step 1 — Enable the Camera
sudo raspi-config
# Interface Options → Camera → Enable
sudo reboot
For Pi 5 or newer libcamera-based setups, camera is enabled by default.
Test it:
# Legacy camera
raspistill -o test.jpg
# Libcamera (Pi 4/5, newer)
libcamera-still -o test.jpg
Step 2 — Install Dependencies
sudo apt update
sudo apt install python3-picamera2 ffmpeg -y
Step 3 — Timelapse Script
#!/usr/bin/env python3
"""
Timelapse capture script
Captures a frame every N seconds for the specified duration
"""
import os
import time
from picamera2 import Picamera2
from datetime import datetime
# Settings
INTERVAL_SECONDS = 10 # Capture every 10 seconds
DURATION_HOURS = 8 # Run for 8 hours (0 = run forever)
OUTPUT_DIR = '/home/pi/timelapse'
RESOLUTION = (1920, 1080)
os.makedirs(OUTPUT_DIR, exist_ok=True)
cam = Picamera2()
config = cam.create_still_configuration(main={'size': RESOLUTION})
cam.configure(config)
cam.start()
time.sleep(2) # Warm up
frame = 0
start = time.time()
max_seconds = DURATION_HOURS * 3600 if DURATION_HOURS > 0 else float('inf')
print(f"Starting timelapse: every {INTERVAL_SECONDS}s for {DURATION_HOURS}h")
print(f"Output: {OUTPUT_DIR}")
try:
while time.time() - start < max_seconds:
filename = os.path.join(OUTPUT_DIR, f'frame_{frame:06d}.jpg')
cam.capture_file(filename)
print(f"Frame {frame}: {filename}")
frame += 1
time.sleep(INTERVAL_SECONDS)
except KeyboardInterrupt:
print("Stopped by user")
finally:
cam.stop()
print(f"Captured {frame} frames")
Save as timelapse.py and run:
python3 timelapse.py
Step 4 — Assemble into Video
cd ~/timelapse
# 24fps video from frames
ffmpeg -framerate 24 -i frame_%06d.jpg -c:v libx264 -pix_fmt yuv420p timelapse.mp4
# Higher quality
ffmpeg -framerate 24 -i frame_%06d.jpg -c:v libx264 -crf 18 -pix_fmt yuv420p timelapse_hq.mp4
# Resize to 1080p if captured at higher resolution
ffmpeg -framerate 24 -i frame_%06d.jpg -vf scale=1920:1080 -c:v libx264 -pix_fmt yuv420p timelapse.mp4
Run at Boot (for unattended timelapses)
crontab -e
# Add:
@reboot python3 /home/pi/timelapse.py >> /home/pi/timelapse.log 2>&1
Storage Estimate
| Interval | Duration | Frames | Storage (~300KB/frame) |
|---|---|---|---|
| 10s | 8h | 2,880 | ~864MB |
| 30s | 24h | 2,880 | ~864MB |
| 60s | 7 days | 10,080 | ~3GB |
Tips
- Use a Pi Zero 2W for a tiny always-on camera — draws under 1W
- Store frames on an external USB drive for long captures
- Add
--shutter 1000 --awb autoflags for consistent exposure in changing light - For 3D print timelapses: trigger capture from OctoPrint's timelapse plugin instead