Skip to content

Instantly share code, notes, and snippets.

@bmount
Last active November 14, 2021 16:20
Show Gist options
  • Save bmount/6cb201aa1a869bfdc0b3a4be49fa9c26 to your computer and use it in GitHub Desktop.
Save bmount/6cb201aa1a869bfdc0b3a4be49fa9c26 to your computer and use it in GitHub Desktop.
gstreamer udp rtsp

Snippets collected/distilled from gists/blog posts/etc. Combined here for fellow web-searchers -- goal is to have an easy/minimal sink for in-app use, and then forward that stream in another process.

Read camera, push to UDP sink (usually from appsrc, here v4l2 camera):

$ gst-launch-1.0 -vvvv v4l2src ! 'video/x-raw, width=640, height=480, framerate=30/1' ! videoconvert ! x264enc pass=qual quantizer=20 tune=zerolatency ! rtph264pay ! udpsink port=1234

Visualize above:

$ gst-launch-1.0 -vvv udpsrc port=1234 ! "application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264" ! rtph264depay ! h264parse ! decodebin ! videoconvert ! xvimagesink sync=false

Instead of preceding, read UDP stream and republish over network as RTSP stream, using https://github.com/GStreamer/gst-rtsp-server/blob/master/examples/test-launch.c (build: libtool --mode=link gcc `pkg-config --cflags --libs gstreamer-1.0` -L/usr/lib/x86_64-linux-gnu -lgstrtspserver-1.0 test-launch.c -o gst-rtsp-launch)

GST_DEBUG=1 ./bin/gst-rtsp-launch "udpsrc port=1234 ! application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! x264enc ! rtph264pay name=pay0 pt=96 "

Read RTSP stream:

$ gst-launch-1.0 -vvv rtspsrc location=rtsp://127.0.0.1:8554/test ! rtph264depay ! h264parse ! decodebin ! videoconvert ! xvimagesink sync=false

@ericsonj
Copy link

ericsonj commented Aug 5, 2021

Hi
thanks for the example.

How I can server many clients?

UDP -> RTSP -> CLIENT 1
    \> RTSP -> CLIENT 2

@bmount
Copy link
Author

bmount commented Aug 5, 2021

Hi EJ,

I haven't looked at this code in quite a while but I think the RTSP server can support multiple clients, I'd try (per your plot):

UDP -> RTSP -> CLIENT 1
            \> CLIENT 2

I just saw some bug reports that this fails on certain distributions of GStreamer (eg at least one version of Linux4Tegra), but I think it should work -- do you get any specific errors or unexpected behavior with this approach?

@ericsonj
Copy link

ericsonj commented Aug 6, 2021

Hi @bmount

Thanks you for your comment, I tried this:

UDP -> RTSP -> CLIENT 1
            \> CLIENT 2

But the first client stop the video when the second client start the video. I found that test-launch re play the pipeline for each user connected.

Test

udpsrc port=1234 ! application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! x264enc ! rtph264pay name=pay0 pt=96 

I think that the problem is that many pipeline can´t read the same UDP port.

Now I'm reading multiudpsink for try another option.

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