This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/AM5728: Encode pipeline issues

Part Number: AM5728


Tool/software: Linux

Hello,

I want to capture and encode with AM5728.I need to get resources from the appsink,and  here is my code:

#include <gst/gst.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include<glib.h>

#define FRAME_264 (1280*720)

int i=0;

typedef struct _CustomData {
GstElement *pipeline, *src, *convert, *text, *q1, *enc, *q2, *parse, *q3, *mux, *c1, *sink;

guint64 num_samples; /* Number of samples generated so far (for timestamp generation) */

guint sourceid; /* To control the GSource */

GMainLoop *main_loop; /* GLib's Main Loop */
} CustomData;
CustomData data;

FILE *pFile;
unsigned int *dataPtr = NULL;

static void new_sample (GstElement *sink, CustomData *data) {

printf("i2:%d\n",i);
GstSample *sample;
GstBuffer *buffer;
/* Retrieve the buffer */
g_signal_emit_by_name (sink, "pull-sample", &sample);
buffer = gst_sample_get_buffer (sample);
int size = gst_buffer_get_size (buffer);

if (buffer) {
/* The only thing we do in this example is print a * to indicate a received buffer */
//g_print ("*");
// i++;
gst_buffer_extract (buffer,0,dataPtr,size);
fwrite(dataPtr, sizeof(unsigned int), size, pFile);
gst_buffer_unref (buffer);
}
}

/* This function is called when an error message is posted on the bus */
static void error_cb (GstBus *bus, GstMessage *msg, CustomData *data) {
GError *err;
gchar *debug_info;

/* Print error details on the screen */
gst_message_parse_error (msg, &err, &debug_info);
g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);
g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");
g_clear_error (&err);
g_free (debug_info);

g_main_loop_quit (data->main_loop);
}

static gboolean link_source_element_with_filter(GstElement *element1,
GstElement *element2)

{
/* CAPS to be link:
* 'video/x-raw, format=(string)YUY2, width=(int)800, height=(int)600, framerate=5/1'
* */

gboolean link_ok;
GstCaps *caps;

caps = gst_caps_new_simple("video/x-raw",
"format", G_TYPE_STRING, "YUY2",
"width", G_TYPE_INT, 1280,
"height", G_TYPE_INT, 720,
"framerate", GST_TYPE_FRACTION, 30, 1,
NULL);

link_ok = gst_element_link_filtered(element1, element2, caps);
gst_caps_unref(caps);

if (!link_ok) {
g_warning("Failed to link element1 and element2!(v4l2src->convert)");
}
return link_ok;

}

void link_to_multiplexer(
GstElement *tolink_element,
GstElement *mux)
{
GstCaps *pad_caps = NULL;
GstPad *pad;
GstPad *tolink_pad;
GstPadLinkReturn ret;

tolink_pad = gst_element_get_static_pad(tolink_element, "src");
pad_caps = gst_pad_query_caps(tolink_pad, NULL);
pad = gst_element_get_compatible_pad(mux, tolink_pad, pad_caps);
gst_caps_unref(pad_caps);

ret = gst_pad_link(tolink_pad, pad);
if (ret==0)
g_print("aaa\n");
gst_object_unref(GST_OBJECT(pad));
g_print("A new pad %s was created and linked to %s\n", gst_pad_get_name(tolink_pad), gst_pad_get_name(pad));
}

gint counter = 10;
gboolean callback(gpointer arg)
{
g_print(".");
if(--counter ==0){
g_print("/n");
//退出循环
g_main_loop_quit(data.main_loop);
//注销定时器
return FALSE;
}
//定时器继续运行
return TRUE;
}

int main(int argc, char *argv[])
{
pFile=fopen("file.h264","wb+");

memset (&data, 0, sizeof (data));

dataPtr=(unsigned int*)malloc(sizeof(unsigned char) * FRAME_264);
memset(dataPtr,0,FRAME_264);

gst_init (&argc, &argv);

data.pipeline = gst_pipeline_new("test-pipeline");

data.src = gst_element_factory_make("v4l2src", "video_source");
g_object_set(G_OBJECT(data.src), "device", "/dev/video2", NULL);
g_object_set(G_OBJECT(data.src), "io-mode", 4, NULL);
g_object_set(G_OBJECT(data.src), "num-buffers", 2147483647, NULL);

data.text=gst_element_factory_make("textoverlay", "text");
g_object_set(G_OBJECT(data.text), "text", "afj", NULL);

data.convert = gst_element_factory_make("vpe", "convert");
g_object_set(G_OBJECT(data.convert), "num-input-buffers", 8, NULL);
data.q1 = gst_element_factory_make("queue", "q1");
data.enc = gst_element_factory_make("ducatih264enc", "enc");
//g_object_set(G_OBJECT(enc), "bitrate", 4000, NULL);
data.q2 = gst_element_factory_make("queue", "q2");
data.parse = gst_element_factory_make("h264parse", "parser");
data.q3 = gst_element_factory_make("queue", "q3");
data.mux = gst_element_factory_make("qtmux", "mux");
//data.c1 = gst_element_factory_make("vpe", "c1");
data.sink = gst_element_factory_make("appsink", "sink");
g_object_set (data.sink, "emit-signals", TRUE, NULL);
g_signal_connect (data.sink, "new-sample", G_CALLBACK (new_sample), &data);

gst_bin_add_many(GST_BIN(data.pipeline), data.src, data.convert, data.text, data.q1, data.enc, data.q2, data.parse, data.q3, data.mux, data.sink, NULL);//data.q2, data.parse, data.q3, data.mux,

link_source_element_with_filter(data.src, data.text);
link_source_element_with_filter(data.text, data.convert);

if (gst_element_link_pads(data.convert, "src", data.q1, "sink") != TRUE)
{
g_print("1\n");
}
if (gst_element_link_pads(data.q1, "src", data.enc, "sink") != TRUE)
{
g_print("2\n");
}
if (gst_element_link_pads(data.enc, "src", data.q2, "sink") != TRUE)
{
g_print("3\n");
}
if (gst_element_link_pads(data.q2, "src", data.parse, "sink") != TRUE)
{
g_print("4\n");
}
if (gst_element_link_pads(data.parse, "src", data.q3, "sink") != TRUE)
{
g_print("5\n");
}
link_to_multiplexer(data.q3, data.mux);
if (gst_element_link_pads(data.mux, "src", data.sink, "sink") != TRUE)
{
g_print("6\n");
}

GstBus *bus;
bus = gst_element_get_bus (data.pipeline);
gst_bus_add_signal_watch (bus);
g_signal_connect (G_OBJECT (bus), "message::error", (GCallback)error_cb, &data);
gst_object_unref (bus);

gst_element_set_state (data.pipeline, GST_STATE_PLAYING);

printf("i1:%d\n",i);
g_timeout_add(100,callback,NULL);

data.main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (data.main_loop);

printf("i3:%d\n",i);

gst_element_set_state (data.pipeline, GST_STATE_NULL);
gst_object_unref (data.pipeline);

return 0;
}

But I tried this code and it showed this problem:

So could u help me  or give me some advice ?

Thangks&regads!

  • Hello,

    I will check.

    BR
    Margarita
  • Hello,

    Please could you post the full debug log when you are executing the application?
    If you replace appsink element with fakesink or filesink is it working?
    I have suspicions that the error you are observing is for case mux->appsink only not in case mux->filesink.

    I would recommend you:
    Try to set qtmux's property streamable=true. I have suspicious that the generated file will be not valid.
    You could try to add seek support for appsink also.
    You could check this tutorial for appsink. There is an example also:
    gstreamer.freedesktop.org/.../pipeline-manipulation.html

    Hope this helps.

    BR
    Margarita
  • Hello,
    If I use the filesink ,it works.But I need to use the appsink to get data from the application.
    And I tried your advice (set qtmux's property streamable=true),but it showed the same problems.
    Here is the debug log :
    0:00:00.174394770 1223 0x148a60 WARN v4l2bufferpool gstv4l2bufferpool.c:748:gst_v4l2_buffer_pool_start:<video_source:pool:src> Uncertain or not enough buffers, enabling copy threshold
    .0:00:00.266806841 1223 0x148a60 WARN vpe gstvpebufferpool.c:466:gst_vpe_buffer_pool_import: Allocating a new input buffer index: 0/128, 0
    0:00:00.278054265 1223 0x145890 WARN bufferpool gstbufferpool.c:300:do_alloc_buffer:<vpebufferpool1> alloc function failed
    0:00:00.281741431 1223 0x148a60 WARN vpe gstvpebufferpool.c:466:gst_vpe_buffer_pool_import: Allocating a new input buffer index: 1/128, 1
    0:00:00.293842204 1223 0x145890 WARN bufferpool gstbufferpool.c:300:do_alloc_buffer:<vpebufferpool1> alloc function failed
    0:00:00.296479844 1223 0x148a60 WARN vpe gstvpebufferpool.c:466:gst_vpe_buffer_pool_import: Allocating a new input buffer index: 2/128, 0
    0:00:00.304164217 1223 0x145890 WARN bufferpool gstbufferpool.c:300:do_alloc_buffer:<vpebufferpool1> alloc function failed
    0:00:00.314441172 1223 0x145890 WARN bufferpool gstbufferpool.c:300:do_alloc_buffer:<vpebufferpool1> alloc function failed
    0:00:00.324658103 1223 0x145890 WARN bufferpool gstbufferpool.c:300:do_alloc_buffer:<vpebufferpool1> alloc function failed
    0:00:00.334865761 1223 0x145890 WARN bufferpool gstbufferpool.c:300:do_alloc_buffer:<vpebufferpool1> alloc function failed
    0:00:00.345073420 1223 0x145890 WARN bufferpool gstbufferpool.c:300:do_alloc_buffer:<vpebufferpool1> alloc function failed
    0:00:00.355282055 1223 0x145890 WARN bufferpool gstbufferpool.c:300:do_alloc_buffer:<vpebufferpool1> alloc function failed
    0:00:00.358885447 1223 0x148a60 WARN v4l2src gstv4l2src.c:862:gst_v4l2src_create:<video_source> lost frames detected: count = 2 - ts: 0:00:00.195721486
    0:00:00.361146676 1223 0x148a60 WARN vpe gstvpebufferpool.c:466:gst_vpe_buffer_pool_import: Allocating a new input buffer index: 3/128, 0
    .0:00:00.365578041 1223 0x145890 WARN bufferpool gstbufferpool.c:300:do_alloc_buffer:<vpebufferpool1> alloc function failed
    0:00:00.375942510 1223 0x145890 WARN bufferpool gstbufferpool.c:300:do_alloc_buffer:<vpebufferpool1> alloc function failed
    0:00:00.386075993 1223 0x145890 WARN bufferpool gstbufferpool.c:300:do_alloc_buffer:<vpebufferpool1> alloc function failed
    0:00:00.396348230 1223 0x145890 WARN bufferpool gstbufferpool.c:300:do_alloc_buffer:<vpebufferpool1> alloc function failed
    0:00:00.404950206 1223 0x148b20 WARN qtmux gstqtmux.c:2127:gst_qt_mux_start_file:<mux> error: Downstream is not seekable - will not be able to create a playable file
    Error received from element mux: Downstream is not seekable - will not be able to create a playable file
    Debugging information: ../../../gst-plugins-good-1.8.3/gst/isomp4/gstqtmux.c(2127): gst_qt_mux_start_file (): /GstPipeline:test-pipeline/GstQTMux:mux
    0:00:00.406991998 1223 0x145890 WARN bufferpool gstbufferpool.c:300:do_alloc_buffer:<vpebufferpool1> alloc function failed

    Thangks&regards!
  • Hello,

    Please check the tutorial in my previous post.
    I would recommend you to try to add seek support in your appsink.
    The qtmux and appsink are not TI elements so I would suggested to search over the net for similar issue.

    BR
    Margarita
  • Hello,

    You could check this code:
    github.com/.../x264encsample.cpp
    It could be in help.
    Here you could find some suggestions also:
    gstreamer-devel.narkive.com/.../mp4mux-appsink

    BR
    Margarita