Gstreamer,Python和Appsink

时间:2014-09-08 02:59:03

标签: python gstreamer

我使用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

1 个答案:

答案 0 :(得分:1)

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

我可以使用filesink输出字节数组,然后连续读取。我在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"
相关问题