gpt4 book ai didi

python - 在 ffmpeg 上启用缓存以记录流式传输

转载 作者:行者123 更新时间:2023-12-03 20:26:21 29 4
gpt4 key购买 nike

现在我正在使用 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)

启用缓存和尽可能限制延迟的最佳选择是什么?

最佳答案

您可以阅读FFmpeg StreamingGuide有关延迟的更多详细信息。例如,您有

an option -fflags nobuffer which might possibly help, usually for receiving streams ​reduce latency.



如您所见 here关于 nobuffer

Reduce the latency introduced by buffering during initial input streams analysis.

关于python - 在 ffmpeg 上启用缓存以记录流式传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60563927/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com