Skip to content

Instantly share code, notes, and snippets.

@corenel
Last active October 29, 2024 02:55
Show Gist options
  • Save corenel/a615b6f7eb5b5425aa49343a7b409200 to your computer and use it in GitHub Desktop.
Save corenel/a615b6f7eb5b5425aa49343a7b409200 to your computer and use it in GitHub Desktop.
Install NVDEC and NVENC as GStreamer plugins

Install NVDEC and NVENC as GStreamer plugins

Environment

  • Ubuntu 18.04
  • NVIDIA driver 460.32.03
  • NVIDIA Video Codec SDK 11.0.10
  • GStreamer 1.14.5

Steps

  1. Clone the gst-plugins-bad and check out to the same version as GStreamer installed on your PC
git clone git://anongit.freedesktop.org/gstreamer/gst-plugins-bad
cd gst-plugins-bad/
git checkout 1.14.5
  1. Download NVIDIA Video Codec SDK and copy header files
cd /path/to/video/codec/sdk
cp /usr/local/cuda/include/cuda.h /path/to/gst-plugins-bad/sys/nvenc
cp Interface/nvEncodeAPI.h /path/to/gst-plugins-bad/sys/nvenc
cp Interface/cuviddec.h /path/to/gst-plugins-bad/sys/nvdec
cp Interface/nvcuvid.h /path/to/gst-plugins-bad/sys/nvdec
  1. Build plugins
cd /path/to/gst-plugins-bad
NVENCODE_CFLAGS="-I/path/to/gst-plugins-bad/sys/nvenc" ./autogen.sh --with-cuda-prefix="/usr/local/cuda" --disable-gtk-doc
cd sys/nvenc
make
sudo cp .libs/libgstnvenc.so /usr/lib/x86_64-linux-gnu/gstreamer-1.0/
cd ../nvdec
make
sudo cp .libs/libgstnvdec.so /usr/lib/x86_64-linux-gnu/gstreamer-1.0/
  1. Check installation
gst-inspect-1.0 | grep nvenc
gst-inspect-1.0 | grep nvdec

References

@tadam98
Copy link

tadam98 commented Aug 8, 2021

The below procesure fails on wsl2 over windows 11.

  1. There is probably a missing "make" after the ./autogen.sh. But running make fails with an error.
  2. gst-xxx are in /usr/lib/ but anyway we dont get there is make fails.

https://gist.github.com/corenel/a615b6f7eb5b5425aa49343a7b409200

$ cd Downloads
$ mkdir gstreamer
$ cd gstreamer

step 1

git clone git://anongit.freedesktop.org/gstreamer/gst-plugins-bad
cd gst-plugins-bad/
git checkout 1.14.5

step 2

https://developer.nvidia.com/nvidia-video-codec-sdk/download

/home/mickey/Downloads/gstreamer/Video_Codec_SDK_11.1.5

cd /home/mickey/Downloads/gstreamer/Video_Codec_SDK_11.1.5
cp /usr/local/cuda/include/cuda.h /home/mickey/Downloads/gstreamer/gst-plugins-bad/sys/nvenc/
cp Interface/nvEncodeAPI.h /home/mickey/Downloads/gstreamer/gst-plugins-bad/sys/nvenc/
cp Interface/cuviddec.h /home/mickey/Downloads/gstreamer/gst-plugins-bad/sys/nvenc/
cp Interface/nvcuvid.h /home/mickey/Downloads/gstreamer/gst-plugins-bad/sys/nvenc/

step 3

cd /home/mickey/Downloads/gstreamer/gst-plugins-bad/
NVENCODE_CFLAGS="-I/home/mickey/Downloads/gstreamer/gst-plugins-bad/sys/nvenc/" ./autogen.sh --with-cuda-prefix="/usr/local/cuda" --disable-gtk-doc
make # fails
error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

cd /home/mickey/Downloads/gstreamer/gst-plugins-bad/sys/nvenc
make
#sudo cp .libs/libgstnvenc.so /usr/lib/x86_64-linux-gnu/gstreamer-1.0/
sudo cp .libs/libgstnvenc.so /usr/lib
cd ../nvdec
make
#sudo cp .libs/libgstnvdec.so /usr/lib/x86_64-linux-gnu/gstreamer-1.0/
sudo cp .libs/libgstnvdec.so /usr/lib/

@pringithub
Copy link

pringithub commented Dec 14, 2022

For future reference -
@tadam98 known issue that I ran into building on 20.04. Seemingly wasn't resolved? The hotfix is to remove references to openexr in the ./ext/Makefile (who uses openexr files anyway lol)
https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/issues/1117

Edit: this also is only an issue if you don't cd into /sys/nvenc and simply build from the root ... I guess I'm not the only one to miss that part?

@neilyoung
Copy link

Do you have a receipt for meson builds? 1.22 for instance is not having that ./autogen/make anymore

@danila-pavalotski
Copy link

Do you have a receipt for meson builds? 1.22 for instance is not having that ./autogen/make anymore

The same question.

@neilyoung
Copy link

Do you have a receipt for meson builds? 1.22 for instance is not having that ./autogen/make anymore

The same question.

Before I abandoned all attempts I found, that it is possible to change into subprojects/gst-plugins-bad and build from there

(I tried to compile on Jetson Nano, couldn't make it to have nvh264enc on Ubuntu 20.04, CUDA 12 and GST 1.22, I suppose this is not going to work at all since it would require a GST fork, which is made for the Jetson GPU)

@Vandor1
Copy link

Vandor1 commented Oct 31, 2023

Following all steps provided above I get the error when I try to make the 'sys/nvenc' directory:

  • Ubuntu version 20.08
  • Gsteamer version 1.16.3
  • Video Codec version 12.0

Anyone with a fix?

gstnvbaseenc.c:86:79: error: ‘NV_ENC_PRESET_DEFAULT_GUID’ undeclared (first use in this function); did you mean ‘NV_ENC_PRESET_P7_GUID’?
   86 | #define CASE(gst,nv) case G_PASTE(GST_NV_PRESET_,gst): return G_PASTE(G_PASTE(NV_ENC_PRESET_,nv),_GUID)
   
   gstnvbaseenc.c:131:72: error: ‘NV_ENC_PARAMS_RC_VBR_MINQP’ undeclared (first use in this function); did you mean ‘NV_ENC_PARAMS_RC_VBR’?
  131 | #define CASE(gst,nv) case G_PASTE(GST_NV_RC_MODE_,gst): return G_PASTE(NV_ENC_PARAMS_RC_,nv)

@Vandor1
Copy link

Vandor1 commented Nov 2, 2023

Following all steps provided above I get the error when I try to make the 'sys/nvenc' directory:

* Ubuntu version 20.08

* Gsteamer version 1.16.3

* Video Codec version 12.0

Anyone with a fix?

gstnvbaseenc.c:86:79: error: ‘NV_ENC_PRESET_DEFAULT_GUID’ undeclared (first use in this function); did you mean ‘NV_ENC_PRESET_P7_GUID’?
   86 | #define CASE(gst,nv) case G_PASTE(GST_NV_PRESET_,gst): return G_PASTE(G_PASTE(NV_ENC_PRESET_,nv),_GUID)
   
   gstnvbaseenc.c:131:72: error: ‘NV_ENC_PARAMS_RC_VBR_MINQP’ undeclared (first use in this function); did you mean ‘NV_ENC_PARAMS_RC_VBR’?
  131 | #define CASE(gst,nv) case G_PASTE(GST_NV_RC_MODE_,gst): return G_PASTE(NV_ENC_PARAMS_RC_,nv)

When running git checkout 1.14.5 make sure you are checkouting the version of your gstreamer. That solved my problem. I also used this guide to successfully get nvdec and nvh265enc + nvh264enc:
https://lifestyletransfer.com/how-to-install-nvidia-gstreamer-plugins-nvenc-nvdec-on-ubuntu/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment