How do I enable FFMPEG cuda acceleration?

Forum for questions and support relating to the 1.34.x releases only.
Post Reply
DonZalmrol
Posts: 19
Joined: Wed Jun 24, 2020 8:21 am

How do I enable FFMPEG cuda acceleration?

Post by DonZalmrol »

Hi,

I have an Nvidia NVS510 Quadro card which support CUDA. The drivers are installed and CUDA has been enabled.
  • NVIDIA-SMI 460.32.03
  • Driver Version: 460.32.03
  • CUDA Version: 11.2
NVCC output:

Code: Select all

/usr/local/cuda-11.2/bin/nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Jan_28_19:32:09_PST_2021
Cuda compilation tools, release 11.2, V11.2.142
Build cuda_11.2.r11.2/compiler.29558016_0
FFMPEG output:

Code: Select all

/usr/bin/ffmpeg -hwaccels
ffmpeg version 4.1.6-1~deb10u1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 8 (Debian 8.3.0-6)
  configuration: --prefix=/usr --extra-version='1~deb10u1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
Hardware acceleration methods:
vdpau
vaapi
drm
As you can see CUDA is not listed in my FFMPEG acceleration output. How do I enable this?
When I do google searches you come out on various sources saying that you need to recompile it to include the cuda support.

However they do not inform you on how you can do it and test it...
lightguy48
Posts: 101
Joined: Sun Nov 15, 2015 7:19 pm

Re: How do I enable FFMPEG cuda acceleration?

Post by lightguy48 »

I followed the instructions on this page, skipping the notes regarding a VMWare environment -

https://wiki.zoneminder.com/GPU_passthrough_in_VMWare

So basically starting with the NVIDIA drivers and CUDA section

I did notice a slight improvement in Load values but it wasn't a night and day difference.
DonZalmrol
Posts: 19
Joined: Wed Jun 24, 2020 8:21 am

Re: How do I enable FFMPEG cuda acceleration?

Post by DonZalmrol »

Does this also applies to none VMWare ESX servers?
I have ZM running dedicated on a custom server with latest Debian installed (no virtualization).

I've tried this source, but to no avail.
https://www.reddit.com/r/ZoneMinder/com ... _with_gpu/
DonZalmrol
Posts: 19
Joined: Wed Jun 24, 2020 8:21 am

Re: How do I enable FFMPEG cuda acceleration?

Post by DonZalmrol »

I was able to install libnvidia-encode1 on my Debian as an alternative to the libnvidia-decode-440 which includes libcuda and libcuvid.
https://packages.debian.org/buster/libnvidia-encode1

After a reboot, ffmpeg still has no cuda/cuvid acceleration. Probably I need to install or configure something additionally for ffmpeg.

Code: Select all

ffmpeg -hwaccels

ffmpeg version 4.1.6-1~deb10u1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 8 (Debian 8.3.0-6)
  configuration: --prefix=/usr --extra-version='1~deb10u1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
  
  Hardware acceleration methods:
vdpau
vaapi
drm
I also checked my /dev/dri devices:

Code: Select all

ls -l /dev/dri/
total 0
drwxr-xr-x 2 root root        140 Mar  9 18:04 by-path
crw-rw---- 1 root video  226,   0 Mar  9 18:04 card0
crw-rw---- 1 root video  226,   1 Mar  9 18:04 card1
crw-rw---- 1 root video  226,   2 Mar  9 18:04 card2
crw-rw---- 1 root render 226, 128 Mar  9 18:04 renderD128
crw-rw---- 1 root render 226, 129 Mar  9 18:04 renderD129
By that output I believe that my Nvidia (Quadro) NVS510 is card1
As the lspci grepped output is: 01:00:00

Code: Select all

lspci | grep VGA
01:00.0 VGA compatible controller: NVIDIA Corporation GK107 [NVS 510] (rev a1)
03:00.0 VGA compatible controller: Matrox Electronics Systems Ltd. MGA G200e [Pilot] ServerEngines (SEP1) (rev 05)
Nvidia card details:

Code: Select all

sudo lspci -v -s 01:00.0
01:00.0 VGA compatible controller: NVIDIA Corporation GK107 [NVS 510] (rev a1) (prog-if 00 [VGA controller])
        Subsystem: NVIDIA Corporation GK107 [NVS 510]
        Flags: bus master, fast devsel, latency 0, IRQ 141
        Memory at b2000000 (32-bit, non-prefetchable) [size=16M]
        Memory at 90000000 (64-bit, prefetchable) [size=256M]
        Memory at a0000000 (64-bit, prefetchable) [size=32M]
        I/O ports at 6000 [size=128]
        [virtual] Expansion ROM at b3080000 [disabled] [size=512K]
        Capabilities: [60] Power Management version 3
        Capabilities: [68] MSI: Enable+ Count=1/1 Maskable- 64bit+
        Capabilities: [78] Express Endpoint, MSI 00
        Capabilities: [b4] Vendor Specific Information: Len=14 <?>
        Capabilities: [100] Virtual Channel
        Capabilities: [128] Power Budgeting <?>
        Capabilities: [600] Vendor Specific Information: ID=0001 Rev=1 Len=024 <?>
        Kernel driver in use: nvidia
        Kernel modules: nvidia
And nvidia-detect

Code: Select all

nvidia-detect
Detected NVIDIA GPUs:
01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GK107 [NVS 510] [10de:0ffd] (rev a1)

Checking card:  NVIDIA Corporation GK107 [NVS 510] (rev a1)
Your card is supported by all driver versions.
It is recommended to install the
    nvidia-driver
Then set the following in my ZM (v1.34.23) one camera to the following:
DecoderHWAccelName = cuda
DecoderHWAccelDevice = tried empty, tried /dev/dri/card0,1 and 2

Nvidia-smi and nvtop aren't reporting any services that use the card (which makes sense since ffmpeg has no cuda/ cuvid enabled).

Code: Select all

nvidia-smi
Tue Mar  9 18:47:11 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.32.03    Driver Version: 460.32.03    CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| 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  NVS 510             On   | 00000000:01:00.0 N/A |                  N/A |
| 28%   41C    P8    N/A /  N/A |      1MiB /  1999MiB |     N/A      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+
BlyatBlazer91
Posts: 2
Joined: Thu Sep 08, 2022 12:08 am

Re: How do I enable FFMPEG cuda acceleration?

Post by BlyatBlazer91 »

Im only commenting because I also have an nvidia quadro, and was able to get it up and running on 1.37 by adding the cuda option to each cameras source with a blank device path. and then i went into options>image>ffmpeg_path and added the extra argument -hwaccel cuda. Im running in a docker container and nvidia-smi doesnt show me any processes using the GPU but in the host, nvidia-smi does show me a process for each camera.
openman
Posts: 4
Joined: Mon Jan 19, 2009 11:47 am

Re: How do I enable FFMPEG cuda acceleration?

Post by openman »

I noticed that if cuvid is used in camera's source acceleration method, nvidia-smi reports the connection
A usefull link is also here: https://developer.nvidia.com/blog/nvidi ... ing-guide/
Post Reply