How to read Youtube live stream using openCV python?

陌路散爱 提交于 2020-01-01 06:35:05

问题


I want to read a live stream from youtube to perform some basic CV things, probably we have to somehow strip of the youtube URL to convert it in a format that might be readable by openCV like?:

cap = cv2.VideoCapture('https://www.youtube.com/watch?v=_9OBhtLA9Ig')

has anyone done it?


回答1:


I am sure you already know the answer by now, but I will answer for others searching the same topic. You can do this by using Pafy. First you need to import pafy

Then add this

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

capture = cv2.VideoCapture()
capture.open(best.url)

And that should be it.



来源:https://stackoverflow.com/questions/43032163/how-to-read-youtube-live-stream-using-opencv-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!