HD Streaming from Raspberry Pi

HD Streaming from Raspberry Pi with PiCamera module.

RPi_Zero_W

Introduction.

This post demonstrates 3 methods of streaming HD video over a network from a Raspberry Pi with a PiCamera module to a remote PC running the required client software. Considering
that 3 of the servers can each use 3 different clients, there is really 9 permutations here for sending and receiving the video stream. The demonstrations listed here, while in practice all
work quite well, for practical use would require some refinement. Graceful server/client disconnection/reconnection is not a consideration in this document.

Hardware, Software & Resolution.

The main player is the Raspberry Pi Zero W, running Raspbian Stretch Lite.
A PC running Ubuntu 18.04 (and if using the python client) python3 with cv2 library.
The video resolution used was 1280 x 720 @ 20fps.

Three clients for displaying Rpi H264 tcp Network streams.

The following three client methodologies for viewing H264 tcp streams on a remote PC (running Linux Ubuntu 18.04 in this case) will work with any of the three following H264 Servers
running on the Raspberry Pi (running Debian Stretch Lite).

Note: 192.168.1.200 needs to be replaced with your RPi address.

1.Using vlc

Make sure you’ve got the following packages installed:

$ sudo apt-get install vlc

In a terminal on PC running Linux enter the following:

$ vlc tcp/h264://192.168.1.200:8000/
2.Using mplayer

Make sure you’ve got the following packages installed:

$ sudo apt-get install mplayer

In a terminal on PC running Linux enter the following:

$ mplayer -fps 200 -demuxer h264es ffmpeg://tcp://192.168.1.200:8000
3.Using python3 + OpenCV

This method uses python3 and OpenCV
Create/copy ‘client_cv2.py’ file to the Rpi.
In a terminal on the Rpi enter the following:

$ python3 client_cv2.py

Download ‘client_cv2.py’  Here.
Note: The url address in client_cv2.py (192.168.1.200) will need to be edited and replaced with your RPi address.
You will also need cv2(OpenCV) library installed on python3.

Serving HD video stream from Raspberry Pi.

Installation (On Rpi with working Pi camera module)
Make sure you’ve got the following packages installed:

$ sudo apt-get install python3 python3-picamera

The client for the severs below can be Linux PC running either vlc, mplayer or python OpenCV client script as described above.

1. Using python script. ‘server_h264.py’.

This method the Raspberry Pi uses a python script to serve a H264 video stream via tcp socket to a client.
Download ‘server_h264.py’ Here

Starting the Server (On Rpi)
In a terminal on the Rpi enter the following:

$ python3 server_h264.py
2. Using raspivid & netcat.

This method the RPi uses raspivid piped to netcat, as a console command line, to serve a video stream to a networked client.
Make sure you’ve got the following packages installed on the Raspberry Pi:

$ sudo apt-get install netcat

Starting the Server (On Rpi)
In a terminal on the Rpi enter the following:

$ raspivid -t 0 -w 1280 -h 720 -ih -fps 20 -o - | nc -k -l 8000
3. Using raspivid.

This method the RPi uses raspivid, as a console command line, to serve a tcp video stream to a client.

Starting the Server (On Rpi)
In a terminal on the Rpi enter the following:

$ raspivid -l -t 0 -w 1280 -h 720 -fps 20 -o tcp://0.0.0.0:8000

The lowest latency was achieved with mplayer as the client and raspivid as the server.

1 Comment

  1. Great content! Super high-quality! Keep it up! 🙂

    Reply

Leave a Reply