← How-Tos
raspberry-pi Mar 29, 2026 ◑ 3 views ◯ 2 min read

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

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

IntervalDurationFramesStorage (~300KB/frame)
10s8h2,880~864MB
30s24h2,880~864MB
60s7 days10,080~3GB

Tips