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

问题描述 投票:0回答:3

我想从 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!
python python-3.x opencv live-streaming
3个回答
1
投票

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

此错误是由于 YouTube 直播的错误造成的,并且已在此 commit 中得到解决。请按如下方式更新vidgear:

pip install -U vidgear

0
投票

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


0
投票

问题解决了吗??出了什么问题?

© www.soinside.com 2019 - 2024. All rights reserved.