首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >下载实时Twitch流

下载实时Twitch流
EN

Stack Overflow用户
提问于 2019-02-24 00:41:07
回答 2查看 6.1K关注 0票数 1

我正在寻找一种方法来“管道”一个Twitch流到一个文件中,因为它正在被流传送(抱歉,如果我在这里胡乱使用术语)。我知道可以在流完成后下载VODs,但这在我的用例中不适用。

我看过一个名为streamlink的库,它可以让我获得给定流的确切url,但是我有点迷茫,不知道从哪里开始

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-03-17 00:06:48

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

首先,安装Streamlink。然后只需运行以下命令

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

将流保存到本地文件。

如果你想通过编程来实现这一点,你可以结合ffmpeg使用Streamlink pip模块(pip install streamlink)。

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

代码语言:javascript
复制
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()
票数 2
EN

Stack Overflow用户

发布于 2020-10-10 10:38:16

youtube-dl提供了用于从流URL获取播放列表的接口。下面的1个衬垫运行良好:

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

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54843726

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档