Python 从live Twitch.tv频道下载帧
我正在寻找将当前帧从指定的live Twitch.tv频道保存到磁盘的方法。欢迎使用任何编程语言Python 从live Twitch.tv频道下载帧,python,video,video-capture,Python,Video,Video Capture,我正在寻找将当前帧从指定的live Twitch.tv频道保存到磁盘的方法。欢迎使用任何编程语言 到目前为止,我已经找到了一个使用Python的可能解决方案,但不幸的是,它不起作用 import time, Image import cv2 from livestreamer import Livestreamer # change to a stream that is actually online livestreamer = Livestreamer() plugin = live
到目前为止,我已经找到了一个使用Python的可能解决方案,但不幸的是,它不起作用
import time, Image
import cv2
from livestreamer import Livestreamer
# change to a stream that is actually online
livestreamer = Livestreamer()
plugin = livestreamer.resolve_url("http://twitch.tv/flosd")
streams = plugin.get_streams()
stream = streams['best']
# download enough data to make sure the first frame is there
fd = stream.open()
data = ''
while len(data) < 3e5:
data += fd.read()
time.sleep(0.1)
fd.close()
fname = 'stream.bin'
open(fname, 'wb').write(data)
capture = cv2.VideoCapture(fname)
imgdata = capture.read()[1]
imgdata = imgdata[...,::-1] # BGR -> RGB
img = Image.fromarray(imgdata)
img.save('frame.png')
导入时间,图像
进口cv2
从livestreamer导入livestreamer
#更改为实际在线的流
livestreamer=livestreamer()
plugin=livestreamer.resolve_url(“http://twitch.tv/flosd")
streams=plugin.get_streams()
stream=streams['best']
#下载足够的数据以确保第一帧存在
fd=stream.open()
数据=“”
而len(数据)<3e5:
data+=fd.read()
睡眠时间(0.1)
fd.close()
fname='stream.bin'
打开(fname,'wb')。写入(数据)
捕获=cv2.视频捕获(fname)
imgdata=capture.read()[1]
imgdata=imgdata[…,:-1]#BGR->RGB
img=Image.fromarray(imgdata)
img.save('frame.png')
显然,cv2.VideoCapture(fname)没有返回任何消息,尽管它成功地将大约300K的信息写入了流中。bin可能是个愚蠢的问题,但是当您尝试运行脚本时twitch流是活的吗?
bin
的内容是什么样子的?流是活动的。为了避免上传另一个文件,您可以使用代码作者提供的文件。我无法在我的bin
上调用read(),也无法在bin文件上调用read(),因为无法正确访问ffmpeg(视频解码器),因此打开文件失败。请参阅和类似内容。我通过从这里下载和安装opencv进行了修复: