gpt4 book ai didi

python - VideoCapture 在 Python OPENCV [Linux] 中总是返回 False

转载 作者:太空宇宙 更新时间:2023-11-04 12:31:29 25 4
gpt4 key购买 nike

每次我使用 VideoCapture 尝试访问视频文件中的帧时,返回值 (ret) 都是 false。请参阅下面的示例代码:

cap = cv2.VideoCapture('asd.mkv')
vid = []
while True:
ret, img = cap.read()
if not ret: # Always happens
break
vid.append(cv2.resize(img, (171, 128)))

我已经尝试了今天通过谷歌搜索所能找到的所有内容,包括 OpenCV guidethis long issue在 Github 上。此外,我阅读了一些涉及移动 ffmpeg dll 文件的解决方案,但那只是在 Windows 的情况下。

有什么想法吗?因为我肯定用完了。

最佳答案

供将来引用:使用 pip 安装 opencv 不适用于 ffmpeg。

来自opencv-python FAQ :

Q: Why I can’t open video files on GNU/Linux distribution X or on macOS?

A: OpenCV video I/O depends heavily on FFmpeg. Manylinux and macOS OpenCV binaries are not compiled against it. The purpose of these packages is to provide as easy as possible installation experience for OpenCV Python bindings and they should work directly out-of-the-box. Adding FFmpeg as an additional dependency without a “universal” FFmpeg build (e.g. LGPL licensed build like in the Windows wheels) the goal is considerably harder to achieve. This might change in the future.

解决方案:

  1. Build from source (docs) .这对我有用。
  2. Use scikit-video as a workaround (Github) .

关于python - VideoCapture 在 Python OPENCV [Linux] 中总是返回 False,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43176029/

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