How to Run a Timelapse Camera with Raspberry Pi
How to Run a Timelapse Camera with Raspberry Pi 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 bash sudo raspi-config Interface Options → Camera → Enable sudo reboot For Pi 5 or newer libcamera-based setups, camera is enabled by default. Test it: bash Legacy camera raspistill -o test.jpg Libcamera (Pi 4/5, newer) libcamera-still -o test.jpg Step 2 — Install Dependencies bash sudo apt update sudo apt install python3-picamera2 ffmpeg -y Step 3 — Timelapse Script python #!/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 INTERVALSECONDS = 10 # Capture every 10 seconds DURATIONHOURS = 8 # Run for 8 hours (0 = run forever) OUTPUTDIR = '/home/pi/timelapse' RESOLUTION = (1920, 1080) os.makedirs(OUTPUTDIR, existok=True) cam = Picamera2() config = cam.createstillconfiguration(main={'size': RESOLUTION}) cam.configure(config) cam.start() time.sleep(2) # Warm up frame = 0 start = time.time() maxseconds = DURATIONHOURS 3600 if DURATIONHOURS > 0 else float('inf') print(f"Starting timelapse: every {INTERVALSECONDS}s for {DURATIONHOURS}h") print(f"Output: {OUTPUTDIR}") try: while time.time() - start < maxseconds: filename = os.path.join(OUTPUTDIR, f'frame{frame:06d}.jpg') cam.capturefile(filename) print(f"Frame {frame}: {filename}") frame += 1 time.sleep(INTERVALSECONDS) except KeyboardInterrupt: print("Stopped by user") finally: cam.stop() print(f"Captured {frame} frames") Save as timelapse.py and run: bash python3 timelapse.py Step 4 — Assemble into Video bash cd ~/timelapse 24fps video from frames ffmpeg -framerate 24 -i frame%06d.jpg -c:v libx264 -pixfmt yuv420p timelapse.mp4 Higher quality ffmpeg -framerate 24 -i frame%06d.jpg -c:v libx264 -crf 18 -pixfmt yuv420p timelapsehq.mp4 Resize to 1080p if captured at higher resolution ffmpeg -framerate 24 -i frame%06d.jpg -vf scale=1920:1080 -c:v libx264 -pixfmt yuv420p timelapse.mp4 Run at Boot (for unattended timelapses) bash crontab -e Add: @reboot python3 /home/pi/timelapse.py >> /home/pi/timelapse.log 2>&1 Storage Estimate 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 auto flags for consistent exposure in changing light For 3D print timelapses: trigger capture from OctoPrint's timelapse plugin instead
Related Guides
- Building a Raspberry Pi Timelapse Camera
- How to Set Up OpenCV Machine Vision on a Raspberry Pi
- How to Use the ESP32-CAM: Video Streaming, Motion Detection, and Time-Lapse
- How to Control GPIO Pins on Raspberry Pi with Python
- Automated Plant Watering System with Raspberry Pi
- Controlling GPIO Outputs with Python — LED, Relay, and Buzzer
- Raspberry Pi GPIO: Complete Beginner Guide with Python Examples
- Getting Started with ROS2 on Raspberry Pi for Robotics