I need to run OpenCV-Python image recognition on live streams pulled from Twitch, using Streamlink, without writing the stream to disk. I have all my image recognition tested and ready to go (I tested using a win32api screen capture), and I've also got Streamlink successfully pulling streams using the cli commands it offers, but I need to be able to analyze the streams one frame at a time using OpenCV in a Python script.
My question is: how would I go about analyzing each frame of the Streamlink stream with OpenCV?
I think this code gives you an idea. You just need to get stream by streamlink and capture by openCV
def stream_to_url(url, quality='best'):
streams = streamlink.streams(url)
if streams:
return streams[quality].to_url()
else:
raise ValueError("No steams were available")
Main
def main(url, quality='best', fps=30.0):
stream_url = stream_to_url(url, quality)
cap = cv2.VideoCapture(stream_url)
frame_time = int((1.0 / fps) * 1000.0)
while True:
try:
ret, frame = cap.read()