I'm trying to implement a Gstreamer plugin _chain function based on its template, which simply replaces the input video frame(BGRx) to my converted image in the same size, shown as below:
static GstFlowReturn gst_myplugin_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) {
Gstmyplugin *filter;
filter = GST_MYPLUGIN (parent);
if(filter->silent == FALSE)
g_print("I'm plugged, therefore I'm in. \n");
// retrieve pass-in image frame from input buf
GstMapInfo map;
gst_buffer_map(buf, &map, GST_MAP_READ);
cv::Mat frame(cv::Size(width, height), CV_8UC4, (char *)map.data, cv::Mat::AUTOSTEP); //Q1
// check the orignal frame
cv::imshow("Input image", frame); //Q2
// convert to new image by same size
cv::Mat out = my_convert(frame);
// how to populate output buffer from Mat out then
GstBuffer *out_buf = ??? //Q3
//return gst_pad_push(filter->srcpad, buf); transparent filter in plugin template
return gst_pad_push(filer->srcpad, out_buf); //send my converted image
}
So there are three questions(also marked in above lines):
Q1: how to get input image's width and height ?
Q2: why the parsed image can't be shown properly as those in the video ?
Q3: how to populate the output buffer ?
I've searched a lots online for days, but still can't get them solved yet.