GstRTMPMetadata examples Using Gstd

From RidgeRun Developer Wiki

Follow Us On Twitter LinkedIn Email Share this page






NVIDIA partner logo NXP partner logo




Inserting metadata and receiving a signal using gstd

The following example shows how to insert metadata and receive a signal using gstd with RidgeRun’s FLV/RTMP metadata patches. Make sure you have gstd installed and running.

Step 1 – Start the gstd daemon

Run the daemon in one terminal:

gstd -e

Step 2 – Start the gstd client

In another terminal, run:

gstd-client

Step 3 – Launch an RTMP server

You can use SRS in a container for a quick local RTMP endpoint:

docker run --rm -p 1935:1935 ossrs/srs

Step 4 – Create the sender pipeline

This pipeline injects metadata into the RTMP stream via the meta-string property:

pipeline_create sender videotestsrc is-live=true ! x264enc ! \
  video/x-h264,stream-format=avc,alignment=au ! \
  flvmux name=mux streamable=true meta-string="Hello RTMP Metadata" ! \
  rtmpsink location=rtmp://127.0.0.1/live/test

Step 5 – Create the receiver pipeline

The receiver enables both metadata extraction mechanisms:

  • attach-flvmeta=true: attaches metadata as GstMeta on outgoing buffers.
  • flv-meta-signal=true: emits a signal with the payload as GBytes.
pipeline_create receiver rtmpsrc location=rtmp://127.0.0.1/live/test ! \
  flvdemux attach-flvmeta=true flv-meta-signal=true name=extract ! \
  fakesink

Step 6 – Play the pipelines

Run both pipelines:

pipeline_play sender
pipeline_play receiver

Step 7 – Connect to the metadata signal

Now connect to the flv-meta signal:

signal_connect receiver extract flv-meta

The expected response is a JSON object indicating success and showing the flv-meta signal with its arguments (element + payload). The payload is delivered as a GBytes with the exact size and pointer varying at runtime.

Expected Output

When metadata is received, gstd will return a JSON object similar to:

{
  "code" : 0,
  "description" : "Success",
  "response" : {
    "name" : "flv-meta",
    "arguments" : [
        {
            "type" : "GstElement",
            "value" : "(GstFlvDemux) extract"
        },
        {
            "type" : "GBytes",
            "value" : "((GBytes) 0x7fdb9000fdc0, size=18)"
        }
    ]
  }
}

You should also see debug messages if GST_DEBUG=flv*:6,flvdemux:6,gstflv*:6 is enabled, for example:

0:00:00.468534452 121718 0x55a34b45a8c0 INFO                flvdemux gstflvdemux.c:499:gst_flv_demux_parse_metadata_item:<d> Meta-string: Hello RTMP Metadata

Extra example: Sending live metadata with gstd (two terminals)

This example demonstrates how to receive metadata even if it was not present at the beginning of the stream by changing the value on the fly.

Terminal 1 — create and start the pipelines

gstd-client

Inside the client:

# Create the sender with an initial meta-string
pipeline_create sender videotestsrc is-live=true ! x264enc ! \
  video/x-h264,stream-format=avc,alignment=au ! \
  flvmux name=mux streamable=true meta-string="Initial Metadata" ! \
  rtmpsink location=rtmp://127.0.0.1/live/test

# Create the receiver
pipeline_create receiver rtmpsrc location=rtmp://127.0.0.1/live/test ! \
  flvdemux attach-flvmeta=true flv-meta-signal=true name=extract ! \
  fakesink

# Start both pipelines
pipeline_play sender
pipeline_play receiver

Terminal 2 — connect to the signal

gstd-client

Inside the client:

signal_connect receiver extract flv-meta

Back to Terminal 1 — send dynamic metadata

property_set sender mux meta-string "Dynamic Metadata – Hello World"

You should immediately receive a flv-meta signal event in Terminal 2 with the new payload.