在python的gstreamer中使用speex的问题

2024-10-02 04:25:16 发布

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

不幸的是,后来我尝试用python和treamer进行流媒体编码。在

我找到了一个简单的音频播放器,效果很好:

import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst, Gtk

# Initializing threads used by the Gst various elements
GObject.threads_init()
#Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.
Gst.init(None)

class Main:
    def __init__(self):
        self.mainloop = GObject.MainLoop()
        #Creating the gst pipeline we're going to add elements to and use to play the file
        self.pipeline = Gst.Pipeline()

        #creating the filesrc element, and adding it to the pipeline
        self.filesrc = Gst.ElementFactory.make("filesrc", "filesrc")
        self.filesrc.set_property("location", "beatles.mp3")
        self.pipeline.add(self.filesrc)

        #creating and adding the decodebin element , an "automagic" element able to configure itself to decode pretty much anything
        self.decode = Gst.ElementFactory.make("decodebin", "decode")
        self.pipeline.add(self.decode)
        #connecting the decoder's "pad-added" event to a handler: the decoder doesn't yet have an output pad (a source), it's created at runtime when the decoders starts receiving some data
        self.decode.connect("pad-added", self.decode_src_created)

        #setting up (and adding) the alsasin, which is actually going to "play" the sound it receives
        self.sink = Gst.ElementFactory.make("alsasink", "sink")
        self.pipeline.add(self.sink)

        #linking elements one to another (here it's just the filesrc - > decoder link , the decoder -> sink link's going to be set up later)
        self.filesrc.link(self.decode)

    #handler taking care of linking the decoder's newly created source pad to the sink
    def decode_src_created(self, element, pad):
        pad.link(self.sink.get_static_pad("sink"))

    #running the shit
    def run(self):
        self.pipeline.set_state(Gst.State.PLAYING)
        self.mainloop.run()

start=Main()
start.run()

然后我尝试在中间添加一个speexnc和一个speexdec元素。见6行“#已添加”和1行“#修改”。我知道在这种特殊情况下,通过speex进行编码和解码是没有实际意义的,但是由于python3.x中缺乏这方面的教程和示例,我想在阅读了基本的gstreamer文档和常见问题解答之后开始尝试。虽然没有错误消息,但最终它什么也不播放,而且演讲者也沉默不语:

^{pr2}$

任何使其最终生效的建议都将不胜感激! 先谢谢你!在

编辑:GST的输出\u DEBUG=“*:3”

** (GsTest04.py:2500): WARNING **: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files
0:00:00.310035438  2500  0x25b7290 FIXME                  id3v2      gstid3tag.c:142:gst_tag_from_id3_tag: Cannot map ID3v2 tag 'PRIV' to GStreamer tag
0:00:00.310425594  2500  0x25b7290 FIXME                  id3v2 gstid3tag.c:142:gst_tag_from_id3_tag: Cannot map ID3v2 tag 'PRIV' to GStreamer tag
0:00:00.310597677  2500  0x25b7290 FIXME                  id3v2 gstid3tag.c:142:gst_tag_from_id3_tag: Cannot map ID3v2 tag 'PRIV' to GStreamer tag
0:00:00.310753458  2500  0x25b7290 FIXME                  id3v2 gstid3tag.c:142:gst_tag_from_id3_tag: Cannot map ID3v2 tag 'PRIV' to GStreamer tag
0:00:00.310931687  2500  0x25b7290 FIXME                  id3v2 gstid3tag.c:142:gst_tag_from_id3_tag: Cannot map ID3v2 tag 'PRIV' to GStreamer tag
0:00:00.311063614  2500  0x25b7290 FIXME                  id3v2 gstid3tag.c:142:gst_tag_from_id3_tag: Cannot map ID3v2 tag 'PRIV' to GStreamer tag
0:00:00.311322155  2500  0x25b7290 FIXME                  id3v2 gstid3tag.c:142:gst_tag_from_id3_tag: Cannot map ID3v2 tag 'PRIV' to GStreamer tag
0:00:00.376435699  2500 0x741014f0 WARN                    alsa conf.c:4544:parse_args: alsalib error: Unknown parameter AES0
0:00:00.376732365  2500 0x741014f0 WARN                    alsa conf.c:4704:snd_config_expand: alsalib error: Parse arguments error: No such file or directory
0:00:00.376897261  2500 0x741014f0 WARN                    alsa pcm.c:2217:snd_pcm_open_noupdate: alsalib error: Unknown PCM default:{AES0 0x02 AES1 0x82 AES2 0x00 AES3 0x02}
0:00:00.378137573  2500 0x741014f0 WARN               baseparse gstbaseparse.c:3188:gst_base_parse_loop:<mpegaudioparse0> error: streaming stopped, reason not-linked

Tags: thetofromselfpipelinetagdecodepad
1条回答
网友
1楼 · 发布于 2024-10-02 04:25:16

我看不出有什么明显的错误。我建议使用GST_DEBUG=“*:3”运行程序,以查看日志中是否有任何警告。您可能还需要再次检查所有api调用是否有效。(例如

self.speexenc = Gst.ElementFactory.make(...)

未导致None。我还要检查返回值连接垫()在解码中创建。如果解码器产生的原始音频不是speexec喜欢的,链接将失败。尝试在speexenc之前添加audioconvert元素。在

相关问题 更多 >

    热门问题