【发布时间】:2020-06-19 04:20:36
【问题描述】:
现在我正在使用 steamlink 和 ffmpeg 来录制流并将它们保存到一个文件中,很多时候保存的视频文件都有很多延迟。我找到了这个链接https://www.reddit.com/r/Twitch/comments/62601b/laggy_stream_on_streamlinklivestreamer_but_not_on/
他们声称延迟问题是由于没有在播放器上启用缓存而导致的。
我尝试输入选项-hls_allow_cache allowcache -segment_list_flags cache,结果ffmpeg进程开始或多或少8秒,之后它结束并立即重新开始而不返回视频文件,如果我不输入这两个选项视频被正确录制但大多数时候会有一些滞后。
显然,如果我从浏览器访问流媒体,我没有延迟问题
这是代码
from streamlink import Streamlink, NoPluginError, PluginError
streamlink = Streamlink()
#this code is just a snippet, it is inside a while loop to restart the process
try:
streams = streamlink.streams(m3u8_url)
stream_url = streams['best'].url
#note hls options not seem to work
ffmpeg_process = Popen(
["ffmpeg", "-hide_banner", "-loglevel", "panic", "-y","-hls_allow_cache", "allowcache", "-segment_list_flags", "cache","-i", stream_url, "-fs", "10M", "-c", "copy",
"-bsf:a", "aac_adtstoasc", fileName])
ffmpeg_process.wait()
except NoPluginError:
print("noplugin")
except PluginError:
print("plugin")
except Exception as e:
print(e)
启用缓存和尽可能限制延迟的最佳选项是什么?
【问题讨论】:
标签: python caching ffmpeg http-live-streaming streamlink