当我尝试使用opencv和camgear从youtube直播时,出现以下错误

时间:2019-06-17 07:56:13

标签: python python-3.x opencv live-streaming

我想从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!

2 个答案:

答案 0 :(得分:0)

enter image description here

我尝试运行您的脚本,但URL链接出现错误,但是当我替换为其他URL链接时,您的脚本运行正常,没有错误。看照片

答案 1 :(得分:0)

@Adithya Raj我是 VidGear视频处理python库的作者。

此错误是由于YouTube实时流存在错误,已在此commit中得到解决。请参见问题#16,其解决方案在我的comment中。祝你好运!