Motion Detection
Hybrid two-tier motion detection system combining server-side FFmpeg scene analysis with optional browser-based TensorFlow.js object identification.
Last updated: 2025-02-18
Motion Detection
Certexi's motion detection system uses a hybrid two-tier architecture combining reliable server-side detection with optional browser-based object identification.
Architecture
Surveillance Grid
The 2x3 camera grid shows live feeds from warehouse zones with status indicators for recording, motion detection, and alerts.
6 camera feeds — click any feed to expand. Motion detection and alert indicators shown in real time.
Tier 1: Server-Side Detection
The primary detection engine runs FFmpeg with scene detection filters:
ffmpeg -rtsp_transport tcp \
-i rtsp://camera-url \
-vf "select='gt(scene,0.3)',showinfo" \
-f null -
How It Works
- A long-running FFmpeg process is spawned per camera
- The
scenefilter calculates pixel differences between frames (0–1 scale) - When the difference exceeds the sensitivity threshold, a motion event fires
- The callback extracts a clip from the ring buffer (configurable pre/post recording)
- Clips are optionally uploaded to Nextcloud for evidence storage
Performance
| Metric | Value |
|---|---|
| Detection latency | 200–500ms |
| CPU per camera | 5–10% |
| Memory per camera | 50–100MB |
| Concurrent cameras | 10–20+ (typical server) |
| False positive rate | Low (pixel-level analysis) |
Auto-Recovery
The SimpleMotionDetector singleton manages FFmpeg processes with automatic restart on failure. If a process crashes, it is respawned within seconds.
Tier 2: Browser-Based Object Detection
An optional enhancement that runs TensorFlow.js COCO-SSD in the browser:
- Downloads the model (~6MB, cached after first load)
- Runs inference at 5 FPS on the video element
- Detects 80 object classes (person, car, truck, etc.)
- Draws bounding boxes with confidence scores
- Runs entirely in the browser — no frames sent to the server
Privacy
Browser-side detection is privacy-preserving. Video frames are analyzed locally using WebGL acceleration and never leave the device.
This tier is purely visual — all clip recording happens server-side. Users can disable it without affecting motion detection functionality.
API
Start Detection
POST /api/iot/detection/motion-stream
Content-Type: application/json
{
"cctvId": 1,
"action": "start",
"sensitivity": 0.3,
"cooldownSeconds": 5,
"preRecordSeconds": 5,
"postRecordSeconds": 10,
"uploadToNextcloud": true
}
Query Status
GET /api/iot/detection/motion-stream?cctvId=1
Returns running state, frame count, and motion frame statistics.
Configuration
| Parameter | Default | Description |
|---|---|---|
sensitivity | 0.3 | Motion threshold (0–1, lower = more sensitive) |
cooldownSeconds | 5 | Minimum seconds between clips |
preRecordSeconds | 5 | Buffer seconds before motion |
postRecordSeconds | 10 | Continue recording after motion |
uploadToNextcloud | true | Auto-upload clips to evidence storage |
Browser Detection
| Parameter | Default | Description |
|---|---|---|
confidenceThreshold | 0.5 | Minimum detection confidence |
maxDetections | 20 | Maximum objects per frame |
fps | 5 | Detection frame rate |
Integration with Evidence Capture
Motion detection clips are automatically linked to the evidence chain:
- Motion detected → clip extracted from ring buffer
- Clip uploaded to Nextcloud with metadata (camera ID, timestamp, duration)
- Detection event created in the event ledger
- Evidence hash computed and anchored
- Clip available in the Time Machine for playback
Tuning Guide
- Indoor cameras: Sensitivity 0.2–0.3 (lower for stable environments)
- Outdoor cameras: Sensitivity 0.4–0.5 (higher to filter wind/weather)
- High-traffic areas: Increase cooldown to 10–15 seconds
- Security-critical zones: Lower cooldown to 2–3 seconds