Timelapse,version 563,549

Author:

Automated Timelapse System

A distributed timelapse video system using Raspberry Pi capture nodes and centralized video processing. Produces continuous daily timelapse videos from multiple camera angles with automatic golden hour detection.

Features

  • Multi-camera support – Currently configured for 2 IP cameras (Amcrest, Reolink)
  • Automatic video compilation – Real-time appending of video segments to daily files
  • Golden hour detection – Separate sunset videos using astronomical calculations
  • Staggered processing – Camera uploads separated by 30 seconds to prevent server overload
  • Period-based organization – Day (8am-4pm), Evening (4pm-12am), Night (12am-8am) periods
  • Location-aware – Sunset timing automatically adjusts for Douglas, Michigan coordinates
  • Resilient uploads – Retry logic with proper error handling

System Architecture

Raspberry Pi (Capture Node)

  • Image capture – RTSP stream capture every 15 seconds
  • Video processing – FFmpeg compilation of images into 15-minute segments
  • Upload client – cURL-based segment delivery to processing server
  • Staggered execution – Cameras process 30 seconds apart

Server (Processing Node)

  • Segment receiver – PHP-based upload handler
  • Video appending – FFmpeg concatenation of segments to daily videos
  • Period management – Automatic video rotation every 8 hours
  • Golden hour calculation – Astronomical sunset timing for special footage

Requirements

Raspberry Pi

  • Python 3.7+
  • FFmpeg 4.0+
  • RTSP-capable IP cameras
  • Reliable network connection

Server

  • PHP 7.4+ with file upload support
  • FFmpeg 4.0+
  • Web server (Apache/Nginx)
  • Sufficient storage (2-5GB per day)

Installation

Raspberry Pi Setup

# Clone repository
git clone https://github.com/username/timelapse-system.git
cd timelapse-system

# Create Python virtual environment
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# Configure cameras and server
cp config.py.example config.py
# Edit config.py with your camera URLs and server details

Server Setup

# Copy PHP handler to web directory
cp upload.php /var/www/html/timelapse/

# Create required directories
mkdir -p /var/www/html/timelapse/videos
mkdir -p /var/www/html/timelapse/temp
chmod 755 /var/www/html/timelapse/videos
chmod 755 /var/www/html/timelapse/temp

# Ensure PHP can write to directories
chown -R www-data:www-data /var/www/html/timelapse/

Configuration

config.py (Raspberry Pi)

CAMERAS = {
    'amcrest': {
        'rtsp_url': 'rtsp://admin:password@192.168.1.100/stream',
        'name': 'amcrest',
        'stagger_offset': 0,  # Process at :00 seconds
        'enabled': True
    },
    'reolink': {
        'rtsp_url': 'rtsp://admin:password@192.168.1.101/stream', 
        'name': 'reolink',
        'stagger_offset': 30,  # Process at :30 seconds
        'enabled': True
    }
}

SERVER_CONFIG = {
    'upload_url': 'http://yourserver.com/timelapse/upload.php',
    'upload_retries': 3,
    'upload_timeout': 300
}

Geographic Configuration

Update coordinates in upload.php for accurate sunset calculation:

private $latitude = 42.5596;  // Your latitude
private $longitude = -86.2355; // Your longitude

Usage

Start Raspberry Pi System

# Run as service (recommended)
sudo systemctl enable timelapse
sudo systemctl start timelapse

# Or run manually
cd /path/to/timelapse
python3 main.py

Monitor System

# Check logs
tail -f /home/pi/timelapse/logs/timelapse_*.log

# View system status
curl http://yourserver.com/timelapse/upload.php?action=status

Manual Operations

# Force video rebuild
curl http://yourserver.com/timelapse/upload.php?action=rebuild&camera=amcrest&type=day

# Archive current videos  
curl http://yourserver.com/timelapse/upload.php?action=rotate

File Structure

timelapse-system/
├── main.py                 # Main controller
├── process_segments.py     # Video processing script
├── config.py              # Configuration
├── upload.php             # Server upload handler
├── README.md
├── requirements.txt
└── systemd/
    └── timelapse.service   # Systemd service file

API Endpoints

POST /upload.php

Upload video segment for processing

  • Parameters: camera, video file, timestamp, size
  • Response: JSON with status and video update info

GET /upload.php?action=status

Get system status and video information

GET /upload.php?action=rotate

Archive current videos and start fresh daily files

Daily Output

The system produces 8 video files per day:

  • {camera}_day_{YYYYMMDD}.mp4 – Daytime footage (8am-4pm)
  • {camera}_evening_{YYYYMMDD}.mp4 – Evening footage (4pm-12am)
  • {camera}_night_{YYYYMMDD}.mp4 – Overnight footage (12am-8am)
  • {camera}_sunset_{YYYYMMDD}.mp4 – Golden hour footage (sunset ±30min)

Videos update in real-time as segments arrive throughout the day.

Performance

  • Processing time: ~2-3 seconds per segment
  • Storage usage: ~2-5GB per camera per day
  • Network bandwidth: ~50KB per segment upload
  • Server load: Minimal (stream copy operations only)

Troubleshooting

Common Issues

No uploads reaching server

  • Check network connectivity and server URL
  • Verify camera RTSP streams are accessible
  • Review Raspberry Pi logs for processing errors

FFmpeg append failures

  • Ensure server has write permissions to video directories
  • Check FFmpeg installation and version compatibility
  • Review PHP error logs for specific FFmpeg error messages

Timing/stagger issues

  • Verify system clocks are synchronized (NTP)
  • Check configuration stagger_offset values
  • Monitor controller logs for trigger timing

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with appropriate tests
  4. Submit a pull request with clear description

License

MIT License – See LICENSE file for details

Support

For issues and questions, please create a GitHub issue with:

  • System information (Pi model, server OS, versions)
  • Relevant log excerpts
  • Clear description of expected vs actual behavior

Leave a Reply

Your email address will not be published. Required fields are marked *