Tzu Huan Tai's WebRTC Camera Stack Turns a Raspberry Pi Zero 2 W Into a Low-Latency Streamer

Buildable at a low cost, and with optional two-way communication, this Raspberry Pi-powered camera project streams with sub-1s latency.

Software engineer Tzu Huan Tai has built a live-streaming camera from a Raspberry Pi Zero 2 W — but has gone beyond most similar projects by implementing WebRTC for low-latency streaming, on-device recording, QR code-based camera sharing, and peer-to-peer connectivity for multiple users.

"I've been using a Raspberry Pi as a live camera to monitor plants on my balcony for a while," Tai explains. "A few months ago, a friend visited and noticed this little stuff. He mentioned how he’d love to try something similar since he doesn’t like uploading videos to cloud services, paying subscription fees, or relying on third-party providers. The subscription fee would be very high, especially if he wants to install multiple cameras around his house. So I do my best to begin integrating all the features into an easy-to-use app and design easy-to-follow steps for people (like him) without a tech background to try it out."

This live-streaming camera, shown with optional microphone and speaker for two-way communication, is designed for low-latency WebRTC streaming. (📷: Tzu Huan Tai)

Tai's solution to meet his friend's needs was a software stack fully compatible with the Raspberry Pi family of single-board computers and cameras connected over their MIPI Camera Serial Interface (CSI) ports. The key: a low-latency stream and ease of use. Development began with a Raspberry Pi 4 Model B, but switched to the lower-cost Raspberry Pi Zero 2 W to bring down the bill of materials — using the hardware video encode blocks included in the graphics processor to reduce load on the CPU.

A companion mobile app delivers the ease-of-use side of the equation, with each camera only needing to be added and configured once. These cameras can then be viewed live, using WebRTC — with around one second of latency when running on a Raspberry Pi Zero 2 W — or shared to another user, who only has to scan a QR code displayed on the original smartphone to gain access. Messaging is handled via MQTT, while peer-to-peer access means no reliance on a third-party service — though multiple simultaneous streams may require the more powerful Raspberry Pi 4, rather than the cheaper Raspberry Pi Zero 2 W.

Cameras are managed through a companion app, and can store recordings locally for later download. (📷: Tzu Huan Tai)

As well as live streaming, the cameras can record to local storage for later review — though, at the time of writing, each recorded video needed to be downloaded in full before playback can begin. "How long videos can be stored depends on the size of the USB disk you plug in," Tai notes. "If I have time, I’ll implement MP4 [playback] on-demand through WebRTC."

More information on the project is available in Tai's Reddit post, while source code and setup instructions are available on GitHub under the permissive Apache 2.0 license. Instructions for using the smartphone app are in a separate repository.

ghalfacree

Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.

Latest Articles