Skip to content

raspivid

Frank Bauernöppel edited this page Oct 25, 2017 · 18 revisions

tested with

  • RasPi 3B with Raspbian Jessie, IPv4 address 192.168.2.104
  • Ubuntu 16.04 client, IPv4 address 192.168.2.108

raspivid options used:

option explanation
-pf baseline use baseline profile (no B-frames) which reduces delay
-b 1000000 bitrate (1MBit/s)
-g 30 GOP (group of pictures) size of 30, i.e. send an I-frame every second
-ih inline headers: send SPS and PPS headers with each I-frame

live TCP streaming

on RasPi

RasPi is listening (-l) and keeps (-k) listening after a TCP session terminated. RasPi's own (local) IPv4 address is specified.

pi@raspberrypi:~ $ raspivid -t 0 -n -b 1000000 -g 30 -ih -pf baseline -w 640 -h 480 -fps 30 -l -o tcp://192.168.2.104:1234

Drawback: after client terminates, raspivid terminates too. So you might want to wrap it with an endless bash script loop

pi@raspberrypi:~ $ while :; do raspivid -t 0 -n -b 1000000 -g 30 -ih -pf baseline -w 640 -h 480 -fps 30 -l -o tcp://192.168.2.104:1234 ; done

remote client

Now, on remote client, vlc is opening and terminating TCP stream:

$ vlc -v tcp/h264://192.168.2.104:1234

UDP streaming

remote client

Start remote client first, otherwise it could miss the H.264 SPS/PPS which are needed for decoding the stream. Client is waiting for incoming packets on UDP socket:

$ vlc -vvv udp/h264://@:1234

RasPi

RasPi is pushing UDP packets to the client.

without nc

pi@raspberrypi:~ $ raspivid -t 0 -n -b 1000000 -g 30 -ih -pf baseline -w 640 -h 480 -fps 30 -o udp://192.168.2.108:1234

while client port is not available, you see error messages like mmal: Failed to write buffer data (3294 from 14539)- aborting but they do not do any harm.

with nc

I think, this is no longer needed.

pi@raspberrypi:~ $ raspivid -t 0 -n -b 1000000 -g 30 -ih -pf baseline -w 640 -h 480 -fps 30 -o - | nc -p 1904 -u 192.168.2.108 1234

passing video to gstreamer

pi@raspberrypi:~ $ raspivid -t 10000 -n -b 1000000 -g 30 -ih -pf baseline -w 1920 -h 1080 -fps 30 -o - | gst-launch-1.0 fdsrc ! 'video/x-h264,profile=baseline, width=1920, height=1080' ! h264parse ! mp4mux ! filesink location=test.mp4

RTSP streaming

there is a session concept + time stamping (RTP) included. several transport protocols are possible: UDP, TCP and HTTP tunnelled.

RTP/UDP

# raspivid -t 0 -n -b 1000000 -g 30 -ih -pf baseline -w 640 -h 480 -fps 30 -o - | cvlc -v stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264
$ vlc -v rtsp://192.168.2.104:8554/

further steps

RTSP streaming has many more options like:

  • http tunnelling to stream through a firewall
  • specifying user and password for stream protection

there are alternative RTSP streaming servers out like:

  • live555
  • gst-rtsp-server
Clone this wiki locally