raspberry pi

Stream Raspberry Pi Zero Camera Using raspivid

This post briefly describes streaming video from a Raspberry Pi Zero (Rpi) with an RPi Camera (v1 or v2) to another local device using raspivid, netcat, and mplayer. This is simplified since raspivid now has the ability to output directly to a TCP URL/Port. This avoids having to pipe the camera output to a network application (netcat) on both the server-side and client side. And with a single SSH call from the client to the Raspberry Pi initiating the video stream may be started from the client without having to log in to the Raspberry Pi. mplayer will receive and play with little delay (depending on resolution, machine power, and several other factors).

raspivid outputs h264 video by default and programs like VLC and mplayer play it directly but as it is with codecs it may be transcoded. The intention here is to have the least latency possible while maintaining as close to real-time 720p video as possible. Processing on the fastest machine (client in this case – any current laptop is much faster than a Raspberry Pi Zero) is therefore required as well as keeping the raw output of the camera.

System Setup

Install the latest version of Raspbian on your SD card, insert into Raspberry Pi, plug the camera into its CSI port and power-up. Then update the system with the following command:

$ sudo apt-get update && sudo apt-get upgrade -y

Enabling SSH will be necessary through the raspi-config utility which may be found under the Interfaces menu item. Open the config menu and enter the Interfaces menu then choose Camera and finally Yes then reboot.

$ sudo raspi-config


Install netcat and mplayer then run netcat to listen on a specified open port, piping that into mplayer. Here are the commands:

$ sudo apt-get install netcat mplayer
nc -l -p 9000 | mplayer -fps 60 -cache 4000 -cache-min 50 - 

The caching and additional parameters to mplayer should be adjusted to achieve whatever quality is desired.


Now to send the video to the waiting client, as mentioned straight away, raspivid is all that is needed to get the video directly to a destination via TCP. The -o argument specifies the output ,and -t is the length of time to display or send video, where a value of zero represents infinity.

raspivid -o -t 0

There are plenty of options available to tweak raspivid. Only the bare minimum has been shown here just to provide a working example. Review the manual.

Leave a Reply