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:

6 thoughts on “How to Enable Nvidia NVENC for OBS in Linux

  1. Scott Miller Post author

    Note: the

    --enable-shared 
    

    is needed for apps like obs, openshot, or others to be able to use nvenc. However, this appears to plow over Debian provided libraries, if various libav* packages are installed.

    I had to overwrite existing debian libraries (sadface.jpg) to get the created deb to install.


    sudo checkinstall on stretch results in:

    Selecting previously unselected package ffmpeg.
    (Reading database ... 325242 files and directories currently installed.)
    Preparing to unpack .../ffmpeg_20160921git-1_amd64.deb ...
    Unpacking ffmpeg (20160921git-1) ...
    dpkg: error processing archive /home/stmiller/Downloads/ffmpeg/ffmpeg_20160921git-1_amd64.deb (--install):
     trying to overwrite '/usr/include/x86_64-linux-gnu/libavcodec/avcodec.h', which is also in package libavcodec-dev:amd64 7:3.1.3-1+b3
    dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
    Errors were encountered while processing:
     /home/stmiller/Downloads/ffmpeg/ffmpeg_20160921git-1_amd64.deb
    /var/tmp/tmp.WeNMqJ96J2/dpkginstall.log (END)
    

    Force install (eek) the name of my deb with:

    $ sudo dpkg -i --force-overwrite ffmpeg_20160921-1_amd64.deb
    

    Undo this if desired:

    $ sudo dpkg -r ffmpeg
    
    $ sudo apt install --reinstall libavcodec-dev libavutil-dev libswresample-dev libavformat-dev 
    
    Reply
  2. Joshua Salles

    I had to install libnvidia-encode1 to get libnvidia-encode.so

    Reply
    1. Ely

      Can you expand on how to use the github build script? When running it I got an error referring me to the CMakeOutput.log and CMakeError.log files, which are just huge files that I don’t know what to read from…

      Reply
    2. ROD

      While I got no errors throughout the steps mentioned in that website, I just can’t enable NVENC nor can any apps on my computer (OBS, SSR) list NVENC as an encoder option.
      What else is there to it?

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.