当使用带有两个接收器的交错元素时,Gst 管道不是 运行

Gst Pipeline not running when using interleave element with two sinks

我在 gstreamer 管道中使用交错元素时遇到问题。

我正在将输入 (autoaudiosrc) 中的音频读入 T 型,这样我就可以将它写入磁盘并实时获取音频电平(将用它提供一个硬件 vu 表,在它只是打印的附加片段中标准输出的级别)。我希望能够使用任何 1 或 2 个通道并将它们写入一个单独的文件,这样我就可以将 6 个输入通道分成 5 个文件(1 个立体声,4 个单声道)。 现在将所有内容写入一个文件工作正常,然后我添加了一个 deinterleave 元素以将所有内容拆分为单声道文件,这也工作正常,但是将两个通道组合成一个立体声通道会破坏整个管道。

def new_recorder_bin(path, sinks=1):
    bin = Gst.Bin()
    interleave = Gst.ElementFactory.make('interleave', None)
    queue = Gst.ElementFactory.make('queue', None)
    encoder = Gst.ElementFactory.make('wavenc', None)
    output = Gst.ElementFactory.make('filesink', None)
    output.set_property('location', path)
    bin.add(interleave)
    bin.add(queue)
    bin.add(encoder)
    bin.add(output)
    interleave.link(queue)
    queue.link(encoder)
    encoder.link(output)
    if sinks == 1:
        interleave.set_property('channel_positions', [GstAudio.AudioChannelPosition.MONO])
        sink = interleave.get_request_pad('sink_0')
        ghostpad = Gst.GhostPad.new('sink_0', sink)
        bin.add_pad(ghostpad)
    elif sinks == 2:
        interleave.set_property('channel_positions', [
            GstAudio.AudioChannelPosition.FRONT_LEFT,
            GstAudio.AudioChannelPosition.FRONT_RIGHT
        ])
        sink0 = interleave.get_request_pad('sink_0')
        ghostpad0 = Gst.GhostPad.new('sink_0', sink0)
        sink1 = interleave.get_request_pad('sink_1')
        ghostpad1 = Gst.GhostPad.new('sink_1', sink1)
        bin.add_pad(ghostpad0)
        bin.add_pad(ghostpad1)
    return bin

这是创建新 bin 以将一个或两个通道写入磁盘的代码。当我只连接一个水槽垫(并将水槽设置为 1)时,一切仍然正常,但是当我连接两个水槽垫(并将水槽设置为 2)时,文件已创建但管道似乎卡住了。既没有打印出关卡,也没有将数据写入文件。

我已将完整文件附在要点中,这是原型代码,但在我重构它之前,我希望一切正常。

https://gist.github.com/maxjoehnk/16785499db6e864bf120cf85a81b1ecf

好的,Florian Zwoch 的评论就是线索。我为每个频道添加了一个队列,现在一切正常。所以我的 new_recorder_bin 函数现在看起来像这样:

def new_recorder_bin(path, sinks=1):
    bin = Gst.Bin()
    interleave = Gst.ElementFactory.make('interleave', None)
    encoder = Gst.ElementFactory.make('wavenc', None)
    output = Gst.ElementFactory.make('filesink', None)
    output.set_property('location', path)
    bin.add(interleave)
    bin.add(encoder)
    bin.add(output)
    interleave.link(encoder)
    encoder.link(output)
    if sinks == 1:
        queue = Gst.ElementFactory.make('queue', None)
        bin.add(queue)
        interleave.set_property('channel_positions', [GstAudio.AudioChannelPosition.MONO])
        sink = interleave.get_request_pad('sink_0')
        queueSink = queue.get_static_pad('sink')
        queueSrc = queue.get_static_pad('src')
        queueSrc.link(sink)
        ghostpad = Gst.GhostPad.new('sink_0', queueSink)
        bin.add_pad(ghostpad)
    elif sinks == 2:
        queue0 = Gst.ElementFactory.make('queue', 'Queue L')
        queue1 = Gst.ElementFactory.make('queue', 'Queue R')
        bin.add(queue0)
        bin.add(queue1)
        interleave.set_property('channel_positions', [
            GstAudio.AudioChannelPosition.FRONT_LEFT,
            GstAudio.AudioChannelPosition.FRONT_RIGHT
        ])
        sink0 = interleave.get_request_pad('sink_0')
        queueSink0 = queue0.get_static_pad('sink')
        queueSrc0 = queue0.get_static_pad('src')
        queueSrc0.link(sink0)
        ghostpad0 = Gst.GhostPad.new('sink_0', queueSink0)
        sink1 = interleave.get_request_pad('sink_1')
        queueSink1 = queue1.get_static_pad('sink')
        queueSrc1 = queue1.get_static_pad('src')
        queueSrc1.link(sink1)
        ghostpad1 = Gst.GhostPad.new('sink_1', queueSink1)
        bin.add_pad(ghostpad0)
        bin.add_pad(ghostpad1)
    return bin

这不是特别干净,但似乎工作正常所以现在我会坚持使用它。