Ts mux/demux and KLVA

Hi,

I’m trying to mux an h264 and a KLV with mpegtsmux and receive the stream with tsdemux.

Actually it have to be compliant with the stanag MISB ST 0601.

I use an appsrc to inject the metadata buffer at 1Hz with this code found online (gstreamer-test-klv/klv-encode) by impleotv):

// For ASYNC_KLV, we need to remove timestamp and duration from the buffer
GST_BUFFER_PTS(buffer) = GST_CLOCK_TIME_NONE;
GST_BUFFER_DTS(buffer) = GST_CLOCK_TIME_NONE;
GST_BUFFER_DURATION(buffer) = GST_CLOCK_TIME_NONE;

GST_BUFFER_FLAG_SET(buffer, GST_STREAM_FLAG_SPARSE);

ret = gst_app_src_push_buffer((GstAppSrc*)m_appsrc, buffer);

The appsrc is configured this way:
appsrc name=klvappsrc is-live=1 do-timestamp=1 format=3 caps=\"meta/x-klv, stream-format=(string)klv, parsed=(bool)true, sparse=(bool)true\" ! videomuxer.sink_67

I want to send a KLV async so the video is not in sync with metadata.

The problem is that the tsdemux seems to sync the video with the metadata, so the video is stepping at 1Hz. If I send metadata at 30Hz the video stepping goes away.

Is this a well known problem/behavoir?

Thanks

I think the MPEG-TS muxer behaviour depends a bit on the exact version you’re using, and also if the demuxer operates in live mode or not.

The behaviour with regard to sparse metadata streams changed a bit over time if I remember correctly.

Some of the code in the snippet you pasted makes no sense (unless someone has custom patches on top of the official gstreamer), e.g.

  • GST_STREAM_FLAG_SPARSE is not a buffer flag and can’t be set on buffers. It’s sent as part of a stream-start event by the source element. I’m not sure off the top of my head if it’s possible to make appsrc do that, would have to check.
  • the sparse=(bool)true in the caps is not something that’s part of our KLV caps and will be ignored by the muxer (unless there are custom patches).

I read about some modification on ts mux/demux so I updated gstreamer to 1.28.

I copied the buffer flag stuff from internet.. :slight_smile:

I dont know if the buffer timestamp stuff is also wrong.