如果我运行以下命令,它可以完美运行:
gst-launch-1.0 souphttpsrc is-live=true location="$(youtube-dl --format m4a --get-url https://www.youtube.com/watch?v=ndl1W4ltcmg)" ! decodebin ! audioconvert ! autoaudiosink
但是,当我尝试在我的 Python 代码中实现它时:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os, gi, time
from threading import Thread
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GLib
Gst.init()
main_loop = GLib.MainLoop()
thread = Thread(target=main_loop.run)
thread.start()
url = os.popen(f"youtube-dl --format m4a --get-url https://www.youtube.com/watch?v=ndl1W4ltcmg").read()
player = Gst.parse_launch(f"souphttpsrc is-live=true location='{url}' ! decodebin ! audioconvert ! autoaudiosink")
player.set_state(Gst.State.PLAYING)
try:
while True:
time.sleep(0.1)
except KeyboardInterrupt:
pass
player.set_state(Gst.State.NULL)
main_loop.quit()
它给了我以下错误:
<块引用>(test.py:29787): GStreamer-CRITICAL **: 13:39:16.637: gst_query_set_uri: 断言 'gst_uri_is_valid (uri)' 失败 错误:gst-resource-error-quark:解析 URL 时出错。 (5)gstsouphttpsrc.c(1463):gst_soup_http_src_build_message():/GstPipeline:pipeline0/GstSoupHTTPSrc:souphttpsrc0:
有什么想法吗?
编辑: