在docker image中使用NVIDIA GPU硬件加速构建FFmpeg,无法加载libnvcuvid.so.1和libnvidia-encode.so,1

bvuwiixz  于 2023-03-29  发布在  Docker
关注(0)|答案(1)|浏览(1115)

我正在尝试按照以下说明使用NVIDIA GPU硬件加速构建FFmpeg:https://docs.nvidia.com/video-technologies/video-codec-sdk/ffmpeg-with-nvidia-gpu/index.html#compiling-for-linux。我使用的Docker镜像是nvidia/cuda:12.0.1-devel-ubuntu20.04
运行测试命令ffmpeg -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -i bbb.mp4 -c:a copy -c:v h264_nvenc -b:v 5M output.mp4,得到以下输出:

ffmpeg version N-109965-ge50a02b0f6 Copyright (c) 2000-2023 the FFmpeg developers                                                                                                                                                                                               
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)                                                                                                                                                                                                                              
  configuration: --enable-nonfree --enable-cuda-nvcc --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 --disable-static --enable-shared                                                                                          
  libavutil      58.  3.100 / 58.  3.100                                                                                                                                                                                                                                        
  libavcodec     60.  6.100 / 60.  6.100                                                                                                                                                                                                                                        
  libavformat    60.  4.100 / 60.  4.100                                                                                                                                                                                                                                        
  libavdevice    60.  2.100 / 60.  2.100                                                                                                                                                                                                                                        
  libavfilter     9.  4.100 /  9.  4.100                                                                                                                                                                                                                                        
  libswscale      7.  2.100 /  7.  2.100                                                                                                                                                                                                                                        
  libswresample   4. 11.100 /  4. 11.100                                                                                                                                                                                                                                        
-vsync is deprecated. Use -fps_mode                                                                                                                                                                                                                                             
Passing a number to -vsync is deprecated, use a string argument as described in the manual.                                                                                                                                                                                     
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'bbb.mp4':                                                                                                                                                                                                                              
  Metadata:                                                                                                                                                                                                                                                                     
    major_brand     : isom                                                                                                                                                                                                                                                      
    minor_version   : 1                                                                                                                                                                                                                                                         
    compatible_brands: isomavc1                                                                                                                                                                                                                                                 
    creation_time   : 2013-12-16T17:44:39.000000Z                                                                                                                                                                                                                               
    title           : Big Buck Bunny, Sunflower version                                                                                                                                                                                                                         
    artist          : Blender Foundation 2008, Janus Bager Kristensen 2013                                                                                                                                                                                                      
    comment         : Creative Commons Attribution 3.0 - http://bbb3d.renderfarming.net                                                                                                                                                                                         
    genre           : Animation                                                                                                                                                                                                                                                 
    composer        : Sacha Goedegebure                                                                                                                                                                                                                                         
  Duration: 00:10:34.60, start: 0.000000, bitrate: 3481 kb/s                                                                                                                                                                                                                    
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 2998 kb/s, 30 fps, 30 tbr, 30k tbn (default)
    Metadata:                                                                                                                           
      creation_time   : 2013-12-16T17:44:39.000000Z                                                                                     
      handler_name    : GPAC ISO Video Handler                                                                                          
      vendor_id       : [0][0][0][0]                                                                                                    
  Stream #0:1[0x2](und): Audio: mp3 (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 160 kb/s (default)                                     
    Metadata:                                                                                                                           
      creation_time   : 2013-12-16T17:44:42.000000Z                                                                                     
      handler_name    : GPAC ISO Audio Handler                                                                                          
      vendor_id       : [0][0][0][0]                                                                                                                                                                                                                                            
  Stream #0:2[0x3](und): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 320 kb/s (default)                                                                                                                                                                          
    Metadata:                                                                                                                                                                                                                                                                   
      creation_time   : 2013-12-16T17:44:42.000000Z                                                                                                                                                                                                                             
      handler_name    : GPAC ISO Audio Handler                                                                                                                                                                                                                                  
      vendor_id       : [0][0][0][0]                                                                                                                                                                                                                                            
    Side data:                                                                                                                                                                                                                                                                  
      audio service type: main                                                                                                                                                                                                                                                  
Stream mapping:                                                                                                                                                                                                                                                                 
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_nvenc))                                                                                                                                                                                                                      
  Stream #0:2 -> #0:1 (copy)                                                                                                                                                                                                                                                    
Press [q] to stop, [?] for help                                                                                                                                                                                                                                                 
[h264 @ 0x55bd878c2d80] Cannot load libnvcuvid.so.1                                                                                                                                                                                                                             
[h264 @ 0x55bd878c2d80] Failed loading nvcuvid.                                                                                                                                                                                                                                 
[h264 @ 0x55bd878c2d80] Failed setup for format cuda: hwaccel initialisation returned error.                                                                                                                                                                                    
[h264_nvenc @ 0x55bd86f5e680] Cannot load libnvidia-encode.so.1                                                                                                                                                                                                                 
[h264_nvenc @ 0x55bd86f5e680] The minimum required Nvidia driver for nvenc is 520.56.06 or newer                                                                                                                                                                                
[vost#0:0/h264_nvenc @ 0x55bd86f5e1c0] Error initializing output stream: Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

nvidia-smi的输出:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.85.05    Driver Version: 525.85.05    CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:01:00.0  On |                  N/A |
| 27%   43C    P8    12W / 250W |    500MiB / 11264MiB |      1%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

共享库不是docker镜像的一部分。我有什么选项可以添加它们?

mu0hgdu0

mu0hgdu01#

检查您的nvidia-container-runtime参数。对于NVENC,您需要启用video功能。docker运行示例:

docker run --gpu all,capabilities=video -it nvidia/cuda:12.0.1-devel-ubuntu20.04 /bin/bash

在docker-compose.yml中,deploy/resources/reservations/devices/capabilities下必须包含值video

version: '2.2'
services:
  name_of_your_service:
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              device_ids: ['0']
              capabilities: [gpu,video]

Empty(或者只有gpu值)将无法链接NVENC,导致上面的错误。我认为特权模式也会启用所有gpu功能。默认的apt pre-build ffmpeg ubunutu包确实可以与NVENC一起使用,但在docker中需要相同的功能步骤。否则,您会得到此错误:

Cannot load libnvidia-encode.so.1
The minimum required Nvidia driver for nvenc is 470.57.02 or newer
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

有关详细信息,请参见https://github.com/NVIDIA/nvidia-container-runtime

相关问题