0

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?

O R
  • 9
  • 6

1 Answers1

1

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()

https://github.com/streamlink/streamlink/blob/6a30ed7524eff2cdb205e024294b187cb660e4e3/examples/opencv-face.py#L40

gazi ahmet
  • 36
  • 2
  • Upon further testing, I am seeing that this code performs significantly worse than Streamlink console commands and the VLC player. I am getting a lot of stuttering and missing frames. For some reason, on MacOS, the stream is playing in slow motion. Any ideas? – O R Apr 05 '21 at 16:05