gpt4 book ai didi

python - 无法使用 OpenCV 使用 cv2.CAP_FFMPEG 在 GPU 上解码视频

转载 作者:行者123 更新时间:2023-12-04 23:01:25 28 4
gpt4 key购买 nike

我正在尝试使用 OpenCV 获取视频列表的所有帧(大量 .mp4 视频)。为了加快这个过程,我想我可以使用 FFMPEG 和 Nvidia Video Codec SDK 来使用硬件加速解码(我的机器上有 T4 卡)。我的代码是这样的:

import os
os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"]="video_codec;h264_cuvid"
import cv2

ret = cv2.VideoCapture("input.mp4", cv2.CAP_FFMPEG)
while True:
x, y = ret.read()
if x:
continue
break
但是当我运行我的脚本时出现这些错误。
[ERROR:0] global /tmp/pip-req-build-afu9cjzs/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp (1086) open Could not find decoder 'h264_cuvid'
[ERROR:0] global /tmp/pip-req-build-afu9cjzs/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp (1109) open VIDEOIO/FFMPEG: Failed to initialize VideoCapture
我的 ffmpeg 配置, ffmpeg :
ffmpeg version N-102965-gf531a1a4e8 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
configuration: --enable-nonfree --enable-cuda --enable-cuvid --enable-nvdec --enable-cuda-nvcc --enable-nvenc --enable-libnpp --enable-shared --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
libavutil 57. 0.100 / 57. 0.100
libavcodec 59. 3.101 / 59. 3.101
libavformat 59. 4.100 / 59. 4.100
libavdevice 59. 0.100 / 59. 0.100
libavfilter 8. 0.103 / 8. 0.103
libswscale 6. 0.100 / 6. 0.100
libswresample 4. 0.100 / 4. 0.100
Hyper fast Audio and Video encoder
ffmpeg -hwaccels :
ffmpeg version N-102965-gf531a1a4e8 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
configuration: --enable-nonfree --enable-cuda --enable-cuvid --enable-nvdec --enable-cuda-nvcc --enable-nvenc --enable-libnpp --enable-shared --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
libavutil 57. 0.100 / 57. 0.100
libavcodec 59. 3.101 / 59. 3.101
libavformat 59. 4.100 / 59. 4.100
libavdevice 59. 0.100 / 59. 0.100
libavfilter 8. 0.103 / 8. 0.103
libswscale 6. 0.100 / 6. 0.100
libswresample 4. 0.100 / 4. 0.100
Hardware acceleration methods:
cuda
OpenCV版本 opencv-python==4.5.3.56

最佳答案

在我的设置中,我必须构建 ffmpeg 以启用 cuvid 支持。
您可以检查您的 ffmpeg 是否支持 cuvid:

# type this in terminal:
ffmpeg -decoders 2>/dev/null | grep h264_cuvid
# returns:
V..... h264_cuvid Nvidia CUVID H264 decoder (codec h264)
您的系统中还需要一些 nvidia 库:
# type this in terminal:
ldconfig -p 2>/dev/null | grep cuvid
# You should see something similar to below:
libnvcuvid.so.1 (libc6,x86-64) => /usr/lib/libnvcuvid.so.1
libnvcuvid.so (libc6,x86-64) => /usr/lib/libnvcuvid.so

关于python - 无法使用 OpenCV 使用 cv2.CAP_FFMPEG 在 GPU 上解码视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68435446/

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