您需要安装2件东西
- pafy(pip安装pafy)
- youtube_dl(sudo pip install –upgrade youtube_dl)
安装完这两个软件包后,您可以使用youtube网址播放youtube上的流视频。请参考下面的代码
url = 'https://youtu.be/W1yKqFZ34y4'vPafy = pafy.new(url)play = vPafy.getbest(preftype="webm")#start the videocap = cv2.VideoCapture(play.url)while (True): ret,frame = cap.read() """ your pre here """ cv2.imshow('frame',frame) if cv2.waitKey(20) & 0xFF == ord('q'): breakcap.release()cv2.destroyAllWindows()


