Python 2.7 stream live twitch video in tkinter window using cv2 and livestreamer

499 views Asked by At

I currently using cv2 to display the video from my webcam into a tkinter window.

import Tkinter as tk
from livestreamer import Livestreamer
import numpy as np
import cv2
from PIL import Image, ImageTk

from page import Page

class PageThree(Page):
   def __init__(self, *args, **kwargs):
      Page.__init__(self, *args, **kwargs)


      session = Livestreamer()
      stream = session.streams('http://www.twitch.tv/riotgames')
      stream = stream['source']
      fd = stream.open()

      #Capture video frames
      lmain = tk.Label(self)
      lmain.grid(row=0, column=0)
      cap = cv2.VideoCapture(0)
      def show_frame():
          _, frame = cap.read()
          frame = cv2.flip(frame, 1)
          cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
          img = Image.fromarray(cv2image)
          imgtk = ImageTk.PhotoImage(image=img)
          lmain.imgtk = imgtk
          lmain.configure(image=imgtk)
          lmain.after(10, show_frame) 

      show_frame()

Is there a way to using livestreamer to be able to have the video feed as a stream from Twitch user livestreamer?

0

There are 0 answers