gpt4 book ai didi

python - 如何使用 openCV python 读取 Youtube 直播?

转载 作者:太空宇宙 更新时间:2023-11-03 14:06:35 25 4
gpt4 key购买 nike

我想从 youtube 读取实时流来执行一些基本的 CV 操作,可能我们必须以某种方式剥离 youtube URL 以将其转换为 openCV 可能可读的格式,例如?:

cap = cv2.VideoCapture('https://www.youtube.com/watch?v=_9OBhtLA9Ig')

有人做过吗?

最佳答案

我相信您现在已经知道答案了,但我会为搜索相同主题的其他人解答。您可以使用 Pafy 来完成此操作

(可能与 youtube_dl 一起)。

import pafy
import cv2

url = "https://www.youtube.com/watch?v=_9OBhtLA9Ig"
video = pafy.new(url)
best = video.getbest(preftype="mp4")

capture = cv2.VideoCapture(best.url)
while True:
grabbed, frame = capture.read()
# ...

应该就是这样。

关于python - 如何使用 openCV python 读取 Youtube 直播?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43032163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com