Remote video streaming from Raspberry PI camera

Содержание

raspberry pi remote camera streaming featured image

This tutorial will show you how to setup a remote video streaming from a Raspberry PI camera using terminal, without the need of a desktop environment.

In this project, Raspberry PI will work as a streaming server, broadcasting its camera video using Raspivid piped to Netcat.

Raspivid is the default (preinstalled in all Raspberry PI OS distributions) command line tool for capturing video with a Raspberry Pi camera module. It is part of raspicam tools, a set of software able to manage your Raspberry PI Camera for getting videos (raspivid), time lapse video or photographs (raspistill).

NetCat (alias nc) is a computer networking utility for receiving and sending data to network connections using TCP or UDP.

I will use a Raspberry PI 3 Model A+, but this procedure applies to all Raspberry PI boards.

What We Need

RPI 3 model A+

As usual, I suggest adding from now to your favourite e-commerce shopping cart all needed hardware, so that at the end you will be able to evaluate overall costs and decide if continuing with the project or removing them from the shopping cart. So, hardware will be only:

    (including proper power supply or using a smartphone micro usb charger with at least 3A) or newer Raspberry PI Board (at least 16 GB, at least class 10)

Check hardware prices with following links:

Amazon raspberry pi boards box

Amazon Micro SD box

Amazon Raspberry PI Power Supply box

Amazon Raspberry PI Camera box

Step-by-Step Procedure

Stat preparing your operating system. You can install Raspberry PI OS Lite (for a headless, fast linux distribution) or Raspberry PI OS Desktop (in this case, using its internal terminal).

Make your OS up-to-date. From terminal:

Connect camera to your Raspberry PI camera module port.

Enable camera interface from raspi-config tool. From terminal:

raspi-config home pi3 model A+

Select option 3 (Interface Option) with arrow keys and press ENTER:

raspi-config interface options pi3 model A+

We’ll use first option (Camera). So, simply press ENTER again. In next window, select “yes” with left arrow key:

raspi-config interface options camera pi3 model A+

Press ENTER to confirm. Next window will confirm that camera is enabled:

raspi-config interface options camera enabled pi3 model A+

Press ENTER. You will go back to raspi-config home. Go to FINISH and press ENTER. A reboot will be required:

raspi-config reboot pi3 model A+

Please confirm and wait for your Raspberry PI to be rebooted.

Start Raspberry PI Streaming

Raspberry PI streaming will start with following terminal command:

This command will trigge raspivid to start capturing camera video and directing its output, via pipe operator (“|”) to netcat (nc is an alias for netcat command). Used options mean following:

  • -t: specifies ms of video to capture (default 5000). If set to zero, disables timeout to have a continuous stream
  • -b: sets bitrate, in bits per second. 25000000 means 25Mbps
  • -fps: sets frames per second capturing rate
  • -w and -h: set image width and height (in pixels)
  • -o sets output. If you specify a file name, it will save video to a file. With “-o -” it will redirect output to stdout.

Following explain netcat options:

  • -l: work in listening mode, waiting for inbound connections
  • -k: Keep inbound sockets open for multiple connects
  • -v: enable verbose mode
  • -4: use IPv4
  • last parameter (8080) sets port to 8080

Once used this command, Raspberry PI will start to listen on network for incoming connections:

From receiving PC side, you will now be ablo to get video stream with video player able to read network stream using tcp protocol and h264 encoding. In my example I will use the free VLC (Videolan), avaliable both for windows and linux. I will use it installed on a windows PC on same LAN.

From VLC interface, select from “Media” menù “Open Network Stream”. Use your Raspberry PI IP address instead of mine (192.168.1.178) and insert a link composed as following:

VLC remote streaming tcp h264 port 8080

Finally use Play button to start vieweing you Raspberry PI camera stream.

Final Toughts

Raspivid with netcat will produce a reliable remote video streaming, but introducing delay. Some user report having better performance by using rtp (Real Time Protocol). This way requires installing vlc on Raspberry PI (which uses ablout 1GB of storage).


Источник: peppe8o.com