AW: playback H264 encoded file too fast

jles jlesquer at gmail.com
Tue Jul 16 07:45:04 UTC 2019


Hi,

It actually didn't work as I thought, it looked at normal speed but I test
it with different light conditions and unfortunately still the issue...

This is the code:

static void
cb_need_data (GstElement *appsrc,
          guint       unused_size,
		  GstElement *vrate)
{
	clock_t start, end;
    struct timespec ts_start;
    struct timespec ts_end;
	static GstClockTime timestamp = 0;
	guint buffer_size;
	GstFlowReturn ret;
	static float fps=0.0;
	static float fps_prev=0.0;
	// image buffer
	IMG image;


	memset(&image,0,sizeof(image));
	image.size = sizeof(IMG);
//	start = clock();
    GetImage(Handle,&image);
//	end = clock();
	GetCamParam(Handle, FRAMERATE, &fps);
//	printf("The execution time is : %f fps: %f\r\n", ((double)(end  - start))
/ CLOCKS_PER_SEC, fps);
	buffer_size =  image.width * image.height * 2;

	GstBuffer *buffer = gst_buffer_new_wrapped_full( (GstBufferFlags)0 ,
(guint8*)image.bp, buffer_size, 0, buffer_size, NULL, NULL );
	
	/*Set timestamp*/
    GST_BUFFER_PTS (buffer) = timestamp;
    GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale_int (1, GST_SECOND,
fps);
    timestamp += GST_BUFFER_DURATION (buffer);
	
	/*Push buffer*/
	g_signal_emit_by_name (appsrc, "push-buffer", buffer, &ret);
	gst_buffer_unref (buffer);

	if (ret != GST_FLOW_OK ) {
finish:
		/* something wrong, stop pushing */
		gst_app_src_end_of_stream(GST_APP_SRC(appsrc));
		g_main_loop_quit (loop);

	}

}

int main(int argc, char **argv)
{

	IMG image;
	/* init GStreamer */
	gst_init (&argc, &argv);
	clock_t start, end;
	static float fps=0.0;
	static float fps_prev=0.0;
	GstElement *appsrc, *video_rate, *filesink, *omxh264,
*enc_queue,*src_queue, *enc_capsfilter, *videoconvert,*capsfilter,*mp4mux,
*h264parser;

	// Retrieving a handle to the camera device
	stat = OpenDevice(0, &Handle);
	HandleResult(stat,"OpenDevice");
	

	// Start acquisition
	StartAcquisition(Handle);
	GetImage(Handle,&image);

	loop = g_main_loop_new (NULL, FALSE);

	/* Pipeline elements */
	pipeline = gst_pipeline_new ("pipeline");
	appsrc = gst_element_factory_make ("appsrc", "source");
	video_rate = gst_element_factory_make ("videorate", "video_rate");
	omxh264 = gst_element_factory_make ("omxh264enc", "omxh264enc");
	enc_queue = gst_element_factory_make ("queue", "Encoder Queue");
	src_queue = gst_element_factory_make ("queue", "Source Queue");
	videoconvert = gst_element_factory_make ("videoconvert", "video convert");
	capsfilter = gst_element_factory_make ("capsfilter", "caps filter");
	enc_capsfilter = gst_element_factory_make ("capsfilter", "Encoder output
caps");
	h264parser = gst_element_factory_make ("h264parse", "h264 parser");
	mp4mux = gst_element_factory_make ("mpegtsmux", "mp4 mux");
	filesink = gst_element_factory_make ("filesink", "filesink");

	/* setup */
	g_object_set(filesink, "location", "media/test/output.ts", NULL);
	g_object_set (G_OBJECT (appsrc), "is-live", TRUE,NULL);
	g_object_set (G_OBJECT (appsrc), "stream-type", 0, "format",
GST_FORMAT_TIME, NULL);
	g_object_set(G_OBJECT(appsrc), "do-timestamp", TRUE, NULL);
	g_object_set (G_OBJECT (enc_capsfilter), "caps", gst_caps_new_simple
("video/x-h264", "profile", G_TYPE_STRING, "high", NULL), NULL);
	g_object_set (G_OBJECT(omxh264),  "b-frames", 0, "control-rate", 1,
"gop-length",0, NULL);

	g_object_set (G_OBJECT (appsrc), "caps",
	gst_caps_new_simple ("video/x-raw",
					 "format", G_TYPE_STRING, "GRAY8",
					 "width", G_TYPE_INT, image.width,
					 "height", G_TYPE_INT, image.height,
					 "framerate", GST_TYPE_FRACTION, 0, 1,
					 NULL), NULL);

	g_object_set (G_OBJECT (capsfilter), "caps",
	gst_caps_new_simple ("video/x-raw",
					 "format", G_TYPE_STRING, "NV12",
					 "width", G_TYPE_INT, image.width,
					 "height", G_TYPE_INT, image.height,
					 "framerate", GST_TYPE_FRACTION, 25, 1,
					  NULL), NULL);

	/*Build pipeline*/
	gst_bin_add_many (GST_BIN (pipeline), appsrc,
video_rate,videoconvert,capsfilter,src_queue, omxh264 ,
enc_queue,enc_capsfilter, h264parser , mp4mux,filesink , NULL);
	gst_element_link_many (appsrc, video_rate,
videoconvert,capsfilter,src_queue, omxh264, enc_queue,enc_capsfilter,
h264parser , mp4mux, filesink, NULL);


	/* setup appsrc */
	g_signal_connect (appsrc, "need-data", G_CALLBACK
(cb_need_data),video_rate);

	/* play */
	gst_element_set_state (pipeline, GST_STATE_PLAYING);
	g_main_loop_run (loop);

	/* clean up */
finish:
	printf("Stop Pipeline\r\n ");
	gst_element_set_state (pipeline, GST_STATE_NULL);
	gst_object_unref (pipeline);
	g_main_loop_unref (loop);
	StopAcquisition(Handle);
	// Close device
	if (Handle) CloseDevice(Handle);

	return 0;
}





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


More information about the gstreamer-devel mailing list