SpectraX is a streamlined surveillance system for turning any phone, tablet, or IP camera into a secure RTSP/HLS streaming source with object detection capabilities. It's built for people who need a simple, powerful, and private way to set up a surveillance system or a quick streaming solution.
⚠️ Note: SpectraX uses a self-signed certificate for RTSPS by default, which can trigger security warnings in some clients. For production use, replace it with a certificate from a trusted CA.
- What It Does
- Key Features
- System Architecture
- Getting Started
- Configuration
- Object Detection
- Event-Based Recording
- Web Dashboard
- Advanced Usage
- Troubleshooting
SpectraX wraps MediaMTX, a powerful RTSP/HLS server, with intelligent object detection and recording capabilities. Turn any device with a camera into a smart surveillance system in minutes.
- Multiple Protocols: RTSP (low latency), RTSPS (encrypted), and HLS (browser-compatible)
- Mobile-Ready: Works with Larix Broadcaster and other RTSP apps
- Multi-Camera Support: Monitor multiple streams simultaneously
- Automatic Credentials: Secure, randomly generated passwords stored in system keychain
- YOLO Integration: Real-time object detection using YOLOv8 models
- Customizable Models: Choose from nano (fast) to large (accurate) models
- Smart Filtering: Detect specific objects (person, car, dog, etc.)
- Visual Overlays: Bounding boxes and labels on detected objects
- Adjustable Confidence: Fine-tune detection sensitivity
- Intelligent Recording: Automatically record when objects are detected
- Pre/Post Buffers: Capture 10 seconds before and after detections
- Selective Recording: Only record specific object types
- SQLite Database: Searchable metadata for all recordings
- Storage Management: Automatic cleanup when storage limits reached
- Live Viewing: Real-time video with AI detection overlays
- Recordings Browser: View and manage all recorded clips
- Multi-Camera Grid: Monitor all cameras in one interface
- REST API: Access recordings and statistics programmatically
- Responsive Design: Works on desktop and mobile browsers
- RTSPS Encryption: TLS-encrypted RTSP streams
- Credential Management: Secure storage using OS keyring
- Network Isolation: Bind to localhost or specific interfaces
- Self-Signed Certificates: Included for immediate use
SpectraX has been streamlined into a clean, modular architecture:
root/
├── video-feed/ # 📦 Main Python package
│ ├── videofeed/ # Core modules
│ │ ├── surveillance.py # 🎯 MAIN ENTRY POINT - Unified CLI
│ │ ├── config.py # 🔧 Configuration management
│ │ ├── detector.py # 🎯 YOLO object detection
│ │ ├── recorder.py # 📹 Event-based recording
│ │ ├── visualizer.py # 🌐 Web interface & API
│ │ ├── credentials.py # 🔐 Secure credential management
│ │ ├── api.py # 🔗 Recordings database API
│ │ ├── utils.py # 🛠️ Utility functions
│ │ ├── constants.py # 📋 Shared constants
│ │ └── templates/ # 🎨 Web interface templates
│ ├── config/ # ⚙️ Configuration files
│ │ └── surveillance.yml # Main config file
│ ├── models/ # 🤖 YOLO models
│ ├── ui/ # 🖥️ Web dashboards
│ ├── tests/ # 🧪 Test suite
│ ├── setup.py # Package setup
│ └── requirements.txt # Python dependencies
├── scripts/ # 🚀 Helper scripts
│ ├── surveillance.sh # Main launcher
│ └── surveillance.service # Systemd service
├── docs/ # 📚 Documentation
└── README.md # This file
-
surveillance.py
: Unified command-line interface with all commands:config
- Start with YAML configuration filestart
- Start with command-line optionsquick
- Quick start with defaultsrun
- Start streaming server onlydetect
- Start object detection onlyreset
- Reset stored credentials
-
config.py
: Configuration management withSurveillanceConfig
class for YAML parsing -
detector.py
: YOLO-based object detection with multi-camera support -
recorder.py
: Event-based recording triggered by object detection -
visualizer.py
: FastAPI web interface with live video and recordings browser
System Requirements:
- macOS, Linux, or Windows
- Python 3.8 or higher
- 4GB RAM minimum (8GB recommended for multiple cameras)
- Tested on macOS Sequoia 15.4.1
Required Software:
-
MediaMTX - RTSP/HLS streaming server
# macOS brew install mediamtx # Linux # Download from https://github.com/bluenviron/mediamtx/releases # Windows # Download from https://github.com/bluenviron/mediamtx/releases
-
Python 3.8+
python3 --version # Check your version
Recommended Clients:
- Mobile Publishing: Larix Broadcaster (iOS/Android)
- Desktop Viewing: OBS Studio or VLC Media Player
- Clone and Setup
# Clone the repository
git clone https://github.com/soos3d/SpectraX.git
cd SpectraX
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # macOS/Linux
# or: .\venv\Scripts\activate # Windows
# Install dependencies
cd video-feed
pip install -r requirements.txt
cd ..
- Download YOLO Models (optional - will auto-download on first use)
cd video-feed/models
wget https://github.com/ultralytics/assets/releases/download/v8.3.0/yolov8n.pt
wget https://github.com/ultralytics/assets/releases/download/v8.3.0/yolov8l.pt
cd ../..
- Configure Your System
Edit video-feed/config/surveillance.yml
to set your camera paths and preferences.
# Start with configuration file (recommended)
./scripts/surveillance.sh config
# Quick start with defaults (1 camera at video/camera-1)
./scripts/surveillance.sh quick
# Open standalone web dashboard
./scripts/surveillance.sh dashboard
The system will display connection URLs for your cameras and the web interface.
All settings are managed in video-feed/config/surveillance.yml
. This is the only file you need to edit.
# Camera stream paths
cameras:
- video/front-door
- video/backyard
- video/garage
# Network settings
network:
bind: "127.0.0.1" # localhost only (secure)
# bind: "0.0.0.0" # all interfaces (LAN access)
api_port: 3333
# Object detection
detection:
enabled: true
port: 8080
model: "yolov8n.pt" # Options: yolov8n, yolov8s, yolov8m, yolov8l
confidence: 0.4
resolution:
width: 960
height: 540
Detection Filtering:
detection:
filters:
classes: ["person", "car", "dog"] # Only detect these (empty = all)
min_area: 1000 # Ignore tiny detections
max_area: 500000 # Ignore huge detections
Visual Appearance:
appearance:
box:
thickness: 2
color: "yellow" # green, red, blue, yellow, white, black, roboflow
label:
text_scale: 0.5
position: "top_left"
Recording Settings:
recording:
enabled: true
min_confidence: 0.5
pre_buffer_seconds: 10 # Record before detection
post_buffer_seconds: 10 # Record after detection
max_storage_gb: 10.0
recordings_dir: "~/video-feed-recordings"
record_objects: ["person", "car", "dog"] # Only record these
See the config file for complete documentation of all options.
When the system starts, it displays connection URLs:
📱 For Mobile Cameras (Publishing):
- Install Larix Broadcaster on your phone
- Use the RTSPS URL shown in the terminal
- Enter the publisher username and password
- Start streaming!
🖥️ For Viewing:
- Web Dashboard: Open the URL shown (e.g.,
http://192.168.x.x:8080
) - OBS/VLC: Use the viewer RTSPS URL with credentials
- Browser HLS: Use the HLS URL for browser-based viewing
SpectraX uses YOLOv8 from Ultralytics for real-time object detection on your video streams.
Model | Size | Speed | Accuracy | Use Case |
---|---|---|---|---|
yolov8n.pt |
~6 MB | Fastest | Good | Multiple cameras, limited hardware |
yolov8s.pt |
~22 MB | Fast | Better | Balanced performance |
yolov8m.pt |
~52 MB | Medium | Very Good | Better accuracy needed |
yolov8l.pt |
~88 MB | Slow | Excellent | Single camera, good hardware |
yolov8x.pt |
~136 MB | Slowest | Best | Maximum accuracy |
Models are automatically loaded from video-feed/models/
or downloaded on first use.
Smart Filtering:
- Detect only specific objects (person, car, dog, cat, etc.)
- Filter by detection size (ignore tiny or huge detections)
- Adjust confidence threshold to reduce false positives
Visual Customization:
- Choose bounding box colors and thickness
- Customize label appearance and position
- Real-time overlay on video streams
Performance Tuning:
- Adjust processing resolution for speed vs. quality
- Configure frame buffer size
- Set reconnection intervals
YOLO can detect 80+ object classes including:
- People: person
- Vehicles: car, truck, bus, motorcycle, bicycle
- Animals: dog, cat, bird, horse, cow, sheep
- Common items: backpack, umbrella, handbag, suitcase, bottle, cup, chair, couch, bed, dining table, laptop, cell phone
See COCO dataset classes for the complete list.
Automatically record video clips when objects are detected.
- Continuous Buffering: System maintains a rolling buffer of recent frames
- Detection Trigger: When an object is detected, recording starts
- Pre-Buffer: Includes 10 seconds before the detection
- Post-Buffer: Continues 10 seconds after the last detection
- Metadata Storage: All recordings saved to SQLite database with searchable metadata
recording:
enabled: true
min_confidence: 0.5 # Only record high-confidence detections
pre_buffer_seconds: 10
post_buffer_seconds: 10
max_storage_gb: 10.0
recordings_dir: "~/video-feed-recordings"
record_objects: ["person", "car", "dog"] # Selective recording
- Automatic Cleanup: Oldest recordings deleted when storage limit reached
- Metadata Preserved: Database tracks all recordings with timestamps, objects detected, and confidence scores
- Efficient Format: MP4 videos with H.264 encoding
- Web Dashboard: Browse and play recordings in your browser
- REST API: Query recordings programmatically
- File System: Direct access to MP4 files in recordings directory
- Database: SQLite database for custom queries
Modern web interface for monitoring cameras and managing recordings.
- Live Video: Real-time MJPEG streams with AI detection overlays
- Multi-Camera Grid: View all cameras simultaneously
- Recordings Browser: Search, filter, and play recorded clips
- Statistics: FPS, detection counts, and system status
- REST API: Programmatic access to all features
- Responsive: Works on desktop and mobile browsers
Option 1: Integrated Dashboard (Recommended)
-
Start the system:
./scripts/surveillance.sh config
-
Open the URL shown in terminal (e.g.,
http://192.168.x.x:8080
) -
The dashboard shows:
- Live video feeds with detection overlays
- FPS and detection statistics
- Recordings tab for browsing saved clips
Option 2: Standalone HTML Dashboard
For quick access without the full system:
# Open standalone dashboard
./scripts/surveillance.sh dashboard
# Or open directly in browser
open video-feed/ui/dashboard.html
Note: The standalone dashboard requires the surveillance system to be running to connect to video streams.
Status and Streams:
GET /status
- System status and statisticsGET /video/stream
- MJPEG video stream with detectionsGET /paths
- Available camera paths
Recordings:
GET /api/recordings
- List all recordingsGET /api/recordings/{id}
- Get specific recordingGET /api/recordings/stats
- Recording statisticsGET /recordings/{filename}
- Download recording file
- Backend: FastAPI + Uvicorn
- Streaming: MJPEG for low-latency video
- Database: SQLite for recording metadata
- Templates: Jinja2 for HTML rendering
- Detection: Real-time YOLO inference
Start with custom settings:
./scripts/surveillance.sh custom --path video/camera-1 --path video/camera-2
Python module usage:
# Start streaming server only (no detection)
python -m videofeed.surveillance run --path video/front-door
# Start detection only (existing stream)
python -m videofeed.surveillance detect --rtsp-url "rtsps://viewer:pass@host:8322/video/cam"
# Reset stored credentials
python -m videofeed.surveillance reset
cd video-feed
pip install -e . # Editable install
# Run tests
pytest
# Run directly
python -m videofeed.surveillance config
For running as a system service:
# Copy service file
sudo cp scripts/surveillance.service /etc/systemd/system/
# Edit paths in service file
sudo nano /etc/systemd/system/surveillance.service
# Enable and start
sudo systemctl enable surveillance
sudo systemctl start surveillance
# Check status
sudo systemctl status surveillance
Replace self-signed certificates with your own:
security:
use_tls: true
tls_key: "/path/to/your/private.key"
tls_cert: "/path/to/your/certificate.crt"
MediaMTX fails to start:
- Check if MediaMTX is installed:
which mediamtx
- Verify ports 8322, 8554, 8888 are not in use
- Check terminal output for specific error messages
Connection refused errors:
- Ensure MediaMTX is running (check terminal output)
- Verify network bind address in config (127.0.0.1 vs 0.0.0.0)
- Check firewall settings
No video in dashboard:
- Verify camera is publishing to the correct URL
- Check credentials match those shown in terminal
- Ensure detector is running (look for "Loading model" message)
Recording not working:
- Check
recording.enabled: true
in config - Verify recordings directory exists and is writable
- Check
record_objects
list matches detected objects - Ensure sufficient disk space
Model downloads to wrong location:
- Models should auto-load from
video-feed/models/
- If not, manually download to that directory
- Check file permissions
Script not executable:
chmod +x scripts/surveillance.sh
Config file not found:
- Verify file exists at
video-feed/config/surveillance.yml
- Check file permissions (should be readable)
Module import errors:
# Install in development mode
cd video-feed
pip install -e .
Find your IP address:
# macOS/Linux
ifconfig | grep "inet " | grep -v 127.0.0.1
# Windows
ipconfig
Port Configuration:
- RTSP: 8554 (unencrypted)
- RTSPS: 8322 (encrypted)
- HLS: 8888 (browser streaming)
- Detection: 8080 (web dashboard)
- API: 3333 (paths discovery)
Slow detection:
- Use smaller model (yolov8n.pt instead of yolov8l.pt)
- Reduce resolution in config
- Decrease frame buffer size
- Limit number of cameras
High CPU usage:
- Lower detection resolution
- Increase confidence threshold (fewer detections)
- Use hardware acceleration if available
Recording lag:
- Reduce pre/post buffer seconds
- Lower video resolution
- Check disk I/O performance
- Check logs: Terminal output shows detailed error messages
- Reset credentials:
python -m videofeed.surveillance reset
- Test components separately:
- Test MediaMTX:
mediamtx --help
- Test Python:
python -m videofeed.surveillance --help
- Test MediaMTX:
- Review documentation: See
docs/
folder for detailed guides
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Submit a pull request
See LICENSE file for details.
- MediaMTX - Excellent RTSP/HLS server
- Ultralytics YOLOv8 - State-of-the-art object detection
- Supervision - Computer vision utilities
- FastAPI - Modern web framework