Skip to content

NVIDIA nvdec and nvenc plugins

fduncanh edited this page Aug 10, 2023 · 96 revisions

Installation of nvdec (and nvenc) plugins from gstreamer1.0-plugins-bad, for GStreamer-1.16.x or earlier.

Since GStreamer-1.18.0, the NVIDIA nvcodec plugins have been shipped with GStreamer, but before then, the NVIDIA plugins were named nvdec and nvenc, and required three proprietary-header files from NVIDIA to be copied into the gst-plugins-bad source in order to be built.
These files

  • cuviddec.h, nvcuvid.h (needed for nvdec plugin)
  • nvEncodeAPI.h (needed for nvenc plugin).

are now released with a free-software license, and though they were not included when gstreamer-1.16 was originally released, have now been added to the current gst-plugins-bad-1.16.x source code in gst-build/subprojects/gst-plugins-bad/sys/nvdec/ and gst-build/subprojects/gst-plugins-bad/sys/nvenc./. You can find them there in the 1.16.x release if you need to add them to these directories when building the plugins for older releases of GStreamer.

Because of this history, users of GStreamer-1.16.3 and earlier must build these plugins themselves. Here is the build procedure for 1.16.x; it may be more complicated for earlier versions. Ubuntu-20.04LTS (1.16.2) is one of the few current distributions still using v 1.16.x.

First determine where the GStreamer plugins are installed on your system:

find / -name gstreamer-1.0

They will be in (path to)/gstreamer-1.0, where (path to) is something like /usr/lib (e.g., for 64-bit OS, /usr/lib64 on OpenSUSE, /usr/lib/x86_64-gnu-linux on Debian/Ubuntu, etc.). The GStreamer development files may also need to be installed.

You should also make sure pkg-config is installed:

which pkg-config

If you need to install it, the package that supplies it may be called pkgconf, or pkgconfig.

Next Install NVIDIA's CUDA packages. These may be available through your package manager, or directly from NVIDIA. GStreamer-1.16.x requires a CUDA version 10.1 or earlier (Install CUDA-10.1). The GStreamer build process checks to see if CUDA with an acceptable version is installed, using pkgconfig.

  • if the CUDA pkgconfig files (cuda-10.1.pc, cudart-10.1.pc) are missing (as in a number of distributions, e.g. see here, where links to download the missing files are given), GStreamer will not find CUDA: this seems to be the case in Ubuntu-20.04LTS, but downloading and placing these files in the pkgconfig directory (/usr/lib/x86_64-linux-gnu/pkgconfig in the 64-bit OS) solves the problem. You can also place them somewhere else, and add -Dpkg_config_path=... in step 8 below, where ... is the path to the directory containing these two files.

The GStreamer build process with (version) = 1.16.2 or 1.16.3, etc., is:

  1. (install required packages) meson flex bison
  2. git clone https://gitlab.freedesktop.org/gstreamer/gst-build.git
  3. cd gst-build
  4. git checkout (version)
  5. meson build
  6. cd gst-plugins-bad
  7. meson build
  8. meson configure build -Dnvdec=enabled
  9. cd build
  10. ninja
  11. cd sys/nvdec
  12. strip libgstnvdec.so
  13. cp libgstnvdec.so (path to)/gstreamer-1.0

If step 8 fails because CUDA is not found, check that a required version is installed; also check that the pkgconfig files cuda-10.1.pc, cudart-10.1.pc (for CUDA-10.1) are not missing (see earlier). (They should be in a directory "pkgconfig" in the PKG_CONFIG_PATH.)

If step 10 fails because of missing wayland*.h files (these are expected to be in /usr/include but could be installed elsewhere, as in /usr/include/wayland on OpenSUSE15.3), repeat step 8, with -Dwayland=disabled. Alternatively, find the wayland include files and copy them to either /usr/include, or gst-build/gst-plugins-bad/gst-libs/gst/wayland/. Then continue.

If you want to also build the nvenc plugin for encoding video, also add -Dnvenc=enabled at step 8, and repeat steps 11-13 with "nvenc" replacing "nvdec".

For GStreamer-1.14 and earlier, the -D option at step 8 is not valid, and the maximum required version of CUDA is lower; you also need to obtain cuviddec.h and nvcuvid.h from GStreamer-1.16 or later and copy them into gst-build/subprojects/gst-plugins-bad/sys/nvdec/ (also copy nvEncodeAPI.h into gst-build/subprojects/gst-plugins-bad/sys/nvenc/ if you wish to build nvenc); this needs to be done after step 5 and before step 10.

  • A distribution using GStreamer-1.14 or earlier is likely to be obsolete, and you should consider upgrading to a new one if possible.