This is a first draft. It outlines how 2 scripts – Python code on a Raspberry Pi 5, and php code on Scootercam’s website – work together to produce timelapse videos. Expect some changes.
Intelligent Timelapse Manager
A sophisticated timelapse system that captures images at optimized intervals throughout the day and automatically creates incremental videos perfect for sunset/sunrise and nature photography.
🌅 Features
Smart Period-Based Capture
- Day Period (8am-4pm): 30-second intervals for efficient daytime coverage
- Evening Period (4pm-12am): 15-second intervals for optimal sunset capture
- Night Period (12am-8am): 45-second intervals for minimal nighttime activity
Automated Video Processing
- Creates MP4 segments every 15 minutes with consistent 15 FPS
- Automatic FTP upload to web server
- Real-time incremental video concatenation
- Growing “day-so-far” videos that update throughout each period
Production-Ready Architecture
- Multi-camera support (tested with Reolink and Amcrest cameras)
- Robust error handling and recovery
- UTF-8 logging with detailed debugging
- Automatic cleanup of processed files
- Period-aware scheduling system
📋 Requirements
Hardware
- Raspberry Pi (tested on Pi 3/4)
- IP cameras with RTSP support
- Stable network connection
- Web server with FTP access
Software
- Python 3.7+
- FFmpeg
- curl
- Required Python packages:
requests
,schedule
🚀 Installation
1. Clone Repository
git clone https://github.com/yourusername/timelapse-manager.git
cd timelapse-manager
2. Install Dependencies
# Update system
sudo apt update && sudo apt upgrade -y
# Install FFmpeg and curl
sudo apt install ffmpeg curl -y
# Install Python packages
pip3 install requests schedule
3. Configure Cameras
Edit timelapse_config.json
:
{
"cameras": {
"camera1": {
"url": "rtsp://username:password@192.168.1.100/stream",
"enabled": true,
"output_dir": "camera1",
"resolution": "1920x1080",
"period_intervals": {
"day": 30,
"evening": 15,
"night": 45
}
}
},
"server": {
"ftp_host": "your-server.com",
"ftp_user": "your-ftp-user",
"ftp_password": "your-ftp-password"
}
}
4. Deploy Server Script
Upload concatenate_videos.php
to your web server and update the authentication key.
📖 Usage
Manual Operation
# Test camera connectivity
python3 timelapse_manager.py capture_test
# Test FTP upload
python3 timelapse_manager.py ftp_test
# Check current status
python3 timelapse_manager.py status
# Test period-based intervals
python3 timelapse_manager.py period_test
# Run the main service
python3 timelapse_manager.py
System Service (Optional)
# Create systemd service
sudo cp timelapse-manager.service /etc/systemd/system/
sudo systemctl enable timelapse-manager.service
sudo systemctl start timelapse-manager.service
📊 Video Output
Expected Durations (8-hour periods)
- Day Video: ~1:04 minutes (960 images at 15 FPS)
- Evening Video: ~2:08 minutes (1,920 images at 15 FPS)
- Night Video: ~0:43 minutes (640 images at 15 FPS)
File Structure
/timelapse/
├── camera1/
│ ├── images/ # Captured images
│ └── segments/ # Local MP4 segments (temporary)
├── current/ # Growing videos (server)
│ ├── camera1_20250819_evening_current.mp4
│ └── camera1_20250819_day_current.mp4
└── archive/ # Completed period videos
├── camera1_20250819_day_143000.mp4
└── camera1_20250819_evening_210000.mp4
⚙️ Configuration
Period Intervals
Customize capture frequencies in timelapse_config.json
:
"period_intervals": {
"day": 30, // seconds between captures (8am-4pm)
"evening": 15, // seconds between captures (4pm-12am)
"night": 45 // seconds between captures (12am-8am)
}
Video Settings
"general": {
"segment_fps": 15, // Output video frame rate
"segment_interval": 900, // Segment creation interval (seconds)
"image_quality": 85, // JPEG quality (1-100)
"cleanup_days": 7 // Local file retention
}
🔧 Troubleshooting
Common Issues
Multiple processes running:
# Kill all instances
sudo pkill -f timelapse_manager
ps aux | grep timelapse # Should only show grep command
FFmpeg hanging:
# Test camera connectivity
timeout 30 ffmpeg -i "rtsp://your-camera-url" -vframes 1 -y test.jpg
Upload failures:
# Test FTP connection
python3 timelapse_manager.py ftp_test
Unicode encoding errors:
# Set environment variable
export PYTHONIOENCODING=utf-8
Debugging
Enable debug logging:
{
"general": {
"log_level": "DEBUG"
}
}
📁 File Management
Automatic Cleanup
- Images are deleted after being processed into segments
- Local segments are deleted after successful upload
- Server archives completed period videos
- Configurable retention periods
Manual Cleanup
# Clean files older than today
python3 cleanup_old_files.py
# Reset current videos
curl "https://your-server.com/concatenate_videos.php?action=reset_daily_video&key=YOUR_KEY"
🏗️ Architecture
Client (Raspberry Pi)
- Image Capture: Period-aware RTSP frame extraction
- Segment Creation: FFmpeg concatenation of images to MP4
- Upload: Reliable curl-based FTP transfer
- Monitoring: Comprehensive logging and status reporting
Server (Web Server)
- File Reception: FTP server for segment uploads
- Video Concatenation: Real-time MP4 appending with FFmpeg
- Period Management: Automatic archiving at period boundaries
- Web Interface: Status monitoring and manual controls
🕐 Scheduling
Automatic Events
- 00:00: Daily video reset (new day starts)
- 03:00: Local file cleanup
- 08:00: Switch to day period (30s intervals)
- 16:00: Switch to evening period (15s intervals)
- 00:00: Switch to night period (45s intervals)
Segment Processing
- Every 15 minutes: Create MP4 from recent images
- Immediate: Upload to server via FTP
- Real-time: Server concatenates to growing video
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
📄 License
This project is licensed under the MIT License – see the LICENSE file for details.
🙏 Acknowledgments
- Built for sunset/sunrise timelapse photography
- Optimized for Raspberry Pi deployment
- Designed for continuous 24/7 operation
- Tested with Reolink and Amcrest IP cameras
📞 Support
For issues and questions:
- Check the troubleshooting section
- Review log files with debug enabled
- Test individual components with provided test commands
- Open an issue with detailed logs and configuration
Perfect for capturing:
- 🌅 Sunrise timelapses
- 🌇 Sunset sequences
- 🌙 Day-to-night transitions
- 🏞️ Nature photography
- 🏗️ Construction projects
- 🌱 Plant growth studies