python gstreamer正在寻找https音频中断播放

y4ekin9u  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(219)

以下是脚本的第一部分:

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()

之后,我可以使用souphttpsrc:

player = Gst.parse_launch(f"souphttpsrc is-live=false location={url} ! decodebin ! audioconvert ! autoaudiosink")

或playbin:

player = Gst.parse_launch(f"playbin uri={url}")

然后启动,然后稍等:

player.set_state(Gst.State.PLAYING)
time.sleep(1)

最后,我试着及时寻找:

player.seek_simple(Gst.Format.TIME,  Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, 20 * Gst.SECOND)

或以字节为单位:

player.seek_simple(Gst.Format.BYTES,  Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, 120000)

以下是脚本的结尾:

try:
    while True:
        time.sleep(0.1)
except KeyboardInterrupt:
    pass

player.set_state(Gst.State.NULL)
main_loop.quit()

两者都返回true,但随着时间的推移,播放立即停止(状态也变为暂停,但切换回播放没有帮助)。但这可能与这个问题有关。
这就是为什么我尝试了字节,它在寻求120000字节后继续播放,但在不久之后停止(大约180000字节),这里的状态保持播放,但也没有声音。
有没有办法通过gstreamer查找流式音频?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题