How to output opencv to gstreamer in python?

I want to process camera stream in opencv (that works fine), but then output the resulting processed frames over the network so I can see them as it's an embedded system without a monitor. I've spent days looking, but cannot work out how to push the frames to gstreamer in python. It looks like I should create an appsrc->udp pipeline in gstreamer (that's no problem), but I cannot find anywhere how to push the frames to appsrc in opencv using python. I've seen some examples in C++ but I've no idea how to translate them to python. It seems one can either copy buffers like this: Push images into Gstreamer pipeline Or this implies an easier way by opening an appsrc directly in opencv videowriter: How to write opencv mat to gstreamer pipeline?

Does anyone out there have a very simple example of how to output opencv to gstreamer in python?


I am no python expert .. but what about this ..

Suppose you have this code for connecting the appsrc need-data signal (like here ):

source = gst.element_factory_make("appsrc", "source")
.. you need to set caps, then connect:
source.connect('need-data', self.needdata)

Then in the needdata function you need to get the data pointer of your opencv frame and create GstBuffer from it and emit it..

Suppose you have two variables self.data is the actual opencv data and self.size is the size of the data:

def needdata(self, src, length):
    buf = Gst.Buffer.new_allocate(self.size) 
    buf.fill(0, self.data)
    src.emit('push-buffer', buf)

Hm not sure whats in that length variable.. the pygst on gstreamer 1.0 seems to be quite undocumented.. or I cannot find the docs..

链接地址: http://www.djcxy.com/p/25430.html

上一篇: 分割故障OpenCV cap.read udp流Python

下一篇: 如何在Python中输出opencv到gstreamer?