【问题标题】:Downloading a live Twitch stream下载实时 Twitch 流
【发布时间】:2019-02-23 16:41:07
【问题描述】:

我正在寻找一种在流式传输时将 Twitch 流式传输到文件中的方法(对不起,如果我在这里扼杀了术语)。我知道可以在流完成后下载 VOD,但这不适用于我的用例。

我查看了一个名为 streamlink 的库,它可以让我获得给定流的确切 url,但我有点不知道从这里去哪里

【问题讨论】:

    标签: video-streaming twitch


    【解决方案1】:

    youtube-dl 提供了一个从流 URL 获取播放列表的接口。以下 1 班轮运作良好:

    ffmpeg -i $( youtube-dl -f best --get-url twitch.tv/host ) -codec copy "out.mp4"

    还有一个twitch-dl 实用程序我没试过。

    【讨论】:

      【解决方案2】:

      这是一个对我有用的解决方案:

      首先,安装Streamlink。然后运行这个命令

      streamlink -o <file name>.mkv <URL of the Twitch stream> best

      将流保存到本地文件。

      如果您想以编程方式实现此目的,您可以将 Streamlink pip 模块 (pip install streamlink) 与 ffmpeg 结合使用。

      下面是代码的样子(在 Python 3 中):

      import streamlink
      from subprocess import Popen
      from time import sleep
      
      # get the URL of .m3u8 file that represents the stream
      stream_url = streamlink.streams('https://www.twitch.tv/forsen')['best'].url
      print(stream_url)
      
      # now we start a new subprocess that runs ffmpeg and downloads the stream
      ffmpeg_process = Popen(["ffmpeg", "-i", stream_url, "-c", "copy", 'stream.mkv'])
      
      # we wait 60 seconds
      sleep(60)
      
      # terminate the process, we now have ~1 minute video of the stream
      ffmpeg_process.kill()
      

      【讨论】:

        猜你喜欢
        • 2014-10-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-13
        • 1970-01-01
        相关资源
        最近更新 更多