CCTV SmartHub & Edge AI Systems
This skill provides an authoritative architectural framework for building high-reliability, 24/7 SmartHub CCTV systems with integrated Edge AI computer vision.
It details the end-to-end surveillance pipeline: multi-camera ingestion, direct-to-disk recording, zero-copy shared memory frame delivery, cascaded motion detection, real-time object detection and tracking, and storage retention.
Detailed References
- CCTV SmartHub & Edge AI Reference Architecture
- Stream Ingestion, Protocols & Media Demuxing
- Vision Analytics, Motion Gating & Tracking Pipeline
- 24/7 Storage, Retention & Video Recording Pipelines
Underlying Compute Optimization Companion
For low-level microarchitectural tuning, SIMD intrinsics, zero-copy memory ring buffers, and OS kernel governance, see the companion skill:
1. Core Architectural Pillars
1.1 The Dual-Stream Law
Never decode a high-resolution main stream (4K/1080p) for AI computer vision:
- Main Stream (High-Res): Demux RTP/H.264 packets and write directly to segmented MP4 containers on disk without decoding. CPU cost is $< 0.2%$ per camera.
- Sub Stream (640x360 @ 5–10 FPS): Pass to hardware decoders (VA-API / NVDEC / QSV) for motion gating and neural network inference.
1.2 Cascaded Vision Analytics
Neural networks must never process static or irrelevant frames:
- SIMD Frame Difference (CPU): Compute absolute luminance difference ($F_t - F_{t-1}$) in $< 0.05\text{ms}$. If changed pixels $< 0.5%$, discard immediately.
- Background & ROI Modeling: Filter repetitive foliage movement and privacy masks.
- Neural Detection: Dispatch to quantized INT8/FP16 models (YOLOv8-Nano / MobileNetV4) only when motion zones are triggered.
- Multi-Object Tracking: Maintain track continuity with ByteTrack to prevent repeated duplicate alerts.
1.3 Zero-Copy Ingestion-to-Inference IPC
Avoid passing raw pixel buffers over network sockets or serializing across runtimes. Use POSIX Shared Memory (/dev/shm + mmap) with 64-byte cache-line aligned C-ABI structs to share decoded frames between the ingestion process (Go/Rust) and the AI engine (C++/CUDA).
1.4 Hybrid Storage & Smart Watermark Pruning
- Combine continuous low-bitrate sub-stream recording with motion-triggered 4K main-stream recording (buffered with 5–10 second pre-event RAM chunks).
- Prune historical video using high/low disk watermarks (90% to 85%) via batched SQLite queries, avoiding heavy filesystem
rm -rfscans that freeze disk I/O.
2. Polyglot Architecture & Workload Division
┌────────────────────────────────────────────────────────┐
│ Stream Ingester & NVR Daemon (Go) │
│ - RTSP TCP / WebRTC ingestion with M:N goroutines │
│ - Direct-to-disk fragmented MP4 segmentation │
│ - Circular RAM pre-event buffers │
└──────────────────────────┬─────────────────────────────┘
│ Raw Sub-Stream NALs
▼
┌────────────────────────────────────────────────────────┐
│ Native Vision & AI Engine (Rust / C++) │
│ - VA-API / NVDEC / VideoToolbox hardware decode │
│ - SIMD luminance motion differencing (NEON / AVX2) │
│ - ONNX Runtime / TensorRT neural inference │
│ - ByteTrack Kalman filter tracking │
└──────────────────────────┬─────────────────────────────┘
│ Detection Events & Bounding Boxes
▼
┌────────────────────────────────────────────────────────┐
│ Management & User Gateway (Node.js / Go) │
│ - SQLite WAL event metadata persistence │
│ - WebSocket live client push │
│ - User dashboard, rules engine, notification webhooks │
└────────────────────────────────────────────────────────┘
3. Production Verification Checklist
- Is RTSP transport set to interleaved TCP? Avoid UDP packet drop artifacts.
- Is the 4K main stream being recorded direct-to-disk? Verify no CPU/GPU re-encoding occurs on the recording path.
- Are MP4 segments aligned to IDR keyframes? Ensure GOP boundary cuts to maintain chunk playability.
- Is neural inference gated by motion? Ensure idle camera streams consume 0% inference compute.
- Is SQLite configured with
PRAGMA journal_mode = WAL;andsynchronous = NORMAL;? Prevent disk stalls during continuous event logging.