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

Loading diagram…

Surveillance Grid

The 2x3 camera grid shows live feeds from warehouse zones with status indicators for recording, motion detection, and alerts.

certexi.com/app/surveillance/grid
Loading interactive demo...

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

  1. A long-running FFmpeg process is spawned per camera
  2. The scene filter calculates pixel differences between frames (0–1 scale)
  3. When the difference exceeds the sensitivity threshold, a motion event fires
  4. The callback extracts a clip from the ring buffer (configurable pre/post recording)
  5. Clips are optionally uploaded to Nextcloud for evidence storage

Performance

MetricValue
Detection latency200–500ms
CPU per camera5–10%
Memory per camera50–100MB
Concurrent cameras10–20+ (typical server)
False positive rateLow (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

ParameterDefaultDescription
sensitivity0.3Motion threshold (0–1, lower = more sensitive)
cooldownSeconds5Minimum seconds between clips
preRecordSeconds5Buffer seconds before motion
postRecordSeconds10Continue recording after motion
uploadToNextcloudtrueAuto-upload clips to evidence storage

Browser Detection

ParameterDefaultDescription
confidenceThreshold0.5Minimum detection confidence
maxDetections20Maximum objects per frame
fps5Detection frame rate

Integration with Evidence Capture

Motion detection clips are automatically linked to the evidence chain:

  1. Motion detected → clip extracted from ring buffer
  2. Clip uploaded to Nextcloud with metadata (camera ID, timestamp, duration)
  3. Detection event created in the event ledger
  4. Evidence hash computed and anchored
  5. 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
Motion Detection | Certexi Docs