Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GStreamer - Webcam stream from Raspberry to VLC-PC

I'm trying to stream webcam video from a Raspberry to a VLC player using gstreamer 1.0. Right now i got the following command for the Raspberry:

gst-launch-1.0 -vv -e v4l2src device=/dev/video0  \
! videoscale \
! "video/x-raw,width=352,height=288,framerate=10/1" \
! queue  \
! x264enc \
! h264parse \
! rtph264pay config-interval=10 pt=96 \
! udpsink host=239.255.12.42 port=5004

And the following sdp file to play the stream with vlc:

c=IN IP4 239.255.12.42
m=video 5004 RTP/AVP 96
a=rtpmap:96 H264/90000

When i run the gst-launch-1.0 command i can see with wireshark that it is sending udp packets but when i try to play the stream with vlc and the sdp file i get nothing. The vlc log says:

es error: cannot peek
es error: cannot peek
live555 error: no data received in 10s, aborting

I don't know what's wrong. I probably have'nt build the pipeline properly and that's why the vlc does not recognize the stream as a proper video stream. Any ideas?

Thanks in advance for your help.

like image 433
DaveCode Avatar asked Dec 04 '15 12:12

DaveCode


1 Answers

VLC understand ts stream combined with RTP protocol. The approach is to use rtp payloader after mpegtsmux which will payload the generated ts buffers (packets).

So instead of this:

src ! queue ! x264enc ! h264parse ! rtph264pay ! udpsink

You can do this:

src ! queue ! x264enc ! h264parse ! mpegtsmux ! rtpmp2tpay ! udpsink

And then use just rtp://@:port in vlc In this way the mpegtsmux will encapsulate information about what streams does it contains

I should note that your approach is not incorrect, and could be even more effective (mpegtsmux will slice video into 188 Byte packets, but your approach will slice into ~ 1400 Bytes udp packets), but you need to provide correct SDP file for vlc in order to stream it. For example like this but I do not have much experience with this..

So this is your current pipe which works:

gst-launch-1.0 -vv -e v4l2src device=/dev/video0 ! "video/x-raw,width=352,height=288,framerate=25/1"\ ! queue ! x264enc speed-preset=1 ! h264parse ! mpegtsmux ! rtpmp2tpay ! udpsink host=192.255.10.41 port=5004

You can maybe achieve better results when using zerolatency:

like this x264enc tune=4 it will discard all other quality parameters like speed-preset etc..

This is from docs about tune property:

tune : Preset name for non-psychovisual tuning options
       flags: readable, writable
       Flags "GstX264EncTune" Default: 0x00000000, "(none)"
       (0x00000001): stillimage       - Still image
       (0x00000002): fastdecode       - Fast decode
       (0x00000004): zerolatency      - Zero latency
like image 169
nayana Avatar answered Nov 04 '22 08:11

nayana