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

标签 python caching ffmpeg http-live-streaming streamlink

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

相关文章:

python - 在redis中,如何删除一个键并同时获取它的值

python - python中href url中的正则表达式编号

c++ - 确定具有可变元素的优先级队列的最佳 ADT (C++)

asp.net - 您对依赖于数据库的 ASP.NET 应用程序使用什么缓存策略?

performance - 确定 PostgreSQL 查询是从磁盘还是从内存缓存运行的?

c - 如何在 ffmpeg 中获取音频 AVStream 的字符串表示形式?

python - 管理 Mac OS 在 Windows 环境中使用非 ASCII 字符创建的文件名?

python - 运行的 uwsgi 线程过多

ffmpeg - 使用ffmpeg垂直或水平堆叠(马赛克)几个视频?

streaming - 如何使用 `m4v` 将视频转换为 `ffmpeg` ?