使用带两个接收器的交错元素时Gst管道未运行

2024-06-01 03:18:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我对gstreamer管道中interleave元素的使用有问题。在

我把音频从一个输入端(autoaudiosrc)读入tee,这样我就可以把它写到磁盘上,并实时获得音频电平(将它与硬件vu表一起输入,在所附的代码片段中,它只是将电平打印到stdout)。我想能够使用任何1或2个频道,并将它们写入一个单独的文件,这样我就可以将6个输入频道分成5个文件(1个立体声,4个单声道)。 现在把所有的东西都写在一个文件里工作得很好,然后我添加了一个去隔行元素,把所有的东西都分成单声道文件,这也很好,但是把两个声道合并成一个立体声声道会破坏整个流程。在

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


Tags: 文件noneaddencodernewoutputmakebin
1条回答
网友
1楼 · 发布于 2024-06-01 03:18:45

好吧,所以Florian Zwoch的评论就是线索。我为每个通道添加了一个队列,现在一切正常。所以我的新的“录音机”功能现在看起来是这样的:

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

这不是特别干净,但它似乎工作得很好,所以现在我将坚持它。在

相关问题 更多 >