PyGst / GStreamer не воспроизводит звук, командная строка в норме - PullRequest
0 голосов
/ 29 октября 2018

Я новичок в 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)

Есть указатели?Благодарю.

1 Ответ

0 голосов
/ 30 октября 2018

Попробуйте использовать Gst.parse_launch, чтобы напрямую ввести весь конвейер так же, как вы делаете это в командной строке.

Например:

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

А потом:

pipeline = Gst.parse_launch(PIPE)

Это гораздо проще, чем добавлять его по отдельности и связывать их с конвейером.

...