Dual Camera Timelapse System
An automated timelapse capture system for Amcrest and Reolink IP cameras running on Raspberry Pi. Captures images from both cameras simultaneously, processes them into MP4 videos, and uploads to an FTP server.
Features
- Concurrent Image Capture: Captures from both Amcrest and Reolink cameras with a 2-second offset
- Automated Processing: Creates MP4 timelapses from captured images using ffmpeg
- Staggered Upload: Uploads videos with timing offsets to prevent bandwidth conflicts
- Error Handling: Comprehensive logging, connectivity checks, and failure recovery
- Resource Management: Disk space monitoring and automatic cleanup of temporary files
- Quality Control: Automatically removes corrupt/small image files
Hardware Requirements
- Raspberry Pi (tested on Pi 5)
- Network access to both cameras
- Sufficient storage space (minimum 1GB free recommended)
- Internet connection for FTP uploads
Software Dependencies
wget
– for camera image captureffmpeg
– for video processingcurl
– for FTP uploadsping
– for connectivity checks- Standard Unix utilities (
find
,mv
,rm
, etc.)
Installation
- Clone or download the script to your Raspberry Pi
- Make it executable:
chmod +x dual-camera-timelapse.sh
- Install dependencies (if not already present):
sudo apt update sudo apt install wget ffmpeg curl
- Create required directories:
sudo mkdir -p /var/www/html/{sa,ss,sawork,swork,mp} sudo chown -R $USER:$USER /var/www/html/
Configuration
Camera Settings
Edit the script and update these variables with your camera details:
# Amcrest Camera
AMCREST_USER="admin"
AMCREST_PASS="your_password"
AMCREST_IP="192.168.1.205"
# Reolink Camera
REOLINK_USER="admin"
REOLINK_PASS="your_password"
REOLINK_IP="192.168.1.211"
REOLINK_RS="your_rs_token" # Found in Reolink camera API settings
# FTP Upload
FTP_USER="your_ftp_user"
FTP_PASS="your_ftp_password"
FTP_HOST="your_ftp_server"
Security Best Practices
Option 1: Environment Variables
export AMCREST_PASS="your_password"
export REOLINK_PASS="your_password"
export FTP_PASS="your_ftp_password"
Option 2: Config File (Recommended)
# Create /home/pi/.camera-config
AMCREST_PASS="your_password"
REOLINK_PASS="your_password"
FTP_PASS="your_ftp_password"
# Source in script:
source /home/pi/.camera-config
Capture Settings
- Amcrest: 480 images (32 minutes at 4-second intervals)
- Reolink: 600 images (40 minutes at 4-second intervals)
- Offset: 2-second delay between camera starts
- Output: 24fps MP4 videos, 1280×720 resolution
Usage
Manual Execution
./dual-camera-timelapse.sh
Automated Execution (Cron)
# Edit crontab
crontab -e
# Add entry (runs every 2 hours):
0 */2 * * * /home/pi/dual-camera-timelapse.sh
# Or daily at 6 AM:
0 6 * * * /home/pi/dual-camera-timelapse.sh
Systemd Service (Optional)
# Create service file
sudo nano /etc/systemd/system/dual-timelapse.service
# Enable and start
sudo systemctl enable dual-timelapse.service
sudo systemctl start dual-timelapse.service
File Structure
/var/www/html/
├── sa/ # Amcrest raw images
├── ss/ # Reolink raw images
├── sawork/ # Amcrest processed images
├── swork/ # Reolink processed images
└── mp/ # Final MP4 videos
├── sa2024-01-15.mp4 # Amcrest timelapse
└── ss2024-01-15.mp4 # Reolink timelapse
/home/pi/
└── dual-timelapse.log # System logs
Monitoring & Logs
View Real-time Logs
tail -f /home/pi/dual-timelapse.log
Check System Status
# Process status
ps aux | grep timelapse
# Disk usage
df -h /var/www/html
# Recent log entries
tail -20 /home/pi/dual-timelapse.log
Troubleshooting
Common Issues
Camera Unreachable
- Check IP addresses and network connectivity
- Verify camera web interfaces are accessible
- Ensure cameras are powered on
Permission Denied Errors
# Fix directory permissions
sudo chown -R $USER:$USER /var/www/html/
sudo chmod -R 755 /var/www/html/
Low Quality/Missing Images
- Check camera settings and image quality
- Verify network stability
- Monitor disk space usage
ffmpeg Failures
# Test ffmpeg manually
ffmpeg -framerate 24 -pattern_type glob -i '/var/www/html/sawork/*.jpg' \
-c:v libx264 test.mp4
FTP Upload Issues
- Verify FTP credentials and server accessibility
- Check network connectivity to FTP server
- Test manual upload:
curl -T test.mp4 ftp://server/ --user user:pass
Log Analysis
Check for specific errors:
grep "ERROR" /home/pi/dual-timelapse.log
grep "WARNING" /home/pi/dual-timelapse.log
Monitor capture success rate:
grep "capture completed" /home/pi/dual-timelapse.log
Customization
Adjust Capture Duration
# In the script, modify these lines:
for run in {1..480}; do # Amcrest (32 min)
for run in {1..600}; do # Reolink (40 min)
Change Video Quality
# Higher quality (larger files):
-crf 20
# Lower quality (smaller files):
-crf 30
Different Frame Rates
# Slower motion:
-framerate 12
# Faster motion:
-framerate 30
Advanced Configuration
Multiple Intervals Per Day
# Capture every 4 hours
0 */4 * * * /home/pi/dual-camera-timelapse.sh
# Capture only during daylight (6 AM to 6 PM)
0 6,10,14,18 * * * /home/pi/dual-camera-timelapse.sh
Storage Management
The script automatically:
- Removes images smaller than 10KB (corrupt/failed captures)
- Cleans up temporary files after processing
- Can be extended to remove old videos after X days
Network Optimization
- 2-second camera offset reduces network congestion
- 30-second upload stagger prevents FTP server overload
- 5-second processing delay prevents CPU/disk conflicts
Camera API References
Amcrest API
http://IP/cgi-bin/snapshot.cgi?channel=1&type=0
Reolink API
http://IP/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=TOKEN&user=USER&password=PASS
Performance Notes
- Total execution time: ~45-50 minutes
- Peak disk usage: ~2-4GB during processing
- Network bandwidth: Dependent on image resolution and upload speeds
- CPU usage: High during ffmpeg processing phases
Support
Check logs first for troubleshooting, then verify:
- Camera connectivity and credentials
- Disk space availability
- Network stability
- FTP server accessibility
Version History
- v1.0 – Initial dual camera implementation
- Added concurrent capture with staggered processing
- Comprehensive error handling and logging