【发布时间】:2019-10-27 21:45:28
【问题描述】:
我正在尝试使用 opencv 和 pafy 访问 youtube 视频。我按照这里给出的说明Is it possible to stream video from https:// (e.g. YouTube) into python with OpenCV? 。但是按照说明操作后,我得到了下面提到的错误- cv2.error: OpenCV(4.0.0) /io/opencv/modules/highgui/src/window.cpp:350: 错误: (-215:Assertion failed) size.width>0 && size.height>0在函数“imshow”中
import cv2
import pafy
url = "https://www.youtube.com/watch?v=_p9VEKecHKI"
live = pafy.new(url)
stream = live.getbest(preftype="mp4")
cap = cv2.VideoCapture(stream.url)
#cap = cv2.VideoCapture()
#cap.open(stream.url)
while True:
ret, frame = cap.read()
cv2.imshow('frame', frame)
if cv2.waitKey(1) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
我得到的错误 -
Traceback (most recent call last):
File "videoCapture.py", line 20, in <module>
cv2.imshow('frame', frame)
cv2.error: OpenCV(4.0.0) /io/opencv/modules/highgui/src/window.cpp:350: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'
当我在这一行给出 preftype="webm" -
stream = live.getbest(preftype="webm")
我得到以下错误 -
Traceback (most recent call last):
File "videoCapture.py", line 11, in <module>
cap = cv2.VideoCapture(stream.url)
AttributeError: 'NoneType' object has no attribute 'url'
【问题讨论】:
标签: python opencv youtube pafy