从现场Twitch.tv频道下载帧

时间:2013-11-18 13:32:30

标签: python video video-capture

我正在寻找一种方法将当前帧从指定的实时Twitch.tv通道保存到磁盘。欢迎任何编程语言。


到目前为止,我已经找到了使用Python here的可能解决方案,但遗憾的是它不起作用。

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.VideoCapture(fname)虽然设法将大约300K的信息写入 stream.bin

,但仍然没有返回

0 个答案:

没有答案