Integration for backscrub project into OBS Studio
It's a video filter plugin for OBS Studio (currently limited to video capture devices that produce YUY2 format streams), which uses the backscrub
library to remove the background of a video source (replacing it with green), allowing subsequent chroma keying of alternate backgrounds.
- Install the dependencies (assuming you have OBS Studio already!):
build-essentials
,libobs-dev
,libopencv-dev
- Clone this project.
- Do the CMake dance:
% mkdir build; cmake -B build; cmake --build build -j
This will pull the submodules (backscrub and Tensorflow), configure them (mostly Tensorflow fetching several more dependencies) then compile everything. Expect to wait 10+ minutes for a full build, and lose ~2GB of disk space.
NB: This is fiddly, fragile and poorly tested
- Development environment: VS2019 community edition, on Server2019 / Windows10/11
- Download and install dependencies (assuming you have OBS Studio already!):
- OpenCV 3.4.14: https://sourceforge.net/projects/opencvlibrary/files/3.4.14/opencv-3.4.14-vc14_vc15.exe/download
- Note installed path, eg:
C:\Users\phlash\Download\opencv
- Download OBS source code and bodge an import library (in lieu of a libobs-dev package):
- Match your version, eg for 29.0.2: https://github.com/obsproject/obs-studio/archive/refs/tags/29.0.2.zip
- Create a fresh
libobs
folder eg:C:\Users\phlash\Downloads\libobs
- Save LibObsConfig.zip to the
libobs
folder and unpack in place to get a CMake config script - From OBS source ZIP, unpack only the
libobs
folder into folder above, then rename asinc
, eg:C:\Users\phlash\Downloads\libobs\inc
- Create a
bin
folder next toinc
eg:C:\Users\phlash\Downloads\libobs\bin
- Copy the
OBS.DLL
library out of your installed OBS Studio eg:C:\Program Files\obs-studio\bin\64bit\OBS.DLL
intobin
folder. - In a
VS2019 Developer Command Prompt
, generate an import library from the DLL, instructions modified from: https://stackoverflow.com/questions/9946322/how-to-generate-an-import-library-lib-file-from-a-dllC> cd <libobs\bin folder> C> echo LIBRARY OBS > obs.def C> echo EXPORTS >> obs.def C> for /f "skip=19 tokens=4" %A in ('dumpbin /exports OBS.DLL') do echo %A >> obs.def C> lib /def:obs.def /out:OBS.LIB /machine:x64
- Clone this project.
- Checkout
windows-build
branch. - In a
VS2019 Developer Command Prompt
Do the CMake dance, informing it where OpenCV and libobs are:
C> mkdir build C> cmake -B build -D CMAKE_PREFIX_PATH="<OpenCV path>\build;<libobs folder>" C> cmake --build build -j
- The build will fail, you need to fix up a bug in Tensorflow (tensorflow/tensorflow#54323)
- Edit:
tensorflow\tensorflow\core\lib\random\random_distributions_utils.h
and replaceM_PI
symbol with3.1415928
.
- Edit:
- Re-run build:
C> cmake --build build -j
I choose to create sym-links for the built object and the data directory out of the obs-studio installation, this avoids install-to-test issues:
% cd /lib/x86_64-linux-gnu/obs-plugins
% sudo ln -s /home/phlash/obs-backscrub/build/obs-backscrub.so .
% cd /usr/share/obs/obs-plugins
% sudo ln -s /home/phlash/obs-backscrub/data obs-backscrub
Not quite the same as Linux as Windows cannot do file symlinks, only folders, so we copy the built object and dependencies:
C> cd \Program Files\obs-studio\obs-plugin\64bit
C> copy \Users\phlash\obs-backscrub\build\obs-backscrub.dll
C> copy <OpenCV path>\build\x64\opencv-world3414d.dll
C> cd ..\..\data\obs-plugin
C> mklink /D obs-backscrub \Users\phlash\obs-backscrub\data
Fire up OBS Studio - check the logs to ensure obs-backscrub.dll
loads successfully.
Add a video capture source, go to filters, and add an audio/video filter 'Background scrubber'. That's it.