Simple Examples

From RidgeRun Developer Wiki

Follow Us On Twitter LinkedIn Email Share this page









Simple video and audio streaming

1. Streaming with local relay

In order to use MoQ you need to connect with a relay server, the plugin elements depend on this, nevertheless the rrmoqbin element can launch a local relay server if specified, refer to Relay Managment for details. The following examples will use the local relay spawn by the rrmoqbin.

Single track video streaming

Sender and relay server (rrmoqbin):

gst-launch-1.0 rrmoqbin channel=test-video name=bin \
  sink_0::track-name=video \
  videotestsrc is-live=true ! videoconvert ! x264enc ! queue ! bin.sink_0

Receiver with rrmoqsrc, rrmoqsrc will create pad names based on the tracks available in the catalog and that you request by setting src.video where src is the name of the rrmoqsrc element:

gst-launch-1.0 rrmoqsrc relay-url=https://127.0.0.1:4443 channel=test-video name=src \
  src.video ! decodebin ! videoconvert ! autovideosink

Single track audio streaming

Sender and relay server (rrmoqbin):

gst-launch-1.0 rrmoqbin channel=test-audio name=bin \
  sink_0::track-name=audio \
  audiotestsrc is-live=true ! audioresample ! audioconvert ! voaacenc ! aacparse ! queue ! bin.sink_0

Receiver (rrmoqsrc):

gst-launch-1.0 rrmoqsrc relay-url=https://127.0.0.1:4443 channel=test-audio name=src \
  src.audio ! decodebin ! audioconvert ! autoaudiosink

2. Streaming with video with external relay

Setting an external relay

In the context of rrmoqbin and external relay means a relay server that is running outside of the rrmoqbin instance wether its running in the localhost or a different a server in a different device, depedens on the provided host address, for example local relays use localhost 127.0.0.1 or the device owns IP under certain network interface e.g 192.168.X.X. A relay-mode=local means that the rrmoqbin will create a instance of a relay lserver itself which only makes sense for the addresses mentioned before. In summary using relay-mode=external allows to connect to other relay server as publisher.

To set a relay server manually, you’ll need to clone the moq repository:

sudo apt install just # for ubuntu or install from https://github.com/casey/just
git clone git@github.com:moq-dev/moq.git -b moq-relay-v0.9.6
cd moq-relay
just relay

If you wanna set the relay accessible from other devices in the network update its listen address as shown in the following diff as example:

+++ b/rs/moq-relay/cfg/dev.toml
@@ -9,7 +9,7 @@ level = "debug"
 [server]
 # Listen for QUIC connections on UDP:4443
 # Sometimes IPv6 causes issues; try 127.0.0.1:4443 instead.
-listen = "[::]:4443"
+listen = "192.168.X.X:4443"

The following diagram shows the behavior based on the address:

Relay server accessibility
Relay server accessibility

Then you can set the external relay url in the rrmoqbin for an existing relay server (this can be either a relay server launched manually as explain or with another rrmoqbin):

gst-launch-1.0 rrmoqbin relay-mode=external \
  relay-server-host-addr=https://127.0.0.1:4443 \
  channel=test-video name=bin \
  sink_0::track-name=video \
  videotestsrc is-live=true ! videoconvert ! x264enc ! queue ! bin.sink_0

The receiver would the same as with the local relay streaming:

gst-launch-1.0 rrmoqsrc relay-url=https://127.0.0.1:4443 channel=test-video name=src \
  src.video ! decodebin ! videoconvert ! autovideosink

3. Streaming video with external relay and sink element

This example is very similar to example number 2, but directly using the rrmoqsink element:

gst-launch-1.0  videotestsrc is-live=true ! videoconvert ! x264enc ! h264parse ! queue ! \
  rrmoqsink relay-url=https://127.0.0.1:4443 channel=test-video track-name=video

The receiver would the same as with the local relay streaming:

gst-launch-1.0 rrmoqsrc relay-url=https://127.0.0.1:4443 channel=test-video name=src \
  src.video ! decodebin ! videoconvert ! autovideosink

4. Streaming video from file

The following example uses rrmoqsink to stream a .mp4 file, in this case we use this sample:

gst-launch-1.0 filesrc location=path/to/video ! qtdemux name=d \
  d.video_0 ! queue ! rrmoqsink relay-url=https://127.0.0.1:4443 channel=test-video track-name=video

Or you can use rrmoqbin as well (either local or external relay):

gst-launch-1.0 -v rrmoqbin relay-mode=external relay-server-host-addr=https://127.0.0.1:4443 channel=test-video name=bin \
  sink_0::track-name=video filesrc  location=path/to/video ! \
  qtdemux name=d d.video_0 ! queue ! bin.sink_0

The receiver would the same as point 2:

gst-launch-1.0 rrmoqsrc relay-url=https://127.0.0.1:4443 channel=test-video name=src \
  src.video ! decodebin ! videoconvert ! autovideosink

5. Streaming video and audio from file

For this we use the rrmoqbin single it can handle multiple streams into the same channel (with external relay):

gst-launch-1.0 -v \
  rrmoqbin relay-mode=external relay-server-host-addr=https://localhost:4443 name=moq channel=test \
    sink_0::track-name=video1 sink_0::channel=test sink_1::track-name=audio2 sink_1::channel=test  \
  filesrc location=path/to/video  ! qtdemux name=d  \
  d.video_0 ! queue ! moq.sink_0 \
  d.audio_0 ! queue ! moq.sink_1

Receive only the audio:

gst-launch-1.0 rrmoqsrc relay-url=https://127.0.0.1:4443 channel=test name=src \
  src.audio2 ! decodebin ! audioconvert ! autoaudiosink

Receive both the audio and video:

gst-launch-1.0 -v   rrmoqsrc name=src relay-url=https://localhost:4443 channel=test src.audio2 ! queue ! decodebin ! audioconvert ! autoaudiosink src.video1 ! queue ! decodebin ! videoconvert ! autovideosink

Stream video and audio each on a channel:

gst-launch-1.0 -v \
  rrmoqbin relay-mode=external relay-server-host-addr=https://localhost:4443 name=moq channel=test \
    sink_0::track-name=video sink_0::channel=test-video sink_1::track-name=audio sink_1::channel=test-audio  \
  filesrc location=path/to/video  ! qtdemux name=d  \
  d.video_0 ! queue ! moq.sink_0 \
  d.audio_0 ! queue ! moq.sink_1

Receive both video and audio on different channels:

gst-launch-1.0 -v \
  rrmoqsrc name=src relay-url=https://localhost:4443 channel=test-video \
    src.video1 ! queue ! decodebin ! videoconvert ! autovideosink \
  rrmoqsrc name=srcaudio relay-url=https://localhost:4443 channel=test-audio \
    srcaudio.audio2 ! queue ! decodebin ! audioconvert ! autoaudiosink

6. Saving video track to a file

Receive a video track with rrmoqsrc and save to a file:

gst-launch-1.0  \
  rrmoqsrc relay-url=http://localhost:4443 channel=test name=src \
  src.track ! queue ! h264parse  \
  ! video/x-h264,stream-format=avc,alignment=au \
  ! qtmux fragment-duration=1000  \
  ! filesink location=out.mp4