在python中只调用一个参数

2024-09-26 23:18:07 发布

您现在位置:Python中文网/ 问答频道 /正文

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)

所以我想做的是,每当源代码板或接收器板上发生事件时,都会在主线程中调用probe回调函数。在

对于函数“def probe\u callback(multisink_pad,info):” 当我试图运行这个函数时,它给了我一个错误:

(TypeError: probe_callback() takes exactly 2 arguments (1 given) )

我遵循这个网站上的代码:Gstreamer message to signal new frame from video source (webcam)

我试过了,但似乎对我没用。有人能帮我吗?在


Tags: selfinfoaddsourcemakepipelinepngvideo

热门问题