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

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


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

Hi,

> 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():

https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-b
ase-libs/html/gst-plugins-base-libs-GstVideoAlignment.html#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:

https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/ext/opencv

Cheers
 -Tim


-- 
Tim Müller, Centricular Ltd - http://www.centricular.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20170530/0f4cc9e4/attachment.html>


More information about the gstreamer-devel mailing list