# The YouTube url or 11 character video id of the video url_video = 'https://youtu.be/2kS0T7fwxJo' # Preferred type, set to mp4, webm, flv, 3gp or any # 把分享的视频地址,转化为 .mp4 地址,如何 cv2.VideoCapture() 直接读取 v = pafy.new(url_video).getbestvideo(preftype='mp4') # 如果地址是"*.mp4"的,可以直接读取 vc = cv2.VideoCapture(v.url)
if vc.isOpened(): open = True else: open = False flag = 0 whileopen: ret, frame = vc.read() if frame isNone: break if ret: gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) flag += 1 vc.release() "total frame is ", flag