GstRTMPMetadata examples using Gstd
The GstRTMPMetadata documentation from RidgeRun is presently being developed. |
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.
Important: We will use two separate terminals:
- Terminal 1 will control the pipelines (sender and receiver).
- Terminal 2 will listen for the flv-meta signal.
This separation makes it easier to see that the metadata is only delivered when it is sent.
Step 1 – Start the gstd daemon
Run the daemon in one terminal:
gstd -e
Step 2 – Start the gstd client (Terminal 1)
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 (Terminal 1)
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 (Terminal 1)
The receiver enables both metadata extraction mechanisms:
attach-flvmeta=true: attaches metadata asGstMetaon outgoing buffers.flv-meta-signal=true: emits a signal with the payload asGBytes.
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 – Connect to the metadata signal (Terminal 2)
Now connect to the flv-meta signal:
signal_connect receiver extract flv-meta
Step 7 – Play the pipelines (Terminal 1)
Run both pipelines:
pipeline_play sender pipeline_play receiver
Important: At this moment the metadata is injected immediately. If Terminal 2 is already listening, it will display the event right away. If not, nothing else will be printed later, unless you update the metadata dynamically.
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.
Important: We will use two separate terminals:
- Terminal 1 will control the pipelines (sender and receiver).
- Terminal 2 will listen for the flv-meta signal.
This separation makes it easier to see that the metadata is only delivered when it is sent.
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
Important: At this point, the initial metadata is injected when the sender starts. If Terminal 2 is already connected, you will see it immediately. If not, nothing else will appear until new metadata is sent.
Terminal 2 — connect to the signal
gstd-client
Inside the client:
signal_connect receiver extract flv-meta
Important: Now Terminal 2 is waiting for flv-meta events. At this moment nothing happens, since no new metadata has been sent yet.
Back to Terminal 1 — send dynamic metadata
property_set sender mux meta-string "Dynamic Metadata – Hello World"
Expected Output in Terminal 2
When the property is updated, the receiver immediately emits a new signal. You should see output similar to:
{
"code" : 0,
"description" : "Success",
"response" : {
"name" : "flv-meta",
"arguments" : [
{
"type" : "GstElement",
"value" : "(GstFlvDemux) extract"
},
{
"type" : "GBytes",
"value" : "((GBytes) 0x7fdb9000fdc0, size=26)"
}
]
}
}
With debug enabled, you should also see a message like:
0:00:10.235 ... INFO flvdemux gstflvdemux.c:499:gst_flv_demux_parse_metadata_item:<d> Meta-string: Dynamic Metadata – Hello World