0

Is there a way to download a YouTube live stream as it's happening in real-time in Python?

My best guess would be to use Pafy. For example,

import pafy

url = "https://www.youtube.com/watch?v=_9OBhtLA9Ig"
video = pafy.new(url)
best = video.getbest(preftype="mp4")

However, I'm not sure if this works for live streams and how to download frames in real-time.

Or maybe using vidgear:

from vidgear.gears import CamGear

stream = CamGear(source='https://youtu.be/dQw4w9WgXcQ', stream_mode = True, logging=True).start()

while True:    
    frame = stream.read()

I'm also not sure if that works in real-time.

These code examples are borrowed from a related question: How to read Youtube live stream using openCV python?

I'd like to be able to process the frames in a while loop kind of like this:

while True:
    # The current frame in real-time
    frame = get_frame()
Sam Lerman
  • 301
  • 2
  • 8
  • 1
    why does the previous question not solve your problem? if it does, why do you ask? -- why do you speak of "downloading" when clearly you don't intend to save the file but decode it right away? – Christoph Rackwitz Aug 06 '22 at 14:24
  • Good points. I may have gotten the terminology wrong. I’m not familiar with either of these solutions, so I don’t know how compatible they are for real-time livestreams. – Sam Lerman Aug 06 '22 at 23:37

0 Answers0