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: GStreamer H.264 encoder issues

Part Number: AM5728


Tool/software: Linux

Hello,

I want to capture and encode a video with the AM5728 EVM using sdk 4.01

Here is my code :

#include <stdio.h>
#include <gst/gst.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include<glib.h> 
#define FRAME_264  (1280*720)
#include <sys/time.h> 
/*
��·ͨ�������źſ�ʼͬʱ�ɼ����룬��������������룬���Բ�ͬ�ļ������� 
 
*/ 
FILE *pFile[4];
unsigned int *dataPtr = NULL;

GstElement *pipeline[6];
GstBus *bus[6];
GstMessage *msg[6];

GstElement *src, *video_queue, *video_convert, *q1, *video_enc, *parse, *q3, *mux, *video_sink;
GstElement *tee, *pic_queue, *pic_convert, *q2, *pic_enc, *pic_sink;
GstPad *tee_video_pad, *tee_picture_pad;
GstPad *queue_video_pad, *queue_picture_pad;

static int i=0;
static void new_sample (GstElement *sink) { 	
	GstSample *sample = NULL;
	GstBuffer *buffer = NULL;
  /* Retrieve the buffer */
  	g_signal_emit_by_name (pic_sink, "pull-sample", &sample);
  	buffer = gst_sample_get_buffer (sample);
  	int size = gst_buffer_get_size (buffer);
  	
	i++;
	g_print("i:%d\n",i);
	if (i>50)
	{
		i=0;
  		if (buffer) {
  			FILE *fp = NULL;
    			//fp = fopen("/opt/image/deviceid/tunnel_1/image.jpg","wb+");
    			fp = fopen("image.jpg","wb+");
    			gst_buffer_extract (buffer,0,dataPtr,size);
    			fwrite(dataPtr, sizeof(unsigned int), size, fp);
			gst_buffer_unref (buffer);
	 		fclose(fp); 
   			fp = NULL;
			g_print("have buffer!");
			//system("/opt/uploadoss/main image deviceid tunnel_1 image.jpg"); 
  		} 
	}
	else
	{
		gst_buffer_unref (buffer);
	} 
	//gst_sample_unref(sample);	
	sample = NULL;
	buffer = NULL;
}

static gboolean link_source_element_with_filter(GstElement *element1,
	GstElement *element2, int width, int height, int framerate)

{
	/* 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, width,
		"height", G_TYPE_INT, height,
		"framerate", GST_TYPE_FRACTION, framerate, 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));
}


/* Main function does atual processing */

void record_start(int channel, char * filename)

//gst-launch-1.0 -e videotestsrc ! 'video/x-raw, format=(string)NV12, width=(int)1280, height=(int)720, framerate=(fraction)30/1' ! vpe num-input-buffers=8 ! queue ! ducatih264enc bitrate=4000 ! queue ! h264parse ! qtmux ! filesink location=x.mov
{
//	GstElement *src, *video_queue, *video_convert, *q1, *video_enc, *parse, *q3, *mux, *video_sink;
//	GstElement *tee, *pic_queue, *pic_convert, *pic_enc, *pic_sink; 
  	
	gst_init(NULL, NULL);

	/* Create the empty pipeline */
	pipeline[channel] = gst_pipeline_new("test-pipeline");

	/* Create the elements */
	src = gst_element_factory_make("v4l2src", "video_source");
	g_object_set(G_OBJECT(src), "device", "/dev/video1", NULL);
	g_object_set(G_OBJECT(src), "io-mode", 4, NULL);
	g_object_set(G_OBJECT(src), "num-buffers", -1, NULL);
	/*
	src = gst_element_factory_make("videotestsrc", "video_source");
	g_object_set(G_OBJECT(src), "num-buffers", -1, NULL);
        */
	video_convert = gst_element_factory_make("vpe", "video_convert");
	g_object_set(G_OBJECT(video_convert), "num-input-buffers", 8, NULL);
	q1 = gst_element_factory_make("queue", "q1");
	video_enc = gst_element_factory_make("ducatih264enc", "video_enc");
	g_object_set(G_OBJECT(video_enc), "profile", 100, NULL);//10000��������⣿�� 
	g_object_set(G_OBJECT(video_enc), "level", 41, NULL);//10000��������⣿�� 
	g_object_set(G_OBJECT(video_enc), "bitrate", 10000, NULL);//10000��������⣿�� 
	
	parse = gst_element_factory_make("h264parse", "parser");
	q3 = gst_element_factory_make("queue", "q3");
	mux = gst_element_factory_make("avimux", "mux");
	video_sink = gst_element_factory_make("filesink", "video_sink");
	g_object_set(G_OBJECT(video_sink), "location", filename, NULL);
	q2 = gst_element_factory_make("queue", "q2");
	tee = gst_element_factory_make ("tee", "tee");
	video_queue =gst_element_factory_make("queue","video_queue"); 
	pic_queue = gst_element_factory_make("queue","pic_queue"); 
	pic_convert = gst_element_factory_make("vpe", "pic_convert");
	g_object_set(G_OBJECT(pic_convert), "num-input-buffers", 8, NULL);
	
	pic_enc = gst_element_factory_make("ducatijpegenc", "pic_enc");
	//g_object_set (pic_enc, "intra-interval", 100, NULL);
	pic_sink = gst_element_factory_make("appsink", "pic_sink");
	g_object_set (pic_sink, "emit-signals", TRUE, NULL);
  	g_signal_connect (pic_sink, "new-sample", G_CALLBACK (new_sample), NULL); 
	

	gst_bin_add_many(GST_BIN(pipeline[channel]), src, tee, video_queue, video_convert, q1, video_enc, parse, q3, mux, video_sink, pic_queue, pic_convert, q2,pic_enc, pic_sink, NULL);
  	
	tee_video_pad = gst_element_get_request_pad (tee, "src_%u");
  	g_print ("Obtained request pad %s for video branch.\n", gst_pad_get_name (tee_video_pad));
  	queue_video_pad = gst_element_get_static_pad (video_queue, "sink");
  	tee_picture_pad = gst_element_get_request_pad (tee, "src_%u");
  	g_print ("Obtained request pad %s for picture branch.\n", gst_pad_get_name (tee_picture_pad));
  	queue_picture_pad = gst_element_get_static_pad (pic_queue, "sink");
  	
  	if (gst_pad_link (tee_picture_pad, queue_picture_pad) != GST_PAD_LINK_OK ||
      gst_pad_link (tee_video_pad, queue_video_pad) != GST_PAD_LINK_OK) {
    g_printerr ("Tee could not be linked.\n");
    gst_object_unref (pipeline);
  	}
	  
  	if (gst_element_link_many (src, tee, NULL) != TRUE)
  	{
	  	g_printerr ("src and tee could not be linked.\n");
  	}
  	
  	link_source_element_with_filter(video_queue, video_convert, 1280, 720, 30);
  		if (gst_element_link_pads(video_convert, "src", q1, "sink") != TRUE)
	{
		g_print("1\n");
	}
	if (gst_element_link_pads(q1, "src", video_enc, "sink") != TRUE)
	{
		g_print("2\n");
	}
	if (gst_element_link_pads(video_enc, "src", parse, "sink") != TRUE)
	{
		g_print("3\n");
	}
	if (gst_element_link_pads(parse, "src", q3, "sink") != TRUE)
	{
		g_print("4\n");
	}
	link_to_multiplexer(q3, mux);
	if (gst_element_link_pads(mux, "src", video_sink, "sink") != TRUE)
	{
		g_print("5\n");
	}
  	
  	link_source_element_with_filter(pic_queue, pic_convert, 1280, 720, 30);
	
	if(gst_element_link_pads(pic_convert, "src", q2, "sink")!= TRUE)
	{
		g_print("6\n");
	}
	if(gst_element_link_pads(q2, "src", pic_enc, "sink")!= TRUE)
	{
		g_print("66\n");
	}
	if(gst_element_link_pads(pic_enc, "src", pic_sink, "sink")!= TRUE)
	{
		g_print("7\n");
	}
  
	gst_object_unref (queue_picture_pad);
  	gst_object_unref (queue_video_pad);
	
	gst_element_set_state(pipeline[channel], GST_STATE_PLAYING);	
}

void record_stop(int channel)
{

 	gst_element_send_event(pipeline[channel],gst_event_new_eos()); 	
	/* Wait until error or EOS */
	bus[channel] = gst_element_get_bus(pipeline[channel]);
	msg[channel] = gst_bus_timed_pop_filtered(bus[channel], GST_CLOCK_TIME_NONE , GST_MESSAGE_ERROR | GST_MESSAGE_EOS);//GST_CLOCK_TIME_NONE
	
 	gst_element_release_request_pad (tee, tee_picture_pad);
  	gst_element_release_request_pad (tee, tee_video_pad);
  	gst_object_unref (tee_picture_pad);
  	gst_object_unref (tee_video_pad);
  
	if (msg[channel] != NULL)
	{
		gst_message_unref(msg[channel]);
	}


	gst_object_unref(bus[channel]);
	
	gst_element_set_state(pipeline[channel], GST_STATE_PAUSED);
	gst_element_set_state(pipeline[channel], GST_STATE_READY);
	gst_element_set_state(pipeline[channel], GST_STATE_NULL);
	gst_object_unref(pipeline[channel]);
}

void main()
{
    dataPtr=(unsigned int*)malloc(sizeof(unsigned int) * FRAME_264);
    memset(dataPtr,0,FRAME_264);
    
	record_start(0, "ch0.avi");
	sleep(50);
	record_stop(0);
	free(dataPtr);
	dataPtr = NULL;
}

And it always encountered a problem:

** (video_picture:1261): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

** (video_picture:1261): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

** (video_picture:1261): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

** (video_picture:1261): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

** (video_picture:1261): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

Could u give me some advice of my code?

And I have asked the question in this website:

But after tring the advice u gave before,I have not solved the problem.

So could give me some advice about the problem.

Thanks&regards!

  • Hello,

    hsg said:

    And it always encountered a problem:

    ** (video_picture:1261): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

    ** (video_picture:1261): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

    ** (video_picture:1261): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

    ** (video_picture:1261): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

    ** (video_picture:1261): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed


    I check your application and it seems that you are running capture pipeline with two encoding branches right?

    I ran similar pipeline:

    root@am57xx-evm:~# gst-launch-1.0 v4l2src device=/dev/video1  io-mode=4 ! 'video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720,framerate=(fraction)30/1' ! tee name=t ! vpe num-input-buffers=8  ! queue ! ducatih264enc ! h264parse ! avimux ! filesink location=1.avi t. !  vpe num-input-buffers=8 ! queue ! ducatih264enc ! h264parse ! fakesink
    Setting pipeline to PAUSED ...
    Pipeline is live and does not need PREROLL ...
    Setting pipeline to PLAYING ...
    New clock: GstSystemClock
    ^Chandling interrupt.
    Interrupt: Stopping pipeline ...
    Execution ended after 0:17:31.032645098
    Setting pipeline to PAUSED ...
    Setting pipeline to READY ...
    Setting pipeline to NULL ...
    Freeing pipeline ...
    root@am57xx-evm:~#

    for 17 mins I do not observe this error.

    How much time I should wait?

    I will check your code also.


    BR
    Margarita

  • Hello,
    Thank u for your fast reply.
    And I tried your pipeline,it did not have any problem.
    emmmm,17 mins are enough.
    And I tested this pipeline which is much similar as my pipeline in my app:
    its output was:
    gst-launch-1.0 v4l2src device=/dev/video1 io-mode=4 ! tee name=t ! queue ! 'video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720,framerate=(fraction)30/1' ! vpe num-input-buffers=8 ! queue ! ducatih264enc bitrate=10000 ! h264parse ! avimux ! filesink location=1.avi t. ! queue ! 'video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720,framerate=(fraction)30/1' ! vpe num-input-buffers=8 ! queue ! ducatijpegenc ! fakesink
    Setting pipeline to PAUSED ...
    Pipeline is live and does not need PREROLL ...
    Setting pipeline to PLAYING ...
    New clock: GstSystemClock

    ** (gst-launch-1.0:1536): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

    ** (gst-launch-1.0:1536): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

    ** (gst-launch-1.0:1536): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

    ** (gst-launch-1.0:1536): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

    ** (gst-launch-1.0:1536): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

    ** (gst-launch-1.0:1536): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed
    ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data flow error.
    Additional debug info:
    ../../../../gstreamer-1.8.3/libs/gst/base/gstbasesrc.c(2948): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
    streaming task paused, reason error (-5)
    Execution ended after 0:00:41.331333937

    But this phenomenon sometimes appears.

    Maybe it was the tee element influenced the pipeline.What's your opinion?
    And it is so appreciate for your help to my app's error.

    Thanks&regards!
  • Hello,
    I forgot to tell u when I replace the "vpe" plugin with "videoconvert" in my app.It did not have this problem.But the output video palyed faster than it should be. So I must using the vpe plugin to achieve my function.
    BR
    Hsg
  • Hello,

    hsg said:
    gst-launch-1.0 v4l2src device=/dev/video1 io-mode=4 ! tee name=t ! queue ! 'video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720,framerate=(fraction)30/1' ! vpe num-input-buffers=8 ! queue ! ducatih264enc bitrate=10000 ! h264parse ! avimux ! filesink location=1.avi t. ! queue ! 'video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720,framerate=(fraction)30/1' ! vpe num-input-buffers=8 ! queue ! ducatijpegenc ! fakesink

    The tee element can not be before the caps filter. However, I tried, it fails after 34 secs.

    The pipeline should be :

    root@am57xx-evm:~# gst-launch-1.0 v4l2src device=/dev/video1  io-mode=4 ! 'video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720,framerate=(fraction)30/1' ! tee name=t ! vpe num-input-buffers=8  ! queue ! ducatih264enc ! h264parse ! avimux ! filesink location=1.avi t. !  vpe num-input-buffers=8 ! queue ! ducatih264enc ! h264parse ! fakesink
    Setting pipeline to PAUSED ...
    [ 5097.568994] omap-iommu 55082000.mmu: 55082000.mmu: version 2.1
    Pipeline is live and does not need PREROLL ...
    Setting pipeline to PLAYING ...
    New clock: GstSystemClock
    ^Chandling interrupt.
    Interrupt: Stopping pipeline ...
    Execution ended after 0:52:09.810355109
    Setting pipeline to PAUSED ...
    Setting pipeline to READY ...
    Setting pipeline to NULL ...
    Freeing pipeline ...
    root@am57xx-evm:~#

    I ran it for almost an hour.

    BR
    Margarita

  • Hello,

    I tiried the pipeline which was more similar as my app.It failed after 5mins.

    gst-launch-1.0 v4l2src device=/dev/video1 io-mode=4 ! tee name=t ! queue ! 'video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720,framerate=(fraction)30/1' ! vpe num-input-buffers=8 ! queue ! ducatih264enc bitrate=10000 ! h264parse ! avimux ! filesink location=1.avi t. ! queue ! 'video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720,framerate=(fraction)30/1' ! vpe num-input-buffers=8 ! queue ! ducatijpegenc ! fakesink

    And I have changed my pipeline in my app.Here is my app which based on the similar pipeline.However,i had the same problem.Is that I should change thesize of the cma pool.And I have add this into the uEnv.txt :"console=ttyO2,115200n8 root=PARTUUID=000e27fb-02 rw cma=128MiB rootfstype=ext4 rootwait root=PARTUUID=000e27fb-02 rw rootfstype=ext4 rootwait"

    #include <stdio.h>
    #include <gst/gst.h>
    #include <time.h>
    #include <string.h>
    #include <stdlib.h>
    #include<glib.h> 
    #define FRAME_264  (1280*720)
    #include <sys/time.h> 
    /*
    ��·ͨ�������źſ�ʼͬʱ�ɼ����룬��������������룬���Բ�ͬ�ļ������� 
     
    */ 
    FILE *pFile[4];
    unsigned int *dataPtr = NULL;
    
    GstElement *pipeline[6];
    GstBus *bus[6];
    GstMessage *msg[6];
    
    GstElement *src, *srcqueue, *video_queue, *video_convert, *q1, *video_enc, *parse, *q3, *mux, *video_sink;
    GstElement *tee, *teequeue, *pic_queue, *pic_convert, *q2, *pic_enc, *pic_sink;
    GstPad *tee_video_pad, *tee_picture_pad;
    GstPad *queue_video_pad, *queue_picture_pad;
    
    static int i=0;
    static void new_sample (GstElement *sink) { 	
    	GstSample *sample = NULL;
    	GstBuffer *buffer = NULL;
      /* Retrieve the buffer */
      	g_signal_emit_by_name (pic_sink, "pull-sample", &sample);
      	buffer = gst_sample_get_buffer (sample);
      	int size = gst_buffer_get_size (buffer);
      	
    	i++;
    	g_print("i:%d\n",i);
    	if (i>50)
    	{
    		i=0;
      		if (buffer) {
      			FILE *fp = NULL;
        			//fp = fopen("/opt/image/deviceid/tunnel_1/image.jpg","wb+");
        			fp = fopen("image.jpg","wb+");
        			gst_buffer_extract (buffer,0,dataPtr,size);
        			fwrite(dataPtr, sizeof(unsigned int), size, fp);
    			gst_buffer_unref (buffer);
    	 		fclose(fp); 
       			fp = NULL;
    			g_print("have buffer!");
    			//system("/opt/uploadoss/main image deviceid tunnel_1 image.jpg"); 
      		} 
    	}
    	else
    	{
    		gst_buffer_unref (buffer);
    	} 
    	//gst_sample_unref(sample);	
    	sample = NULL;
    	buffer = NULL;
    }
    
    static gboolean link_source_element_with_filter(GstElement *element1,
    	GstElement *element2, int width, int height, int framerate)
    
    {
    	/* 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, width,
    		"height", G_TYPE_INT, height,
    		"framerate", GST_TYPE_FRACTION, framerate, 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));
    }
    
    
    /* Main function does atual processing */
    
    void record_start(int channel, char * filename)
    
    //gst-launch-1.0 -e videotestsrc ! 'video/x-raw, format=(string)NV12, width=(int)1280, height=(int)720, framerate=(fraction)30/1' ! vpe num-input-buffers=8 ! queue ! ducatih264enc bitrate=4000 ! queue ! h264parse ! qtmux ! filesink location=x.mov
    {
    //	GstElement *src, *video_queue, *video_convert, *q1, *video_enc, *parse, *q3, *mux, *video_sink;
    //	GstElement *tee, *pic_queue, *pic_convert, *pic_enc, *pic_sink; 
      	
    	gst_init(NULL, NULL);
    
    	/* Create the empty pipeline */
    	pipeline[channel] = gst_pipeline_new("test-pipeline");
    
    	/* Create the elements */
    	src = gst_element_factory_make("v4l2src", "video_source");
    	g_object_set(G_OBJECT(src), "device", "/dev/video1", NULL);
    	g_object_set(G_OBJECT(src), "io-mode", 4, NULL);
    	g_object_set(G_OBJECT(src), "num-buffers", -1, NULL);
    	/*
    	src = gst_element_factory_make("videotestsrc", "video_source");
    	g_object_set(G_OBJECT(src), "num-buffers", -1, NULL);
            */
    	video_convert = gst_element_factory_make("vpe", "video_convert");
    	g_object_set(G_OBJECT(video_convert), "num-input-buffers", 8, NULL);
    	q1 = gst_element_factory_make("queue", "q1");
    	srcqueue = gst_element_factory_make("queue", "srcqueue");
    	teequeue = gst_element_factory_make("queue", "teequeue");
    	video_enc = gst_element_factory_make("ducatih264enc", "video_enc");
    	//g_object_set(G_OBJECT(video_enc), "profile", 100, NULL);//10000��������⣿�� 
    	//g_object_set(G_OBJECT(video_enc), "level", 41, NULL);//10000��������⣿�� 
    	g_object_set(G_OBJECT(video_enc), "bitrate", 10000, NULL);//10000��������⣿�� 
    	
    	parse = gst_element_factory_make("h264parse", "parser");
    	q3 = gst_element_factory_make("queue", "q3");
    	mux = gst_element_factory_make("avimux", "mux");
    	video_sink = gst_element_factory_make("filesink", "video_sink");
    	g_object_set(G_OBJECT(video_sink), "location", filename, NULL);
    	q2 = gst_element_factory_make("queue", "q2");
    	tee = gst_element_factory_make ("tee", "tee");
    	video_queue =gst_element_factory_make("queue","video_queue"); 
    	pic_queue = gst_element_factory_make("queue","pic_queue"); 
    	pic_convert = gst_element_factory_make("vpe", "pic_convert");
    	//g_object_set(G_OBJECT(pic_convert), "num-input-buffers", 8, NULL);
    	
    	pic_enc = gst_element_factory_make("ducatijpegenc", "pic_enc");
    	//g_object_set (pic_enc, "intra-interval", 100, NULL);
    	pic_sink = gst_element_factory_make("appsink", "pic_sink");
    	g_object_set (pic_sink, "emit-signals", TRUE, NULL);
      	g_signal_connect (pic_sink, "new-sample", G_CALLBACK (new_sample), NULL); 
    	
    
    	gst_bin_add_many(GST_BIN(pipeline[channel]), src, tee, video_convert, q1, video_enc, parse, q3, mux, video_sink, pic_convert, q2,pic_enc, pic_sink, NULL);
      	
    	tee_video_pad = gst_element_get_request_pad (tee, "src_%u");
      	g_print ("Obtained request pad %s for video branch.\n", gst_pad_get_name (tee_video_pad));
      	queue_video_pad = gst_element_get_static_pad (video_convert, "sink");
      	tee_picture_pad = gst_element_get_request_pad (tee, "src_%u");
      	g_print ("Obtained request pad %s for picture branch.\n", gst_pad_get_name (tee_picture_pad));
      	queue_picture_pad = gst_element_get_static_pad (pic_convert, "sink");
      	
      	if (gst_pad_link (tee_picture_pad, queue_picture_pad) != GST_PAD_LINK_OK ||
          gst_pad_link (tee_video_pad, queue_video_pad) != GST_PAD_LINK_OK) {
        g_printerr ("Tee could not be linked.\n");
        gst_object_unref (pipeline);
      	}
    	  
    	/*if (gst_element_link_pads(src, "src", srcqueue, "sink") != TRUE)
    	{
    		g_print("11\n");
    	}
    	
    	if (gst_element_link_pads(srcqueue, "src", teequeue, "sink") != TRUE)
    	{
    		g_print("111\n");
    	}//��û�� queue��һ�� 
    	*/
    	
    	link_source_element_with_filter(src, tee, 1280, 720, 30);
    	
      		if (gst_element_link_pads(video_convert, "src", q1, "sink") != TRUE)
    	{
    		g_print("1\n");
    	}
    	if (gst_element_link_pads(q1, "src", video_enc, "sink") != TRUE)
    	{
    		g_print("2\n");
    	}
    	if (gst_element_link_pads(video_enc, "src", parse, "sink") != TRUE)
    	{
    		g_print("3\n");
    	}
    	if (gst_element_link_pads(parse, "src", q3, "sink") != TRUE)
    	{     
    		g_print("4\n");
    	}
    	link_to_multiplexer(q3, mux);
    	if (gst_element_link_pads(mux, "src", video_sink, "sink") != TRUE)
    	{
    		g_print("5\n");
    	}
      	
      	//link_source_element_with_filter(pic_queue, pic_convert, 1280, 720, 30);
    	
    	if(gst_element_link_pads(pic_convert, "src", q2, "sink")!= TRUE)
    	{
    		g_print("6\n");
    	}
    	if(gst_element_link_pads(q2, "src", pic_enc, "sink")!= TRUE)
    	{
    		g_print("66\n");
    	}
    	if(gst_element_link_pads(pic_enc, "src", pic_sink, "sink")!= TRUE)
    	{
    		g_print("7\n");
    	}
      
    	gst_object_unref (queue_picture_pad);
      	gst_object_unref (queue_video_pad);
    	
    	gst_element_set_state(pipeline[channel], GST_STATE_PLAYING);	
    }
    
    void record_stop(int channel)
    {
    
     	gst_element_send_event(pipeline[channel],gst_event_new_eos()); 	
    	/* Wait until error or EOS */
    	bus[channel] = gst_element_get_bus(pipeline[channel]);
    	msg[channel] = gst_bus_timed_pop_filtered(bus[channel], GST_CLOCK_TIME_NONE , GST_MESSAGE_ERROR | GST_MESSAGE_EOS);//GST_CLOCK_TIME_NONE
    	
     	gst_element_release_request_pad (tee, tee_picture_pad);
      	gst_element_release_request_pad (tee, tee_video_pad);
      	gst_object_unref (tee_picture_pad);
      	gst_object_unref (tee_video_pad);
      
    	if (msg[channel] != NULL)
    	{
    		gst_message_unref(msg[channel]);
    	}
    
    
    	gst_object_unref(bus[channel]);
    	
    	gst_element_set_state(pipeline[channel], GST_STATE_PAUSED);
    	gst_element_set_state(pipeline[channel], GST_STATE_READY);
    	gst_element_set_state(pipeline[channel], GST_STATE_NULL);
    	gst_object_unref(pipeline[channel]);
    }
    
    void main()
    {
        dataPtr=(unsigned int*)malloc(sizeof(unsigned int) * FRAME_264);
        memset(dataPtr,0,FRAME_264);
        
    	record_start(0, "ch0.avi");
    	sleep(500);
    	record_stop(0);
    	free(dataPtr);
    	dataPtr = NULL;
    }

    What's your opinion?

    BR

    hsg

  • Hello,

    As I said in my previous post tee element can not be before the caps filter.
    Please replace it here:
    gst-launch-1.0 v4l2src device=/dev/video1 io-mode=4 ! 'video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720,framerate=(fraction)30/1' ! tee name=t ! ....
    Please refer the pipeline in my previous post and change your application based on this pipeline.
    As you could see, this pipeline was working for almost an hour before I to stopped the execution.

    BR
    Margarita
  • Hello,

    I'm so sorry that I post u the wrong pipeline.

    This is the test result of the true pipeline(about 5mins it failed):

    gst-launch-1.0 v4l2src device=/dev/video1 io-mode=4 ! 'video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720,framerate=(fraction)30/1' ! tee name=t ! vpe num-input-buffers=8 ! queue ! ducatih264enc bitrate=10000 ! h264parse ! avimux ! filesink location=1.avi t. ! queue ! vpe num-input-buffers=8 ! queue ! ducatijpegenc ! fakesink
    Setting pipeline to PAUSED ...
    Pipeline is live and does not need PREROLL ...
    Setting pipeline to PLAYING ...
    New clock: GstSystemClock

    ** (gst-launch-1.0:1355): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

    ** (gst-launch-1.0:1355): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

    ** (gst-launch-1.0:1355): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

    ** (gst-launch-1.0:1355): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

    ** (gst-launch-1.0:1355): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed

    ** (gst-launch-1.0:1355): CRITICAL **: gst_fd_memory_get_fd: assertion 'GST_IS_FD_ALLOCATOR (mem->allocator)' failed
    ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data flow error.
    Additional debug info:
    ../../../../gstreamer-1.8.3/libs/gst/base/gstbasesrc.c(2948): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
    streaming task paused, reason error (-5)

    And my app had changed which based on the pipeline(it also failed after about 5mins)

    I'm so sorry for my last message.

    BR

    hsg

  • Hello,

    The only difference between your pipeline and the pipeline that I tested is the bitrate.
    Could you try on your side without bitrate property?

    BR
    Margarita
  • Hello,

    You are right the issue could be reproduced when the bitrate is 10 000 and above.
    Please use lower for now.

    BR
    Margarita
  • Hello,
    Thanks for your testing and reply.
    I used the gstreamer tools to get the properties of the h264 encoder :
    gst-inspect-1.0 ducatih264enc
    and its output was:
    bitrate : Bitrate in kbit/sec
    flags: readable, writable
    Integer. Range: -1 - 102400 Default: 2048
    However,
    I used the pipeline:
    gst-launch-1.0 v4l2src device=/dev/video1 io-mode=4 ! 'video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720,framerate=(fraction)30/1' ! tee name=t ! vpe num-input-buffers=8 ! queue ! ducatih264enc bitrate=4000 ! h264parse ! avimux ! filesink location=1.avi t. ! queue ! vpe num-input-buffers=8 ! queue ! ducatijpegenc ! fakesink
    it failed after about 30mins
    and this pipeline:
    gst-launch-1.0 v4l2src device=/dev/video1 io-mode=4 ! 'video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720,framerate=(fraction)30/1' ! tee name=t ! vpe num-input-buffers=8 ! queue ! ducatih264enc bitrate=4000 level=41 profile=100 ! h264parse ! avimux ! filesink location=1.avi t. ! queue ! vpe num-input-buffers=8 ! queue ! ducatijpegenc ! fakesink
    it lasted for about 40mins
    And usually its running time was not steady.
    This pipeline can last more than one hour:
    gst-launch-1.0 v4l2src device=/dev/video1 io-mode=4 ! 'video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720,framerate=(fraction)30/1' ! tee name=t ! vpe num-input-buffers=8 ! queue ! ducatih264enc ! h264parse ! avimux ! filesink location=1.avi t. ! queue ! vpe num-input-buffers=8 ! queue ! ducatijpegenc ! fakesink
    its bitrate was default(2048kbps).
    But the bitrate was too low to capture the video clearly especially when the scenery was complex.
    So is there any ways to increase the bitrate but not to make the pipeline ended.
    Thanks&regards!
  • Hello,
    I tested the low bitrate(2048kbps),and the pipeline worked fine.
    But we need a higher bitrate to meet the quality of the video.
    Could u help us and solve the problem?
    Thanks&regards!
  • Hello,

    I would recommend you to check the bitrate=6000 for example you should set level=level-5 and give a try on your side with tee element.
    Keep in mind that the tee element is not a TI element as v4l2src.
    Add some more queues in the pipeline.
    We are looking into this, I will get back to you when we have something.

    BR
    Margarita
  • hello hsg:

       Where Can Get the ducatijpegenc plugin,I find there is no this element in the sdk ,Thanks.

  • Hello zhichao tan60372 .

    Please open a new topic with your question and PSDK version that you are using.

    BR
    Margarita
  • Hello,
    Have u found something to the issues?If so,could u give me some advice?
    Thanks&regards!
  • Hello,

    We are still looking into this issue.


    BR
    Margarita
  • Hello,


    Is there any process on your side?


    BR
    hsg
  • Hello hsg,

    Let me check.

    BR
    Margarita
  • Hello Margarita,

    Is there any process on your side?
    I'm hurry and I have no idea to solve the problem.
    And could u give me some other ways to encode the video files reliably.

    BR
    hsg
  • Hello,

    hsg said:
    And could u give me some other ways to encode the video files reliably.

    Do you mean instead of gstreamer?

    You could try to use pipeline with videoconvert element. You could add videorate element to adjust the fps.

    Here is example:

    gst-launch-1.0 v4l2src device=/dev/video1 typefind=true io-mode=4 ! 'video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720,framerate=(fraction)30/1' !   videoconvert  ! videorate ! video/x-raw,framerate=2/2 ! queue  ! tee name=t ! multiqueue   ! queue ! ducatih264enc bitrate=10000 level=level-5 inter-interval=1 ! h264parse ! queue ! avimux ! filesink location=1.avi t. ! queue ! ducatih264enc  ! h264parse ! queue ! qtmux ! filesink location=2.mov --gst-debug=1

    BR
    Margarita

  • Hello,

    Yes, I mean that is there any other reliably pipeline or other ways to encode the video.
    And I am going to use the ffmpeg but I will try this pipeline first.
    Thank u for your new pipeline!

    BR
    hsg
  • Hello,

    I do not think this is an encoder issue. However you could try this command gst-inspect | grep "enc" to check what gst software encoders are available also.

    BR
    Margarita