gpt4 book ai didi

python - GStreamer Python 重新启动时失败

转载 作者:太空宇宙 更新时间:2023-11-03 18:15:17 24 4
gpt4 key购买 nike

我有一个错误,下面的代码第一次运行时工作正常,但在我终止进程并重试之后,尽管创建了管道并成功启动了主循环,但从未调用 new_sample 并且没有收到任何数据.

为了真正让它再次运行,我必须重新启动计算机。我认为这一定与清理 gstreamer 管道有关,但我已经尝试了很多方法,但我在 ps aux 中找不到 gstreamer 进程。另外,我应该提到,如果我使用等效管道运行 gst-launch-1.0,它每次都会有效。我认为这个问题是特定于 python 实现的。

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 关闭则不行。

关于python - GStreamer Python 重新启动时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25110878/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com