Low-Latency Raspberry Pi Audio/Video Streaming Hub

An embedded smart recording and surveillance hub built on a Raspberry Pi running Ubuntu Linux, combining computer vision, real-time media streaming, continuous audio capture, and fault-tolerant remote replication.

Role: Sole Developer
Timeline: Spring 2026
PythonRaspberry PiOpenCVFlaskWebSocketsLinux ALSAsystemdSyncthingUbuntu

Overview & Objective

The objective of this project was to engineer a robust, self-hosted security and monitoring solution that operates independently of third-party cloud services. By developing custom streaming protocols and integrating computer vision directly on the edge, the system acts as a highly efficient, fault-tolerant surveillance hub.

Technical Implementation

Motion-Triggered Video Analytics

Deployed an OpenCV processing pipeline utilizing frame differencing and contour detection to trigger automatic video recording only when physical motion thresholds are exceeded, drastically preserving local storage capacity.

Low-Level Audio Subsystem

Interfaced directly with Linux ALSA (Advanced Linux Sound Architecture) drivers to capture continuous audio streams in parallel with video encoding threads, preventing thread contention or buffer overruns.

Live Streaming Backend

Built a lightweight Flask and WebSocket server to broadcast real-time, low-latency video and telemetry feeds directly to authenticated browser clients.

Background Services & Replication

Encapsulated recording pipelines into dedicated Linux systemd background daemons for automatic crash recovery and startup initialization, alongside automated multi-device folder synchronization powered by Syncthing.

Challenges & Problem Solving

I/O Blocking and Threading

Initially, capturing ALSA audio and processing OpenCV frames on the same thread caused severe buffer underruns and dropped video frames. I resolved this by decoupling the subsystems, placing the audio capture, motion detection, and WebSocket broadcasting into separate asynchronous threads using Python's threading and queue modules.

File Corruption on Power Loss

Sudden shutdowns corrupted the active video files. I integrated a signal handler to safely close the recording buffers upon detecting a SIGTERM, and configured Syncthing to immediately replicate completed files to a remote server to ensure data integrity.

Results & Future Improvements

Results

Achieved a continuous, motion-triggered surveillance feed with synchronized audio and video, maintaining a latency of under 200ms over local WebSockets while utilizing systemd for 100% automated uptime.

Future Improvements

I aim to migrate the Flask WebSocket pipeline to a true peer-to-peer WebRTC implementation to further reduce bandwidth overhead and improve streaming stability over external networks.