How to Enable Nvidia NVENC for OBS in Linux

By | 2016/09/12

OBS on Linux supports using the Nvidia NVENC for H.264 encoding. To get this working, one must compile ffmpeg wtih nvenc support. Check it out!


Requirements:

– nvidia proprietary driver installed
– kepler or maxwell (or later) nvidia GPU
– OBS Studio 0.14 or later


Step 1:

Grab the nvEncoder header

FFmpeg 3.1.3 and later includes this header so one does not need to download any nvenc sdk from nvidia if building FFmpeg 3.1.3+.

Otherwise:

Download and extract Nvidia nvenc sdk from: https://developer.nvidia.com/nvidia-video-codec-sdk

From that download, copy the file
/Video_Codec_SDK_7.0.1/Samples/nvEncoder/NvEncoder.h
to
/usr/local/include


Step 2:

Download and extract the Nvidia cuda sdk from: https://developer.nvidia.com/cuda-downloads

Copy
cuda.h
to
/usr/local/include


Step 3:

Configure and the install ffmpeg with:

--enable-nonfree --enable-nvenc

This may vary wildly by distro, or you may have your own preferred way to compile and build ffmpeg.

Debian Example

Below are debian specific steps using the latest nvidia driver from nvidia.com which will result in a .deb file installed and ffmpeg executable at /usr/local/bin/ffmpeg

sudo apt build-dep ffmpeg

sudo apt install yasm nasm \
                build-essential automake autoconf \
                libtool pkg-config libcurl4-openssl-dev \
                checkinstall libavcodec-extra57

git clone git://git.videolan.org/ffmpeg.git

cd ffmpeg

./configure --prefix=/usr/local --extra-version=1+b3 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --shlibdir=/usr/lib/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --disable-stripping --enable-shared --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librubberband --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-chromaprint --enable-libopencv --enable-libx264 --enable-pic --enable-nonfree --enable-nvenc

make -j4

sudo checkinstall


Step 4: OBS Setup

In OBS, there will now be an encoder option NVENC H.264. Now the bitrate can be cranked up to blu-ray or better quality for local recording if you have a recent video card. I’ve got mine set at 50000.

nvenc_linux

Note that NVENC encoding can be used in other apps as well. For instance in openshot, one can use nvenc for encoding videos.

nvenc_openshot
Example video

Below is a video recorded using obs in Linux using the NVENC encoder, 1080p60 @ 50Mb/s bitrate: