0

我是 GObject 、 GStreamer 、 GI 等的新手。我的 mac 正在运行 high-sierra。

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

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)

任何指针?谢谢。

4

1 回答 1

0

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

例如:

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

接着:

pipeline = Gst.parse_launch(PIPE)

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

于 2018-10-30T08:39:05.970 回答