6

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.

DaveCode
  • 73
  • 2
  • 2
  • 5
  • does unicast work for you - try `host=127.0.0.1` – nayana Dec 04 '15 at 13:17
  • Thanks for your reply @otopolsky. I tried and yes, now it shows some images... but it's incredibly slow. The vlc log says `main error: ES_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to 567 ms) main error: ES_OUT_RESET_PCR called avcodec error: more than 5 seconds of late video -> dropping frame (computer too slow ?)`. Maybe h264 it's too much for the raspberry. I'm trying to find an encoder that doesn't need that much horsepower from the raspberry. So far, no luck. – DaveCode Dec 04 '15 at 14:12
  • what about setting faster preset on x264enc? try `speed-preset=2` or you can try even `tune=zerolatency` – nayana Dec 04 '15 at 14:38
  • Hi again @otopolsky! I tried and same result... vlc log says: `es error: cannot peek es error: cannot peek main error: Failed to resize display avcodec error: more than 5 seconds of late video -> dropping frame (computer too slow ?) avcodec error: more than 5 seconds of late video -> dropping frame (computer too slow ?)`.I'll have to keep searching :). Thanks for the reply! – DaveCode Dec 04 '15 at 15:03
  • what happens when you just use in vlc `rtp://@:5004` ? you can also try without scale, it may be too much for rpi.. what is the CPU load when you do that? – nayana Dec 08 '15 at 08:21
  • Hi @otopolsky. Sorry for the (very)late reply. I tried what you suggested (rtp://@:5004). And still doesn't work... – DaveCode Feb 01 '16 at 10:53
  • Hi @otopolsky. Sorry for the (very)late reply. I tried what you suggested (rtp://@:5004). And still doesn't work... I thought the problem was due to the lack of power of the raspberry. Maybe it's not the case because after including the parameter you said (speed-preset=2) i checked the raspberry cpu performance and it's around 50%... on the client side despite the "video -> dropping frame (computer too slow ?)" message i don't think it's due to my cpu not being able to play the stream because if i monitor my cpu when i'm playing the stream it barely takes a 5% of cpu workload... (1/2) – DaveCode Feb 01 '16 at 11:02
  • So what i think is that i'm probably not building the pipeline properly. Thanks again for your replies! (2/2) – DaveCode Feb 01 '16 at 11:04
  • what about this pipe `videotestsrc ! queue ! x264enc ! h264parse ! mpegtsmux ! rtpmp2tpay ! udpsink host=192.168.0.123 port=5555` and at vlc use rtp:@5555 - no sdp needed, tested it works for me (but on Desktop not rpi) – nayana Feb 01 '16 at 12:29
  • Hi again @otopolsky! Thanks! It works now! You were right. It works without using the sdp file. I don't know what i did wrong the first time. Might have misspelled something. Finally the gstreamer command that worked for me was: `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` I will try to squeeze some more quality to the stream w/o collapsing the cpu but at least i can see something now! Thanks for all your help @otopolsky! – DaveCode Feb 02 '16 at 08:43

1 Answers1

7

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
nayana
  • 3,787
  • 3
  • 20
  • 51
  • Great explanation! Now i undestand the mpegtsmux slicing part better! Despite being repetitive, thanks @otopolsky! – DaveCode Feb 02 '16 at 11:26
  • I have a very similar pipeline (mpegtsmux ! rtpmp2tpay ! udpsink), however my VLC does not play the stream. Could you please elaborate a bit more on how to setup the VLC to play this? Thanks! – Milos Mrdovic Jul 14 '19 at 22:54