Skip to content

Instantly share code, notes, and snippets.

@esrever10
Last active February 7, 2024 10:26
Show Gist options
  • Star 48 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save esrever10/7d39fe2d4163c5b2d7006495c3c911bb to your computer and use it in GitHub Desktop.
Save esrever10/7d39fe2d4163c5b2d7006495c3c911bb to your computer and use it in GitHub Desktop.
gstreamer send and receive h264 rtp stream
# linux send h264 rtp stream:
gst-launch-1.0 -v ximagesrc ! video/x-raw,framerate=20/1 ! videoscale ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=superfast ! rtph264pay ! udpsink host=127.0.0.1 port=5000
# Macos send h264 rtp stream:
gst-launch-1.0 -v avfvideosrc capture-screen=true ! video/x-raw,framerate=20/1 ! videoscale ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=superfast ! rtph264pay ! udpsink host=127.0.0.1 port=5000
# receive h264 rtp stream:
gst-launch-1.0 -v udpsrc port=5000 caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! decodebin ! videoconvert ! autovideosink
@GudarJs
Copy link

GudarJs commented Jan 25, 2018

Hi, is there any way to check is the streaming its ok? maybe showing or saving the video?

@EricksonLu
Copy link

Hi, can you receive the stream by vlc? I can't , and i try to use sdp file receive the pipline, it does not work.

@kevinlieb
Copy link

sdp file for playing in vlc:
c=IN IP4 127.0.0.1
m=video 5000 RTP/AVP 96
a=rtpmap:96 H264/90000

This is rough and may be wrong: it worked but video was off-looking.

@kevinlieb
Copy link

Also to generate a stream with a test video instead of a screen capture in osx do:
gst-launch-1.0 -v videotestsrc ! video/x-raw,framerate=20/1 ! videoscale ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=superfast ! rtph264pay ! udpsink host=127.0.0.1 port=5000

@petetakacs
Copy link

Could you maybe give an example over tcp?

@anselmobattisti
Copy link

You generate a video appling videobalance saturation=0 "greyscale"
gst-launch-1.0 videotestsrc ! videobalance saturation=0 ! x264enc ! video/x-h264, stream-format=byte-stream ! rtph264pay ! udpsink host=127.0.0.1 port=5000

Consume it :)
gst-launch-1.0 udpsrc port=5000 ! application/x-rtp, encoding-name=H264, payload=96 ! rtph264depay ! h264parse ! avdec_h264 ! autovideosink

@anselmobattisti
Copy link

If you need to stream the video to another computer you need to change the host ip and it was what i was doing it wrongly!

The host is the machine tha will recive the stream and not where the place when the video is hosted 🐙 it's tooks me a lot of time to overlap it!

gst-launch-1.0 videotestsrc ! videobalance saturation=0 ! x264enc ! video/x-h264, stream-format=byte-stream ! rtph264pay ! udpsink host=SERVER_THAR_WILL_RECIVE_THE_VIDEO port=5000

sudo -E gst-launch-1.0 udpsrc port=5000 ! application/x-rtp, encoding-name=H264, payload=96 ! rtph264depay ! h264parse ! avdec_h264 ! autovideosink

@farshidbakh
Copy link

Hello All,

I need your help. On my computer I am receiving stream as UDPSRC on some port(port 5004) . I need to forward this from a different port to an end point that receives rstp streams. I am using the following:

udpsrc uri=udp://localhost:5004 ! application/x-rtp, encoding-name=H264, payload=96 ! rtph264depay ! h264parse ! avdec_h264 ! rtspclientsink location=rtsp://localhsot:5006/test

I even tried this:

udpsrc uri=udp://localhost:5004 ! rtspclientsink location=rtsp://localhsot:5006/test and didn't work.

But I cannot get it working. Anyone has any idea? what I am doing wrong. I am new to streaming. I am not sure if all these pipe are necessary or not. I would greatly appreciate your help.

I have this and works fine but I don't want to create .m3u8 files
udpsrc uri=udp://127.0.0.1:5004 ! application/x-rtp, payload=127 ! rtph264depay ! mpegtsmux ! hlssink max-files=10 playlist-root=http://127.0.0.1:8888/ location=./hlssink%05d.ts playlist-location=./wedpalylist.m3u8 "

Thanks,
Farshid

@farshidbakh
Copy link

BTW, I am getting connection refused message. I hope this helps.

@braindevices
Copy link

Is there any plugin can automatically generate sdp file?

@sajorn-warrior
Copy link

Hi guys I need to stream h264 streams from a udpsource on omxh264dec and sink it to wayland ... can someone please help

@randhawp
Copy link

Follow these steps to generate a sdp source
a) gstreamer source stream append a -v as follows

gst-launch-1.0 v4l2src device=/dev/video0  do-timestamp=true !
 video/x-raw,width=1280, height=800,framerate='(fraction)'20/1 ! autovideoconver
t  ! omxh264videoenc  !queue ! h264parse  config-interval=1 ! rtph264pay pt=96 !
  udpsink host=192.168.2.158 port=5000 sync=false -v

b) This will give verbose output like one below

debug  : cedarc <BitStreamCreate:102>: BitStreamCreate OK
/GstPipeline:pipeline0/GstH264Parse:h264parse0.GstPad:src: caps = video/x-h264, stream-format=(string)avc, alignment=(string)au, width=(int)1280, height=(int)800, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)20/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, chroma-format=(strin2
/GstPipeline:pipeline0/GstRtpH264Pay:rtph264pay0.GstPad:src: caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, packetization-mode=(string)1, profile-level-id=(string)4d0020, sprop-parameter-sets=(string)"Z00AIOVAKAMogA\=\=\,aO4xEg\=\=", payload=(int)96, ssrc0
/GstPipeline:pipeline0/GstUDPSink:udpsink0.GstPad:sink: **caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, packetization-mode=(string)1, profile-level-id=(string)4d0020, sprop-parameter-sets=(string)"Z00AIOVAKAMogA\=\=\,aO4xEg\=\=", payload=(int)96,** ssrc=(uin0
/GstPipeline:pipeline0/GstRtpH264Pay:rtph264pay0.GstPad:sink: caps = video/x-h264, stream-format=(string)avc, alignment=(string)au, width=(int)1280, height=(int)800, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)20/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, chroma-format=(st2
/GstPipeline:pipeline0/GstRtpH264Pay:rtph264pay0: timestamp = 3016666383

c) Use the information above to make your sdp file.
Example sdp file from above is

v=0
o=IP4 192.168.2.62
i=test
c=IN IP4 192.168.2.62
s=ESP H264 STREAM
m=video 5000 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 media=video; clock-rate=90000; encoding-name=H264; sprop-parameter-sets=Z00AIOVAKAMogA\=\=\,aO4xEg\=\=

d) Note that in the SDP file the IP address is that of the server. In the server gstreamer code, the IP address is that of the client

@sfahadshahzad
Copy link

can anyone help me to generate rtp stream using decklink video source ?

Fahad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment