GStreamer-Python在重新启动时失败 我有一个错误,下面的代码在我第一次运行时工作正常,但在我终止进程并重试之后,尽管创建了管道并成功启动了主循环,但从未调用新的_示例,也没有收到任何数据。
为了让它再次运行,我必须重新启动我的计算机。我认为这一定与清理gstreamer管道有关,但我已经尝试了很多方法,在ps aux中找不到gstreamer流程。另外,我应该提到,如果我使用等效管道运行gst-launch-1.0,它每次都会工作。我认为这个问题是python实现特有的GStreamer-Python在重新启动时失败 我有一个错误,下面的代码在我第一次运行时工作正常,但在我终止进程并重试之后,尽管创建了管道并成功启动了主循环,但从未调用新的_示例,也没有收到任何数据。,python,gstreamer,Python,Gstreamer,为了让它再次运行,我必须重新启动我的计算机。我认为这一定与清理gstreamer管道有关,但我已经尝试了很多方法,在ps aux中找不到gstreamer流程。另外,我应该提到,如果我使用等效管道运行gst-launch-1.0,它每次都会工作。我认为这个问题是python实现特有的 def new_sample(appsink): sample = appsink.emit('pull-sample') print "pull sample" buffer = samp
def new_sample(appsink):
sample = appsink.emit('pull-sample')
print "pull sample"
buffer = sample.get_buffer()
print "got buffer"
data = buffer.extract_dup(0, buffer.get_size())
save_image(data)
return False
'''
gst-launch-1.0 -v tcpclientsrc host=YOUR-PI-IP-ADDRESS port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink sync=false
'''
def start_consume(ip=DEFAULT_IP_ADDRESS, port=DEFAULT_PORT):
global pipeline
GObject.threads_init()
Gst.init(None)
pipeline = Gst.Pipeline()
tcpsrc = Gst.ElementFactory.make('tcpclientsrc','tcpsrc')
tcpsrc.set_property("host", ip)
tcpsrc.set_property("port", port)
gdepay = Gst.ElementFactory.make('gdpdepay', 'gdepay')
rdepay = Gst.ElementFactory.make('rtph264depay', 'rdepay')
avdec = Gst.ElementFactory.make('avdec_h264', 'avdec')
vidconvert = Gst.ElementFactory.make('videoconvert', 'vidconvert')
asink = Gst.ElementFactory.make('appsink', 'asink')
asink.set_property('sync', False)
asink.set_property('emit-signals', True)
asink.set_property('drop', True)
asink.connect('new-sample', new_sample)
asink.connect('pull-sample', pull_sample)
asink.connect('pull-preroll', pull_preroll)
pipeline.add(tcpsrc)
pipeline.add(gdepay)
pipeline.add(rdepay)
pipeline.add(avdec)
pipeline.add(vidconvert)
pipeline.add(asink)
tcpsrc.link(gdepay)
gdepay.link(rdepay)
rdepay.link(avdec)
avdec.link(vidconvert)
vidconvert.link(asink)
pipeline.set_state(Gst.State.PLAYING)
return pipeline
if __name__ == "__main__":
try:
loop = GObject.MainLoop()
pipeline = start_consume()
loop.run()
except KeyboardInterrupt:
print "Closing pipeline"
pipeline.set_state(Gst.State.NULL)
loop.quit()
我发现错误是关闭gstreamer管道。使用control+\关闭有效,而使用control+c关闭无效