← all projects

project

Streaming video off a robot without spending the CPU

Software H.264 encoding eats 70–80% of a Pi's CPU. Passing the camera's hardware-encoded stream through V4L2 instead drops that to near zero.

Date
Jun 2025
Role
Solo build — GStreamer pipelines, browser clients
Status
shipped
Built with
GStreamer 1.0, Python 3, WebRTC, V4L2, ALSA, Tailscale

The problem was simple to state: software-encoding a video stream on a Raspberry Pi consumes most of the CPU, leaving almost nothing for the robot’s actual control logic. The fix was to stop encoding on the Pi entirely and pass the camera’s native H.264 output straight through.

The server is Python aiohttp with GStreamer doing the media work. Video arrives hardware-encoded over V4L2 — the Pi is a transport node, not an encoder. Audio is captured straight from ALSA, bypassing PipeWire to keep latency down. Three audio processing modes are selectable at startup: NONE (3–5% CPU), LIGHT (basic noise suppression, 10–15%) and MEDIUM (full echo cancellation via webrtcdsp, 15–20%).

The operator connects through a browser — separate interfaces for desktop and iPhone — and gets a live feed with volume, mute and fullscreen. Tailscale handles reachability.

What I took away

Hardware encoding on embedded systems isn’t an optimisation, it’s the design. Software encoding is fine for a demo and leaves no headroom for anything else. Treating the Pi as a transport node rather than an encoding node is the correct mental model.

ALSA and PipeWire conflict resolution needs to be automated, not documented. If the user has to stop a service manually before starting the server, eventually they won’t, and they’ll spend an hour debugging what looks like a hardware fault.

GStreamer caps filters should be explicit everywhere, not only where negotiation visibly fails. Implicit negotiation quietly picks a suboptimal format, and finding that later is much harder than writing the caps string upfront.

RoboticsReal-Time MediaEmbedded Linux