Streaming Video From the Raspberry Pi Camera…

February 6, 2014 | Raspberry Pi | By: Mark VandeWettering

First of all, let me get this off my chest: video over the web is a hideous Tower of Babel.

With that basic complaint, let me start by saying that this project started with a Raspberry Pi and the Raspberry Pi Camera. Previously, I had used the Pi with a USB webcam and had connected it to my wireless router and run the “motion” program to serve as a kind of cat cam. But to be honest, I wasn’t really very happy with the results. The videos it recorded were low frame rate. The quality of the camera was pretty low. It was good enough to allow me to monitor my cat while I was on vacation, and have some assurance that he was still alive, but it left something to be desired.

After picking up some new $8.88 TP-Link Wifi dongles, I decided to see what else I could do. The trick with making this work was trying to find a way to leverage the video compression hardware that already runs on the raspberry pi, and to do as little as possible to it, but still allow it to be streamed to standard web browsers and devices.

I briefly went through experimenting with mjpegstreamer which works, but didn’t really offer the quality that I was after.

Then, I stumbled on this great article on using nginx-rtmp to stream live video from the Raspberry Pi. It looked like just what I wanted. It took me an evening (mostly spent waiting for nginx and ffmpeg to recompile) but I have it working now. Check it out:

Screen Shot 2014-02-06 at 8.56.16 AM

I’m currently able to stream 720×486 wide video at 25fps directly from the Pi at around 25fps, using somewhere around 13% of the available cpu on the Pi. It can be accessed by both desktop browsers and my iPad/iPhone. Seems really good!

With a couple of caveats. Remember that Tower of Babel I mentioned? Yeah, that. To stream to desktop browsers, they must run Flash. That is because nginx-rtmp uses RTMP, which is a proprietary streaming video protocol. But, I’m sure you say “how does this work on the iPad/iPhone?” The answer is it uses a different protocol for those devices, the HTTP Live Streaming protocol, which is also transparently supported by the RTMP server. Why can’t you just use HLS on the desktop? Because most desktop browsers don’t support HLS. Sigh. HLS also has increased latency compared to the RTMP protocol.

Sigh.

But anyway, it works! I’m awaiting the arrival of an Raspberry Pi camera with the IR filter removed and an IR illuminator, and I’ll be doing more experiments. I’ll maybe write up more explicit instructions for this when i get the entire thing working. If anyone wants to give this a try and has trouble, don’t hesitate to sing out with questions.

Share Button
Be Sociable, Share!

Write a comment