Low latency video with a Raspberry Pi

Now that I have a camera board, I’ve been trying to get a real-time video stream out of the Raspberry Pi. First I tried using RTSP, but the problem is that a video player will start buffering an incoming stream, giving you a 10 second delay. I don’t know whether this can be avoided. Then again, I haven’t looked very hard.
I got rather decent results by just bypassing all the overhead, and sending the H.264 stream of the camera directly to a TCP tunnel. On the desktop side, you can then read the data and pipe it to mplayer. For the network transport, netcat comes to the rescue:

First, start listening on the desktop:
nc -u -l -p 6502 | mplayer -fps 15.1 -demuxer h264es -

Then, open the floodgates on your raspberry pi:
raspivid -t 0 -hf -w 320 -h 240 -fps 15 -b 500000 -o - | nc -u 192.168.1.7 6502

There are a lot of parameters you can play with, trying out tcp instead of udp, changing bitrate, size etc. Notice that I set the playback rate a bit higher, this keeps mplayer constantly hungry. If the camera sends even slightly faster than mplayer shows, the frames would start to pile up, and you would get an ever increasing lag (and memory usage).

Leave a Reply

Your email address will not be published. Required fields are marked *