Skip to content

Instantly share code, notes, and snippets.

@fritz-fritz
Last active September 16, 2025 04:47
Show Gist options
  • Save fritz-fritz/b8dd3cc081325d1a73e86be727edc0f7 to your computer and use it in GitHub Desktop.
Save fritz-fritz/b8dd3cc081325d1a73e86be727edc0f7 to your computer and use it in GitHub Desktop.
Custom obs-backgroundremoval build with support for NVIDIA cuda 12 on linux

The below CMakeUserPreset.json can be used to successfully build and install obs-backgroundremoval with a version of the ONNXRUNTIME that supports current NVIDIA CUDA 12.

It makes use of changes introduced in my fork with commit 2c658d8a. EDIT: The PR has now been merged into master

Due to changes upstream with ONNXRUNTIME, the plugin now depends on libcudnn for CUDA which is provided by nvidia-cudnn.

To make use of this:

  1. Clone from my fork on the feature/custom-onnxruntime branch. Clone locaal-ai/obs-backgroundremoval
  2. Place the below CMakeUserPresets.json file at the projects root
  3. Run the following:
    rm -rf build_x86_64 release \
      && cmake --preset cuda12 \
      && cmake --build --preset cuda12 \
      && cmake --build build_x86_64 -t package \
      && sudo apt install ./release/obs-backgroundremoval-1.2.0-x86_64-linux-gnu.deb
  4. Profit

Update 9/15/2025: Changed debian package dependencies for more accurate cuda selection

{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 28,
"patch": 0
},
"configurePresets": [
{
"name": "cuda12",
"displayName": "Linux x86_64 w/ cuda12",
"description": "Build for Linux x86_64 against CUDA 12",
"inherits": ["template"],
"binaryDir": "${sourceDir}/build_x86_64",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"generator": "Ninja",
"warnings": {"dev": true, "deprecated": true},
"cacheVariables": {
"QT_VERSION": "6",
"CMAKE_INSTALL_PREFIX": "/usr",
"CMAKE_BUILD_TYPE": "Release",
"CPACK_DEBIAN_PACKAGE_DEPENDS": "obs-studio, libcuda1, nvidia-cuda-toolkit (>= 12~) | cuda-toolkit-12-9 | cuda-toolkit-12-8 | cuda-toolkit-12-6 | cuda-toolkit-12-5 | cuda-toolkit-12-4 | cuda-toolkit-12-3, nvidia-cuda-toolkit (<< 13~) | cuda-toolkit-12-9 | cuda-toolkit-12-8 | cuda-toolkit-12-6 | cuda-toolkit-12-5 | cuda-toolkit-12-4 | cuda-toolkit-12-3, nvidia-cudnn | cudnn",
"CUSTOM_ONNXRUNTIME_VERSION": "1.21.0",
"CUSTOM_ONNXRUNTIME_URL": "https://github.com/microsoft/onnxruntime/releases/download/v1.21.0/onnxruntime-linux-x64-gpu-1.21.0.tgz",
"CUSTOM_ONNXRUNTIME_HASH": "SHA256=ef37a33ba75e457aebfd0d7b342ab20424aa6126bc5f565d247f1201b66996cf"
}
}
],
"buildPresets": [
{
"name": "cuda12",
"configurePreset": "cuda12",
"displayName": "Linux x86_64 w/ cuda12",
"description": "Linux build for x86_64 against CUDA 12",
"configuration": "Release"
}
]
}
@fritz-fritz
Copy link
Author

@tomekjarosik sorry about that, I had some extra parenthesis in there. I have now tested with the following which I tested on debian. The major change is that in order to specifically gate cuda to version 12 without forcing the removal of cuda 13 I also needed to specify the specific minor versions. What a mess!

"CPACK_DEBIAN_PACKAGE_DEPENDS": "obs-studio, libcuda1, nvidia-cuda-toolkit (>= 12~) | cuda-toolkit-12-9 | cuda-toolkit-12-8 | cuda-toolkit-12-6 | cuda-toolkit-12-5 | cuda-toolkit-12-4 | cuda-toolkit-12-3, nvidia-cuda-toolkit (<< 13~) | cuda-toolkit-12-9 | cuda-toolkit-12-8 | cuda-toolkit-12-6 | cuda-toolkit-12-5 | cuda-toolkit-12-4 | cuda-toolkit-12-3, nvidia-cudnn | cudnn"

I honestly haven't explored more onnx models beyond the v1.21.0 in the above config as it works solid for me!

@fritz-fritz
Copy link
Author

I should note, I haven't tested if the nvidia-cuda-toolkit package will force a downgrade from cuda 13 but I don't think there is actually a cuda 13 version released for this package yet. So it should be a non-issue for now but might need to be adjusted in the future.

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