import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject #,Gtk
from gi.repository import Gst as gst
class TakePhoto:
def __init__(self):
GObject.threads_init()
gst.init(None)
self.pipeline = gst.Pipeline()
self.video_source = gst.ElementFactory.make('v4l2src', 'video_source')
self.video_source.set_property("num-buffers",1)
self.vconvert = gst.ElementFactory.make('videoconvert', 'vconvert')
self.png = gst.ElementFactory.make('pngenc', 'png')
self.multisink = gst.ElementFactory.make('multifilesink', 'multisink')
self.multisink_pad = self.multisink.get_static_pad("sink")
self.multisink_pad.add_probe(gst.PadProbeType.EVENT_UPSTREAM,self.probe_callback)
self.caps = gst.caps_from_string("video/x-raw,format=RGB,width=800,height=600,framerate=5/1")
self.png.set_property('snapshot',True)
self.multisink.set_property('location','/home/pi/frame.png')
self.filter = gst.ElementFactory.make("capsfilter", "filter")
self.filter.set_property("caps", self.caps)
self.pipeline.add(self.video_source)
self.pipeline.add(self.vconvert)
self.pipeline.add(self.filter)
self.pipeline.add(self.png)
self.pipeline.add(self.multisink)
self.video_source.link(self.filter)
self.filter.link(self.vconvert)
self.vconvert.link(self.png)
self.png.link(self.multisink)
def probe_callback(multisink_pad,info):
info_event = info.get_event()
info_structure = info_event.get_structure()
do_something_with_this_info
return Gst.PadProbeReturn.PASS
def take_photo(self): #this is reusable
bus = self.pipeline.get_bus()
self.pipeline.set_state(gst.State.PLAYING)
print "Capture started"
msg = bus.timed_pop_filtered(gst.CLOCK_TIME_NONE,gst.MessageType.ERROR | gst.MessageType.EOS)
print msg
self.pipeline.set_state(gst.State.NULL)
所以我想做的是每次在源板或接收器垫上都有事件时,将在主线程中调用探测器回调函数。
对于函数" def probe_callback(multisink_pad,info):" 当我试图运行这个功能时,它给了我一个错误,说明了这一点:
(TypeError:probe_callback()只需要2个参数(给定1个))
我从这个网站上关注这些代码:Gstreamer message to signal new frame from video source (webcam)
我试过,它似乎并不适合我。有谁可以帮我这个?