好吧,我知道了。确保将其写入二进制数据,并且OpenCV能够解码第一个视频帧。生成的图像具有切换的R和B通道,但是很容易校正。下载大约300
kB似乎足以确保有完整的图像。
import time, Imageimport cv2from livestreamer import Livestreamer# change to a stream that is actually onlinelivestreamer = Livestreamer()plugin = livestreamer.resolve_url("http://twitch.tv/flosd")streams = plugin.get_streams()stream = streams['mobile_High']# download enough data to make sure the first frame is therefd = 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 -> RGBimg = Image.fromarray(imgdata)img.save('frame.png')# img.show()


