gpt4 book ai didi

python - Gstreamer、Python 和 Appsink

转载 作者:行者123 更新时间:2023-11-28 18:41:19 24 4
gpt4 key购买 nike

我使用 Gstreamer 1.0 设置了一个简单的管道,如下所示。当我尝试从 appsink 创建拉样本时,代码停在 "sample = appsink.emit('pull-sample')"处。奇怪的是,如果我删除该行,代码将按预期工作,不断打印“尝试提取样本”。如果我尝试跳过前 100 个样本左右以及更改 appsink 上的属性,我会遇到同样的问题。任何人都知道发生了什么事?

gst-launch-1.0 v4l2src device="/dev/video0" ! videorate ! video/x raw,height=480,width=640,framerate=15/1 !  appsink


def createASink():
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)
return asink

def new_sample(appsink):
print "Trying to pull sample"
sample = appsink.emit('pull-sample')
return False

最佳答案

所以这是一个 hack 解决方法,但它仍然有效。如果有人知道更好的解决方案,请告诉我。

我可以使用文件接收器输出字节数组,然后从中连续读取。我使用 python 中的多处理模块同时运行 gstreamer 和我的消费者。

def consumeStream():
fp = "gst_data"
with open(fp, "r+b") as data_file:
data_file.truncate()
while True:
where = data_file.tell()
line = data_file.readline()
if not line:
time.sleep(.05)
data_file.seek(where)
else:
data_file.truncate()
print "Got data"

关于python - Gstreamer、Python 和 Appsink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25716884/

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