Ask Your Question
0

How to use gst_memory_new_wrapped wrap opencv mat ?

asked 2018-10-10 19:50:38 -0500

Eric.Dafran gravatar image

updated 2018-10-10 19:54:07 -0500

I want use “gst_memory_new_wrapped” wrapped opencv mat and put it to appsrc and stream it out. I fetch v4l2 buffer from my cam and transfer it to mat

init_v4l2_capture(dev_node, cmdline.width, cmdline.height, V4L2_PIX_FMT_YUYV);

cv::Mat mat = cv::Mat(480,640,CV_8UC2,(void*)fbuffer1);

Then transfer it to BGR and do something.

cv::cvtColor(mat,rgb_mat,cv::COLOR_YUV2BGR_YUY2);

After that I put it to a GstMemory use "gst_memory_new_wrapped" and use "gst_buffer_append_memory" append to a GstBuffer and push it to appsrc.

gst_wrapped_mem = gst_memory_new_wrapped( (GstMemoryFlags)0, (gpointer) rgb_cv.data, 640*480*3 ,0,640*480*2,NULL, NULL);

gst_buffer_append_memory(buffer1, gst_wrapped_mem);

g_signal_emit_by_name(gst_handle1->src, "push-buffer", buffer1, &ret1);

At lase the appsrc caps format is BGR.

And finally i got that .... "mysource" is my appsrc name. Thread 3 "mysource:src" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fffe6c74700 (LWP 301)] 0x00007fffe7d7bf33 in ?? () from /usr/lib/x86_64-linux-gnu/libgstvideo-1.0.so.0

edit retag flag offensive close merge delete

Comments

i'm just guessing, but rgb_mat will self-destruct when leaving the scope/function, so rgb_cv.data will be no more valid

berak gravatar imageberak ( 2018-10-11 01:09:47 -0500 )edit

Holy Magic! Your guessing helped me. I should have remembered appsrc will use the shared memory. You're genius, Thanks again.

Eric.Dafran gravatar imageEric.Dafran ( 2018-10-11 01:35:49 -0500 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2018-10-11 01:44:15 -0500

Eric.Dafran gravatar image

updated 2018-10-11 02:05:30 -0500

berak gravatar image

fixed with:

  cv::Mat outside; 
  while(active) {
            rgb_cv.copyTo(outside);
            wrapped_mem1 = gst_memory_new_wrapped( (GstMemoryFlags)0, (gpointer) outside.data, 640*480*3 ,0, 640*480*3,NULL, NULL);
            gst_buffer_append_memory(buffer1, wrapped_mem1);  
            g_signal_emit_by_name(gst_handle1->src, "push-buffer", buffer1, &ret1);   
  }  
   gst_buffer_unref(buffer1);
   outside.release();
edit flag offensive delete link more

Comments

1

Thanks teach me a lot...

Eric.Dafran gravatar imageEric.Dafran ( 2018-10-11 02:14:25 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-10-10 19:50:38 -0500

Seen: 20 times

Last updated: Oct 11