Read frames from GStreamer pipeline in opencv (cv::Mat)

Tim Müller tim at
Tue May 30 15:26:23 UTC 2017

On Mon, 2017-05-29 at 12:03 -0700, pchaurasia wrote:


> I am looking to read frames from my Gstreamer pipeline into opencv
> data structure. I am using 'new_sample' signal of appsink to read
> frames. The map derived from the sample, read off of appsink - does
> not seem to give right size of the frame. 
>   if (!gst_buffer_map ((buffer), &map_info, GST_MAP_READ)) {
>     gst_buffer_unmap ((buffer), &map_info);
>     gst_sample_unref(sample);
>     return GST_FLOW_ERROR;
>   }
> I believe map_info.size --> should give size of the frame. The frame
> size that I see does not appear correct.

How is the size not correct? What frame size in bytes do you get for
what resolution in what format, and what did you expect it to be?

You'll usually want to map video buffers with gst_video_frame_map():

so you also get the stride and such.

As for Cv::Mat, maybe have a look at the GStreamer OpenCV plugin, there
are a bunch of elements that use Cv::Mat as well:


Tim Müller, Centricular Ltd -
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the gstreamer-devel mailing list