Building a gstreamer pipeline to cast directly in web browser

Hi,

I’m working on a project that requires streaming video output from a GStreamer pipeline to a web browser. I am looking into WebRTC as this seems to be the simplest solution to implement.

I want to build a GStreamer pipeline that passes the video output to the browser with WebRTC.

I’ve reviewed several GStreamer and WebRTC examples but I’m still struggling with creating a working end-to-end example or complete working chain.

If you have an example that works, configuration hints, or any other tips on how to connect GStreamer WebRTC elements to a browser client, I would appreciate the help.

Best regards

Joshua.

There are many such examples in subprojects/gst-examples/webrtc · main · GStreamer / gstreamer · GitLab that can show the flow negotiating with a browser peer. Particularly the sendrecv examples are useful for sending and receiving a stream to and from the browser.

Hello.

If all you want to do is stream h264 to the web browser you could use external software for the webrtc part. For example: go2rtc

It’s a standalone binary and handles all of the webrtc stuff. You can run gstreamer via go2rtc either directly or by splitting your pipeline in two and running one half in go2rtc and one separately and feeding into go2rtc via something like tcpserversink and tcpclientsrc (or the new unixfd if you’re on gst 1.26. I haven’t used this personally yet.) Running two pipelines performs better in my experience.

Example: Put this in either go2rtc.yaml or in the go2rtc webgui. Note! The -q (–quiet) flag on gst-launch-1.0 is mandatory!

streams:
  external: exec:gst-launch-1.0 -q tcpclientsrc host=0.0.0.0 port=3000 ! queue ! fdsink
  
  internal: exec:gst-launch-1.0 -q videotestsrc is-live=true pattern=ball ! video/x-raw,format=NV12,framerate=15/1 ! queue ! x264enc speed-preset=1 tune=zerolatency ! h264parse config-interval=-1 ! mpegtsmux ! queue ! fdsink

log:
  format: ""
  level: "trace"
  exec: "trace"

Run this in another terminal:

gst-launch-1.0 -v videotestsrc pattern=ball ! video/x-raw,format=NV12,framerate=15/1 ! queue ! x264enc speed-preset=1 tune=zerolatency ! queue ! h264parse config-interval=-1 ! mpegtsmux ! tcpserversink host=0.0.0.0 port=3000

go2rtc will immediately demux the mpegts into just h264 but having it in there anyway makes things work better IME.