GStreamer UDP send/receive one-liner

13,906

The mistake you are making is that you are assuming what your v4l2src will give out. If you want a particular frame-rate height and width, you need to use videoscale and videorate filters

gst-launch-0.10 -v gstrtpbin name=rtpbin v4l2src device=/dev/video0 ! videorate ! videoscale ! ffmpegcolorspace ! 'video/x-raw-yuv, width=(int)320, height=(int)240, framerate=(fraction)15/1' !  rtpvrawpay ! rtpbin.send_rtp_sink_0 rtpbin.send_rtp_src_0 ! multiudpsink clients="127.0.0.1:9996" rtpbin.send_rtcp_src_0 ! multiudpsink clients="127.0.0.1:9997" sync=false async=false udpsrc port=10000 ! rtpbin.recv_rtcp_sink_0

This will now print the caps that you need to use on the reciever side. Eg. For me this printed. /GstPipeline:pipeline0/GstRtpBin:rtpbin.GstGhostPad:send_rtp_src_0.GstProxyPad:proxypad2: caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)RAW, sampling=(string)YCbCr-4:4:4, depth=(string)8, width=(string)320, height=(string)240, colorimetry=(string)SMPTE240M, ssrc=(uint)1825678493, payload=(int)96, clock-base=(uint)4068866987, seqnum-base=(uint)24582

Using this on the reciever pipeline:

GST_DEBUG=2 gst-launch  udpsrc caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)RAW, sampling=(string)YCbCr-4:4:4, depth=(string)8, width=(string)320, height=(string)240, colorimetry=(string)SMPTE240M, ssrc=(uint)1825678493, payload=(int)96, clock-base=(uint)4068866987, seqnum-base=(uint)24582" port=9996 ! queue ! rtpvrawdepay  ! queue ! ffmpegcolorspace ! autovideosink

The receiver here has no way of knowing the exact caps and hence has to be copy pasted from the sender side. If you want a different sampling use ffmpegcolorspace on the sender and set the appropriate caps after it. (alongside the width, height and framerate)

The above pipeline works fine for me. Remember that ssrc and some other parameters will vary for every run of the src.

Share:
13,906

Related videos on Youtube

alexandernst
Author by

alexandernst

Updated on June 04, 2022

Comments

  • alexandernst
    alexandernst almost 2 years

    I'm trying to stream v4l2src over UDP using GStreamer. The sending part is (apparently) ok, but the receiving part is missing something.

    Those are the actual lines:

    Send: gst-launch-0.10 -v gstrtpbin name=rtpbin v4l2src device=/dev/video0 ! 'video/x-raw-yuv, width=(int)320, height=(int)240, framerate=(fraction)15/1' ! rtpvrawpay ! rtpbin.send_rtp_sink_0 rtpbin.send_rtp_src_0 ! multiudpsink clients="127.0.0.1:9996" rtpbin.send_rtcp_src_0 ! multiudpsink clients="127.0.0.1:9997" sync=false async=false udpsrc port=10000 ! rtpbin.recv_rtcp_sink_0

    Receive: gst-launch-0.10 -v gstrtpbin name=rtpbin udpsrc caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)RAW, sampling=(string)YUV, depth=(string)8, width=(string)320, height=(string)120, colorimetry=(string)SMPTE240M" port=9996 ! rtpbin.recv_rtp_sink_0 rtpbin. ! rtpvrawdepay ! video/x-raw-yuv,framerate=15/1 ! xvimagesink udpsrc port=9997 ! rtpbin.recv_rtcp_sink_0 rtpbin.send_rtcp_src_0 ! multiudpsink clients="127.0.0.1:10000" sync=false async=false

    What am I missing?

    Regards

    EDIT:

    Some of the caps were missing so I added them and now the receiver doesn't crash but just idles without showing anything.

    Send: gst-launch-0.10 -v gstrtpbin name=rtpbin v4l2src device=/dev/video0 ! 'video/x-raw-yuv, width=(int)320, height=(int)240, framerate=(fraction)15/1' ! rtpvrawpay ! rtpbin.send_rtp_sink_0 rtpbin.send_rtp_src_0 ! multiudpsink clients="127.0.0.1:9996" rtpbin.send_rtcp_src_0 ! multiudpsink clients="127.0.0.1:9997" sync=false async=false udpsrc port=10000 ! rtpbin.recv_rtcp_sink_0

    Receive: gst-launch-0.10 -v gstrtpbin name=rtpbin udpsrc caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)RAW, sampling=(string)YCbCr-4:2:0, depth=(string)8, width=(string)320, height=(string)240, colorimetry=(string)SMPTE240M, ssrc=(uint)956768427, payload=(int)96, clock-base=(uint)1415613946, seqnum-base=(uint)35008" port=9996 ! rtpbin.recv_rtp_sink_0 rtpbin. ! rtpvrawdepay ! video/x-raw-yuv,framerate=15/1 ! xvimagesink udpsrc port=9997 ! rtpbin.recv_rtcp_sink_0 rtpbin.send_rtcp_src_0 ! multiudpsink clients="127.0.0.1:10000" sync=false async=false

  • alexandernst
    alexandernst over 11 years
    That worked exactly as I wanted! Thank you. <...> PS: Will it be hard to add audio too?
  • av501
    av501 over 11 years
    Not really. The same principle applies. I suggest you first create a seperate audio only pipeline. Then combine the two.