Embed klv into mpegts

a.vasiliev at geoscan.aero a.vasiliev at geoscan.aero
Mon Dec 14 02:38:03 PST 2015


Hello!

How to embed klv into mpegts stream? I try to link appsrc to mpegtsmux and push parsed klv data to the appsrc. But the stream bacame broken and can't find klv data on the output.

This is the pipeline in which i want to embed klv data. It works well.
gst-launch-1.0 v4l2src input-src=Camera ! videorate drop-only=true  ! 'video/x-raw, format=(string)NV12, width=1920, height=1088, framerate=25/1' ! ce_h264enc target-bitrate=6000000 idrinterval=25 intraframe-interval=60 ! queue ! mpegtsmux alignment=7 ! filesink location=v.ts

This is how i create apsrc and link it to this pipeline.
main()
{
...
GstElement *appSrc = gst_element_factory_make("appsrc", nullptr);
gst_app_src_set_caps (GST_APP_SRC (appSrc),  gst_caps_new_simple("meta/x-klv", "parsed", G_TYPE_BOOLEAN, TRUE, nullptr));
g_object_set(appSrc, "format", GST_FORMAT_TIME, nullptr);

gst_bin_add(GST_BIN(pipeline), appSrc);
gst_element_link(appSrc, mpegtsmux);

g_signal_connect (appSrc, "need-data", G_CALLBACK (need_data), userData);

gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING);
pipeline->startMainLoop();
...
}

void need_data(GstElement* element, guint, gpointer userData)
{
    AppSrc *appsrc = (AppSrc *) userData;
    GstBuffer *buffer = gst_buffer_new();
    GstMapInfo map;
    std::string data;
    guint8 empty = '\x0';

    appsrc->mutex.lock();
    while (!appsrc->queue.empty())
    {
        data.append(appsrc->queue.front());
        appsrc->queue.pop();
    }
    appsrc->mutex.unlock();

    gst_buffer_map (buffer, &map, GST_MAP_WRITE);
    if(!data.empty())
    {

        map.data = (guint8*)g_memdup(data.data(), data.size());
        map.size = data.size();
    }
    else
    {
        map.data = ∅
        map.size = 1;
    }
    gst_buffer_unmap (buffer, &map);
    GST_BUFFER_TIMESTAMP (buffer) = appsrc->timestamp;
    GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale_int (1, GST_SECOND, 1);

    appsrc->timestamp += GST_BUFFER_DURATION (buffer);

    gst_app_src_push_buffer(GST_APP_SRC(element), buffer);

}

Gstreamer Version is 1.6.1.


More information about the gstreamer-devel mailing list