How to get cropmeta from buffer?

fthfth forummailreader at yandex.com
Thu Sep 1 09:18:30 UTC 2016


Hello all,

I am new in GStreamer and image processing. Sorry for stupid questions. 
I want to send an image with metadata so initially I have used
videocropmeta. I am not able to retrive the meta, it always returns null. If
you help me, I would be appreciated.

server:

void need_buf (GstAppSrc *appsrc,
        guint       unused_size,
        gpointer    user_data)
{
    g_print("need buffer\n");
    static GstClockTime timestamp = 0;

    GstBuffer *buffer;
    GstFlowReturn ret;
    guint size,height,width,channels;
    IplImage* img;
    guchar *data1;
    GstMapInfo map;

    img=cvLoadImage("/home/.../Downloads/Image1.jpg",1);
    height    = img->height;
    width     = img->width;
    channels  = img->nChannels;
    data1      = (guchar *)img->imageData;
    size = height*width*channels;
    buffer = gst_buffer_new_allocate (NULL, size, NULL);

    gst_buffer_map (buffer, &map, GST_MAP_WRITE);
    memcpy( (guchar *)map.data,data1 , gst_buffer_get_size( buffer ) );
    //gst_buffer_memset (buffer, 0, white ? 0xff : 0x0, size);
    GST_BUFFER_PTS (buffer) = timestamp;
    GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale_int (1, GST_SECOND,
2);

    timestamp += GST_BUFFER_DURATION (buffer);

    GstVideoCropMeta *meta;
    /* buffer points to a video frame, add some cropping metadata */
    meta = gst_buffer_add_video_crop_meta (buffer);
    /* configure the cropping metadata */
    meta->x = 1;
    meta->y = 2;
    meta->width = 3;
    meta->height = 4;

   // g_signal_emit_by_name (appsrc, "push-buffer", buffer, &ret);
    ret = gst_app_src_push_buffer(appsrc, buffer);

    if (ret != GST_FLOW_OK) {
    	g_print("quit: %s\n", __func__);
        g_main_loop_quit (mm_loop);
    }
}

void startPipe()
{
	GstElement* m_pipeline;
	gst_init (NULL, NULL);
	mm_loop = g_main_loop_new (NULL, FALSE);
	m_pipeline = gst_parse_launch ("appsrc name=testSrc
caps=video/x-raw,format=RGB,width=640,height=480,framerate=30/1 ! "
			"videoconvert name=ffmpeg ! "
			"x264enc ! "
			"h264parse ! rtph264pay config-interval=1 pt=96 ! udpsink
host=172.20.21.255 port=5600 sync=false async=false", NULL);

	GstElement* appsrc = gst_bin_get_by_name(GST_BIN(m_pipeline), "testSrc");

	GstAppSrcCallbacks cbs;
	cbs.need_data = need_buf;
	cbs.enough_data = enough_buf;
	gst_app_src_set_callbacks(GST_APP_SRC_CAST(appsrc), &cbs, NULL, NULL);
	gst_element_set_state (m_pipeline, GST_STATE_PLAYING);
	g_main_loop_run (mm_loop);
	/* clean up */
	gst_element_set_state (m_pipeline, GST_STATE_NULL);
	gst_object_unref (GST_OBJECT (m_pipeline));
	g_main_loop_unref (mm_loop);
}

client: 

/* fakesink handoff callback */
void
on_gst_buffer(GstElement * element,
                        GstBuffer * buf,
                        GstPad * pad,
						gpointer data)
{
    /* ref then push buffer to use it in qt */
	GstVideoCropMeta *meta = gst_buffer_get_video_crop_meta(buf);
	if (meta == NULL)
		return;
	g_print ("gstBuffer");
    gst_buffer_ref(buf);
}

.........
gchar *pipeline = g_strdup_printf ("udpsrc port=5600 ! "
			 "application/x-rtp, encoding-name=H264,payload=96 !  "
			 "rtph264depay ! h264parse ! avdec_h264 ! "
			 "autovideosink name =fakesink0");

	 m_pipeline = GST_PIPELINE (gst_parse_launch (pipeline, NULL));
	 g_free (pipeline);

	 m_bus = gst_pipeline_get_bus(GST_PIPELINE(m_pipeline));
	 gst_bus_add_watch(m_bus, (GstBusFunc) bus_call, m_loop);
	 gst_object_unref(m_bus);

	 GstElement *fakesink = gst_bin_get_by_name(GST_BIN(m_pipeline),
"fakesink0");
	 g_object_set(G_OBJECT (fakesink), "signal-handoffs", TRUE, NULL);
	 g_signal_connect(fakesink, "handoff", G_CALLBACK (on_gst_buffer), m_loop);
	 gst_object_unref(fakesink);

	 GstStateChangeReturn ret =
			 gst_element_set_state(GST_ELEMENT(m_pipeline), GST_STATE_PLAYING);



--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/How-to-get-cropmeta-from-buffer-tp4679347.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.


More information about the gstreamer-devel mailing list