GStreamer In-Band Metadata for MPEG Transport Stream - User Guide

From RidgeRun Developer Wiki



Previous: Getting Started/Building the project Index Next: Examples





Adding metadata support to your application involves two main tasks: on the sending side injecting metadata on the pipeline and on the receiving side extracting the metadata. In this section, we will review how to achieve this.

To inject metadata, you create a GStreamer Buffer (now referred as gstbuf), set the timestamp, set the caps to meta/x-klv, copy your metadata into the buffer, and push the gstbuf to the metadata sink pad on the mpegtsmux element.

In order to make this easier, you can use RidgeRun's metasrc element. Once you have the pipeline with a metasrc element, you can simply set the metasrc metadata property with the data you want to inject. The metasrc element will create the gstbuf, set the timestamp and caps for you. You simply set the metadata property of the metasrc element to contain the data you want to send.

In python for instance, once the pipeline is created, you simply run:

metadata  = “arbitrary data here”
metasrc = self.pipeline.get_by_name(“metasrc")
metasrc.set_property(“metadata", metadata)

Muxing/demuxing the metadata

To extract the metadata, you branch out the demuxer to get the metadata's src_pad and set the caps to meta/x-klv. This pad will output the metadata in gstbuf from the mpegtsdemux element. A simple pipeline would be:

gst-launch-1.0 filesrc location=metadata.ts ! tsdemux ! meta/x-klv ! metasink -v

In this example, metadata.ts is a transport stream recording containing KLV metadata.

If the metadata needs to be injected into the TS mux, you can do it by specifying appropriate caps as follows:

gst-launch-1.0 metasrc metadata=%T period=1 ! meta/x-klv !  mpegtsmux name=mux ! filesink location=metadata.ts videotestsrc is-live=true ! queue ! x264enc ! mux. -v

In this example, the current time is injected with a period of 1s.

Synchronous metadata

Synchronous metadata follows the MISB ST 1402 standard. In order to properly multiplex the VLK packets, the stream_type field has to be added as part of caps as follows:

gst-launch-1.0 metasrc metadata=%T period=1 ! meta/x-klv,stream_type=21 !  mpegtsmux name=mux ! filesink location=metadata.ts videotestsrc is-live=true ! queue ! x264enc ! mux. -v

If no stream_type is specified, then the metadata will be asynchronous.

In the following section you will find more examples of how the metadata elements can be used.


Previous: Getting Started/Building the project Index Next: Examples