[UPDATE] Setting up NVFBC for OBS on Ubuntu (With troubleshooting steps!)

UPDATED WITH 120.00hz NVIDIA xrandr INSTRUCTIONS IN POST 5!


Anthony from LTT gave us instructions for Nvidia users on Linux the holy grail of capture APIs: NVFBC! (go to the “A Shadowplay alternative (optional)” chapter)

However most of you will run into initial issues if you add your own PPA for OBS so this is the full guide with troubleshooting steps:

First, are you on 21.04 or 20.04 LTS? This is important as it determines whether you need to take out a package from your dependencies installation.

Second, did you already install OBS from the PPA? Does /usr/include/obs contain anything? This determines if it’s gonna be easier to do an extra troubleshooting step that is necessary if your libobs0 has surpassed the version set as a dependency by libobs-dev (thanks Canonical.)

This guide will assume you already installed from the PPA and potentially installed additional plugins like obs-ndi.

With these set, let’s proceed with the steps from the video with troubleshooting steps:

First, you will need to patch the shared library just like in the video from here:

But what if your Vulkan driver is NEWER than the listed drivers in the script?

Believe it or not, you can see the patch contents don’t differ greatly between the same generation of driver (the 470 series for example) so all you need to do is manually enter the driver (in my case 470.62.02) and re-use the contents from the previous driver in the script (470.63.01, which actually was released BEFORE 470.62.02)

--- patch-fbc.sh	2021-09-15 16:37:08.834207320 -0700
+++ patch-fbc-new.sh	2021-09-15 16:38:05.109758564 -0700
@@ -117,6 +117,7 @@
     ["465.31"]='s/\x83\xfe\x01\x73\x08\x48/\x83\xfe\x00\x72\x08\x48/'
     ["470.42.01"]='s/\x83\xfe\x01\x73\x08\x48/\x83\xfe\x00\x72\x08\x48/'
     ["470.57.02"]='s/\x83\xfe\x01\x73\x08\x48/\x83\xfe\x00\x72\x08\x48/'
+    ["470.62.02"]='s/\x83\xfe\x01\x73\x08\x48/\x83\xfe\x00\x72\x08\x48/'
     ["470.63.01"]='s/\x83\xfe\x01\x73\x08\x48/\x83\xfe\x00\x72\x08\x48/'
 )
 
@@ -191,6 +192,7 @@
     ["465.31"]='libnvidia-fbc.so'
     ["470.42.01"]='libnvidia-fbc.so'
     ["470.57.02"]='libnvidia-fbc.so'
+    ["470.62.02"]='libnvidia-fbc.so'
     ["470.63.01"]='libnvidia-fbc.so'
 )
 

Now it’s ready for my fresh Vulkan beta driver.

Now exactly like in the video, after doing the modification:

sudo ./patch-fbc.sh

A successful patch will spit out checksums for a original backup going to /opt/nvidia and the patched file going to it’s intended destination in /usr/lib/x86_64-linux-gnu

Next, building the shared library/plugin for OBS.

For 21.04 and up, use the same dependency installation as described in the video:

sudo apt install libgl-dev libobs-dev libsimde-dev meson ninja-build

For 20.04 LTS, do not install libsimde-dev. It builds fine without it.

sudo apt install libgl-dev libobs-dev meson ninja-build

Uh oh. I hit a dependency problem… libobs0 needs version 25.x.x…

This is extremely unfortunate and is why the official PPA needs to supply some packages to remedy some of these dependency problems.

This is where you will have to brute force install libobs-dev by extracting the .deb files.

Grab it from the web interface for the Universe repository:

21.04: Ubuntu – Details of package libobs-dev in hirsute

20.04: Ubuntu – Details of package libobs-dev in bionic

Open the .deb in Archive Manager (or Ark) and extract data.tar.xz

Within data.tar.xz, navigate into the /usr/lib/x86_64-linux-gnu folder. The important folder is the cmake folder, where you will copy one folder inside that folder to the actual /usr/lib/x86_64-linux-gnu/cmake folder on your system.

If your /usr/include/obs is already populated, do not extract the include (*.h) files from this deb package.

Copy the LibObs folder from within cmake into the cmake folder in /usr/lib/x86_64-linux-gnu. I prefer to use Nemo and “Open as Root” to do this, but you can extract and use cp as root if you’re comfortable with that instead.

Copy all libobs.* files from /usr/lib to /usr/lib/x86_64-linux-gnu (including the symlinks)

You will now want to apt-mark hold obs-studio so it doesn’t automatically update and break everything. If you wish to still keep OBS up to date, see POST 2.

NOW we are ready to proceed with building. This part is exactly like the video once again. cd to the place you extracted this:

and execute these commands, just like in the video:

meson build
ninja -C build

Now comes time to move the plugin into the proper place. Do exactly as described in the video by making these directories:

~/.config/obs-studio/plugins
~/.config/obs-studio/plugins/nvfbc
~/.config/obs-studio/plugins/nvfbc/bin
~/.config/obs-studio/plugins/nvfbc/bin/64bit

and putting the nvfbc.so in the build folder (like in the video, but the video didn’t show you had to go into the build folder) and copying it to the 64bit folder you just created.

The folder name nvfbc is case sensitive, so it must remain in lower case for OBS to read it properly.

You DO NOT need to reboot to test it out.

Once it is complete, it will function assuming your build logs all check out, your paths are correct (remember, case sensitive on the plugin folder names) and you should be off to the races.

It will load as a “NvFBC Source” in the sources list.

Do keep in mind that for some reason the FPS option in the plugin is only in whole integers from 1 to 120. (you can’t go beyond 120fps because that’s the limit in the source code) This is unfortunate if your display is using NTSC drop frame, (which 120fps equals 119.88fps and 144fps equals 143.856fps) so this might cause some issues or it might not. Maybe with some fancy source code tweaking this can be added and 144fps could also be added. (The key here is making it a floating point value with decimals rather than a whole integer)

Optimally, you will want to run 60.00hz according to the monitor listing in Nvidia X Server Settings. Or you can get adventurous with randr and set it to exactly 120.00hz. (UPDATE: SEE POST 5!) Going to 144hz will actually be a detriment to capture because of the 120fps cap on NVFBC in the source code for this plugin. (Hopefully this is a source code issue and not a hard cap in the API. If it’s a hard cap, then you will need to stick to 60.00hz and 120.00hz)

Thanks once again to Anthony for letting me know NVFBC is actually possible natively with said patch, and there’s an OBS plugin for it! (aside from the whole integers problem, this is very nice.)

1 Like

WARNING: If you plan to update OBS and not do apt-mark hold, there are additional steps required.

If you update OBS and it no longer launches, you have a mismatch between your /usr/lib and /usr/lib/x86_64-linux-gnu folders in terms of shared libraries.

Copying the shared libraries to x86_64-linux-gnu is only required to build the NVFBC shared library. It is not required after you have successfully built it. After you have successfully built your nvfbc.so, you can safely delete all the libobs based shared libraries you copied before to x86_64-linux-gnu only if you installed OBS from the PPA. (DO NOT do this if you installed OBS from the universe Ubuntu repository)

Posting this to make sure people don’t get suddenly stuck by updating and finding out OBS no longer launches.

idk what anyone else’s experience is like, but I just tried this and I get some hideous screen tearing in game that isn’t there when I simply use window capture. It could simply be that this is causing my screen to lock at 60 hz (while maintaining only around 53fps) and I just don’t notice the tearing when it’s 120 hz. I do wonder if my being extremely GPU bound (even while software encoding) means that I don’t see the benefit from capturing in this way.

Could be your compositor. It’s working pretty good on KDE for me with the compositor completely off.

BREAKTHROUGH:

I have managed to get a Reduced Blanking timing working with 1080p 120.00hz that’s able to be set using xrandr. Tested using the BenQ EX2510 and confirmed working. xrandr is a thorn in Nvidia’s side, as many Nvidia users have trouble with it whereas AMD and Intel IGP users don’t have the same issues.

Modeline "1920x1080_120.00"  274.56  1920 1928 1960 2000  1080 1130 1138 1144 +hsync -vsync

This was calculated using a trusty video blanking calculator available here: Video Timings Calculator (I used CVT-RBv2)

The formula to get it into a modeline using the terminology on the calculator:

Modeline "name" [PixelClock] \
                [HPixels] [HPixels+HFrontPorch] [HPixels+HFrontPorch+HSync] [HTotal] \
                [VPixels] [VPixels+VFrontPorch] [VPixels+VFrontPorch+VSync] [VTotal] \
                [Polarizations]

Polarizations are determined by cvt -r 1920 1080 120.

Nvidia appear to be deliberately hostile towards custom resolutions using xrandr, adding in many different safety checks that prevent you from using xrandr to it’s full ability. Hence the frustration people face when trying to set xrandr and it doing nothing on Nvidia.

You will need this in your /etc/X11/xorg.conf.d as 20-randr.conf

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    Option         "UseEDIDFreqs" "Off"
    Option         "ModeValidation" "AllowNonEdidModes,AllowNon60HzDFPModes,NoMaxPClkCheck,NoEdidMaxPClkCheck,AllowInterlacedModes,NoMaxSizeCheck,NoHorizSyncCheck,NoVertRefreshCheck"
    Option         "Coolbits" "28"
    Option         "UseNvKmsCompositionPipeline" "Off"
EndSection

This will override your entire Device section in xorg.conf so modify accordingly so your custom settings carry over. This is required to defeat the safeties.

Now, you need a startup script to run on login. Make a shell script with this in it:

#!/bin/bash

# Replace DP-0 with your current display

xrandr --newmode "1920x1080_120.00"  274.56  1920 1928 1960 2000  1080 1130 1138 1144 +hsync -vsync
xrandr --addmode DP-0 "1920x1080_120.00"
xrandr --output DP-0 --mode "1920x1080_120.00"

Save as xrandr.sh and make it executable: chmod +x xrandr.sh

Now in whichever startup script manager you choose, (in KDE it’s under System Settings > Startup and Shutdown > Autostart) add the script you just made to run at login (xrandr does NOT need to be root to do this. Validated this on Nvidia Driver 460.91.03)

Adding this information to xorg.conf.d or xorg.conf will not work. It simply refuses to acknowledge custom resolutions in said files as yet another safety measure IMO. It has to be a shell script executed at login.

Now you can capture 120.00hz using NVFBC with VERY few frame time inconsistencies. It will be less on the display and more on how the game engine delivers frames to the framebuffer that affects frame times in the recording. This is as close to as perfect 120hz same system capture as there is on Linux.

I followed everything correctly

#install necessary packages
sudo apt install -y git libgl-dev libobs-dev libsimde-dev meson ninja-build obs-studio

#install fbc patch
git clone https://github.com/keylase/nvidia-patch.git
a="./nvidia-patch/"
cd $a
sudo ./patch-fbc.sh
cd ../

#install nvfbc plugin
git clone https://gitlab.com/fzwoch/obs-nvfbc.git
b="./obs-nvfbc/"
cd $b
meson build
ninja -C build
mkdir -p -- ~/.config/obs-studio ~/.config/obs-studio/plugins ~/.config/obs-studio/plugins/nvfbc ~/.config/obs-studio/plugins/nvfbc/bin ~/.config/obs-studio/plugins/nvfbc/bin/64bit
cp ./build/nvfbc.so ~/.config/obs-studio/plugins/nvfbc/bin/64bit/nvfbc.so
cd ../

#remove folders
sudo rm -rf $a
sudo rm -rf $b

But I still get his error when I press Start Recording
image

Your FFmpeg might not have NVENC enabled. Make sure you have the correct version of FFmpeg installed with your distro.