Nvidia hardware video encoding not working

Hello. I am trying to get Nvidia hardware encoding working, specifically for ALVR but we may use FFmpeg to test if it’s working as that’s a more widely known program. I have an RTX 3060 card on a desktop computer running Endeavour OS (Arch Linux). My Driver version is 525.89.02 and CUDA version 12 (pacman shows cuda 11.8.0-1 but nvidia-smi outputs CUDA version 12). I followed the Arch Wiki and installed nvidia-utils. The modules are loaded:

$ lsmod | grep nvidia
nvidia_drm             73728  7
nvidia_uvm           2908160  0
nvidia_modeset       1515520  9 nvidia_drm
nvidia              61444096  480 nvidia_uvm,nvidia_modeset
video                  65536  1 nvidia_modeset

Trying to render a video with FFmpeg using this command ffmpeg -y -hwaccel cuda -i bigbuckbunny.mp4 bigbuckbunny2.mp4 works, but uses CPU. I compiled FFmpeg myself following Nvidia’s instructions and tried again and got this error:

Device creation failed: -12.
No device available for decoder: device type cuda needed for codec h264.

Also, ffmpeg -help encoder=h264_nvenc returns error Codec 'h264_nvenc' is not recognized by FFmpeg.. I have also installed x265, libde265 and nvenc packages from the AUR but the same issue still occurs. What can I do to get Nvidia H265 Hardware encoding working? Thanks in advance.

Please post the output of
ffmpeg -encoders |grep -i nvidia

$ ffmpeg -encoders |grep -i nvidia
ffmpeg version N-109896-g156ca86569 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.2.1 (GCC) 20230201
  configuration: --enable-nonfree --enable-cuda-nvcc --enable-libnpp --extra-cflags=-I/opt/cuda/include --extra-ldflags=-L/opt/cuda/lib64 --disable-static --enable-shared
  libavutil      58.  3.100 / 58.  3.100
  libavcodec     60.  4.100 / 60.  4.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

Also, ffmpeg -h encoder=h264_nvenc returns:

$ ffmpeg -h encoder=h264_nvenc
ffmpeg version N-109896-g156ca86569 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.2.1 (GCC) 20230201
  configuration: --enable-nonfree --enable-cuda-nvcc --enable-libnpp --extra-cflags=-I/opt/cuda/include --extra-ldflags=-L/opt/cuda/lib64 --disable-static --enable-shared
  libavutil      58.  3.100 / 58.  3.100
  libavcodec     60.  4.100 / 60.  4.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
Codec 'h264_nvenc' is not recognized by FFmpeg.

nvenc wasn’t built into it. Rather use the standard arch ffmpeg.

That worked. Weird that Nvidia’s documentation doesn’t instruct how to compile FFmpeg with Nvenc support.

Those instructions are from a time when nvidia first released the free headers so are likely much outdated and only work with a years-old ffmpeg source release. Nowadays, most distros include this.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.