Problem with appsrc-x264enc-appsink

Valentine luluvwdcastagnette at hotmail.fr
Wed Jul 18 12:46:17 UTC 2018


*Hi, 

When I try the following script, it does not work : the sample of appsink is
empty. Nevertheless, when I link "videotestsrc" to
"videoconvert-x264enc-appsink" directly, it works and when I connect
"appsrc" to "appsink" direcly, it works too... What is the problem ? Thank
you.*

gst_init(NULL,NULL);

    GstElement *pipeline2;
    pipeline2 = gst_pipeline_new("pipeline");
    GstElement *appsink2;
    appsink2 = gst_element_factory_make("appsink", "BufferSink2");
    GstElement *videotestsrc = gst_element_factory_make("videotestsrc",
"source");
    g_object_set(G_OBJECT(videotestsrc), "num-buffers", 1, NULL);
    gst_bin_add_many(GST_BIN(pipeline2), videotestsrc, appsink2, NULL);
    GstCaps *caps2 = gst_caps_new_simple("video/x-raw", "format",
G_TYPE_STRING, "GRAY8", "width", G_TYPE_INT, 100, "height", G_TYPE_INT, 100,
NULL);
    gst_element_link_filtered(videotestsrc, appsink2, caps2);
    GstStateChangeReturn retPip2 = gst_element_set_state(pipeline2,
GST_STATE_PLAYING);

    GstSample *sample2 = gst_app_sink_pull_sample (GST_APP_SINK(appsink2));
    GstBuffer *buffer2= gst_sample_get_buffer(sample2);
    GstMapInfo map2;
    gst_buffer_map(buffer2, &map2, GST_MAP_READ);
    uchar source[map2.size];
    memmove(source, map2.data, map2.size);


    ////////

    int size = map2.size;
    GstFlowReturn ret;
    GstElement *appsrc;
    appsrc = gst_element_factory_make("appsrc", "appsrc");
    g_object_set(G_OBJECT(appsrc), "blocksize", size, NULL);
    g_object_set(G_OBJECT(appsrc), "num-buffers", 1, NULL);

    GstBuffer *buffer;
    buffer = gst_buffer_new_allocate(NULL,size, NULL);
    GstMapInfo map;
    gst_buffer_map(buffer, &map, GST_MAP_WRITE);
    uchar *buf = map.data;
    memcpy(buf, source, size);
    ret = gst_app_src_push_buffer(GST_APP_SRC(appsrc), buffer);

    g_object_set(G_OBJECT(appsrc), "caps",
gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "GRAY8",
"width", G_TYPE_INT, 100, "height", G_TYPE_INT, 100, NULL), NULL);
    //g_object_set(G_OBJECT(appsrc), "stream-type", 0, "format", 3, "size",
size, NULL);


    GstCaps *cap_appsrc_to_x264enc;
    cap_appsrc_to_x264enc = gst_caps_new_simple("video/x-raw", "format",
G_TYPE_STRING, "GRAY8", "width", G_TYPE_INT, 100, "height", G_TYPE_INT, 100,
NULL);

    GstCaps *cap_x264enc_to_sink;
    cap_x264enc_to_sink = gst_caps_new_simple("video/x-h264", "profile",
G_TYPE_STRING, "main", NULL);

    GstElement *x264enc = gst_element_factory_make("x264enc", "encoder");

    g_object_set(G_OBJECT(x264enc), "qp-max", 20, NULL);


    g_object_set(G_OBJECT(x264enc), "pass", 17, NULL); // VBR Pass 1

    g_object_set(G_OBJECT(x264enc), "bitrate", 2000, NULL);

    GstCaps *caps;
    caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING,
"I420", NULL);

    GstElement *appsink;
    appsink = gst_element_factory_make("appsink", "BufferSink");

    GstElement *convert = gst_element_factory_make("videoconvert",
"convert");

    GstElement *pipeline;
    pipeline = gst_pipeline_new("pipeline");


    gst_bin_add_many(GST_BIN(pipeline), appsrc, convert, x264enc, appsink,
NULL);
    gst_element_link_filtered(appsrc, convert, cap_appsrc_to_x264enc);
    gst_element_link_filtered(convert, x264enc, caps);
    gst_element_link_filtered(x264enc,appsink, cap_x264enc_to_sink);

    GstStateChangeReturn retPip = gst_element_set_state(pipeline,
GST_STATE_PLAYING);


    GstSample *sample = gst_app_sink_pull_sample (GST_APP_SINK(appsink));
    GstBuffer *encBuffer= gst_sample_get_buffer(sample);
    gsize senc = gst_buffer_get_size (encBuffer);
    GstMapInfo mapEnc;
    gst_buffer_map(encBuffer, &mapEnc, GST_MAP_READ);
    uchar pRet[mapEnc.size];
    printf("%d\n", mapEnc.size);
    memmove(pRet, mapEnc.data, mapEnc.size);





--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/


More information about the gstreamer-devel mailing list