代码之家  ›  专栏  ›  技术社区  ›  Anil_M

PyGst/GStreamer未播放音频,命令行正常

  •  0
  • Anil_M  · 技术社区  · 6 年前

    我是GObject、GStreamer、GI等的新手。 我让mac跑得很高。

    虽然我能够成功运行测试音频文件,如下所示。

    gst-launch-1.0 filesrc location=test.mp3 ! decodebin ! audioconvert ! autoaudiosink

    我无法在python代码中模拟同样的情况。
    它返回以下错误

    python ccc.py
    <Gst.Message object at 0x10ebb59a8 (GstMessage at 0x7fde5688b740)>
    <flags GST_MESSAGE_ERROR of type Gst.MessageType>
    (gerror=GLib.Error('Internal data stream error.', 'gst-stream-error-quark', 1), debug='gstbaseparse.c(3611): void gst_base_parse_loop(GstPad *) (): /GstPipeline:pipeline0/GstDecodeBin:decodebin/GstMpegAudioParse:mpegaudioparse0:\nstreaming stopped, reason not-linked (-1)')
    

    密码

    #!/usr/bin/python
    
    import gi
    
    gi.require_version('Gst', '1.0')
    
    from gi.repository import  GLib, GObject
    from gi.repository import  Gst as gst
    
    #Initialize Go Objects
    GObject.threads_init()
    gst.init(None)
    
    # Create the pipeline for our elements.
    pipe = gst.Pipeline()
    
    source = gst.ElementFactory.make("filesrc", "file-source")
    source.set_property("location", "test.wav")
    
    decoder = gst.ElementFactory.make("decodebin","decodebin")
    converter = gst.ElementFactory.make("audioconvert","audioconvert")
    audiosink = gst.ElementFactory.make("autoaudiosink", "audiosink")
    
    
    # Ensure all elements were created successfully.
    if (not pipe or not source or not decoder or not audiosink):
        print('Not all elements could be created.')
        exit(-1)
    
    #Add elements to pipeline
    pipe.add(source)
    pipe.add(decoder)
    pipe.add(converter)
    pipe.add(audiosink)
    
    #Link our elements together.
    source.link(decoder)
    decoder.link(converter)
    converter.link(audiosink)
    
    # Set our pipelines state to Playing.
    pipe.set_state(gst.State.PLAYING)
    
    # Wait until error or EOS.
    bus = pipe.get_bus()
    
    msg = bus.timed_pop_filtered(gst.CLOCK_TIME_NONE,gst.MessageType.ERROR | gst.MessageType.EOS)
    print msg
    print msg.type
    print msg.parse_error()
    
    # Free resources.
    pipe.set_state(gst.State.NULL)
    

    有什么建议吗?谢谢

    1 回复  |  直到 6 年前
        1
  •  0
  •   gst    6 年前

    尝试使用 Gst.parse_launch ,以与在命令行中相同的方式直接输入完整的管道。

    如:

    PIPE = """ filesrc location=test.mp3 ! decodebin ! audioconvert !  autoaudiosink """
    

    然后:

    pipeline = Gst.parse_launch(PIPE)
    

    这比单独添加并将它们链接到管道要容易得多。