首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PyGst / GStreamer不播放音频,命令行确定

PyGst / GStreamer不播放音频,命令行确定
EN

Stack Overflow用户
提问于 2018-10-29 00:16:24
回答 1查看 394关注 0票数 0

我是GObject,GStreamer,GI等的新手.我的mac跑得很高.

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

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

我无法在python代码中进行模拟。

它正在返回以下错误

代码语言:javascript
复制
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)')

代码语言:javascript
复制
#!/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)

有什么指示吗?谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-10-30 08:39:05

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

例:

代码语言:javascript
复制
PIPE = """ filesrc location=test.mp3 ! decodebin ! audioconvert !  autoaudiosink """

然后:

代码语言:javascript
复制
pipeline = Gst.parse_launch(PIPE)

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53037244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档