我想从youtube获得实时流,为此,我使用了opencv和vidgear软件包。但是在运行代码时,出现以下错误。我确定网址没有问题。
我尝试使用pafy和streamlink。即使两者都给出了结果,但是在几帧之后,它仍然卡住了,我希望连续的帧没有任何暂停。
import cv2
from vidgear.gears import CamGear
stream = CamGear(source="https://www.youtube.com/watch?v=VIk_6OuYkSo", y_tube =True, time_delay=1, logging=True).start() # YouTube Video URL as input
while True:
frame = stream.read()
if frame is None:
break
cv2.imshow("Output Frame", frame)
key = cv2.waitKey(30)
if key == ord("q"):
break
cv2.destroyAllWindows()
stream.stop()
错误输出::
'NoneType' object has no attribute 'extension'
Traceback (most recent call last):
File "C:\Users\CamfyVision\AppData\Local\Programs\Python\Python36\lib\site-packages\vidgear\gears\camgear.py", line 120, in __init__
print('Extension: {}'.format(_source.extension))
AttributeError: 'NoneType' object has no attribute 'extension'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "DronrStream.py", line 4, in <module>
stream = CamGear(source="https://www.youtube.com/watch?v=VIk_6OuYkSo", y_tube =True, time_delay=1, logging=True).start() # YouTube Video URL as input
File "C:\Users\CamfyVision\AppData\Local\Programs\Python\Python36\lib\site-packages\vidgear\gears\camgear.py", line 125, in __init__
raise ValueError('YouTube Mode is enabled and the input YouTube Url is invalid!')
ValueError: YouTube Mode is enabled and the input YouTube Url is invalid!