LibOBS relative imports config

JustChap

New Member
Hi there!
I'm working on integrating OBS into a NodeJS application via Node's native addons API and, while I can get it working in a test environment, I'm having some trouble when packaging it with the application. C/C++ development is very new to me, so please forgive any simple mistakes :)

My issue revolves around the directory structures that OBS.dll seems to expect. OBS seems to attempt to load some DLLs and .effect files in a predefined location relative to the CWD and I'm looking to override this behaviour.

Here's how I'm roughly trying to structure the application:
-----
App root
- obs​
- data​
- libobs​
(the .effect files...)​
- bin​
obs.dll​
libobs-d3d11.dll​
(other dlls...)​
OBSBinding.node​
index.ts <-- Entry point​
-----

So the Node app starts at index.js, where OBSBinding.node is imported and utilised. OBSBinding exposes the libOBS stuff to Node, allowing me to call obs_startup(), obs_reset_video() and all that. Unfortunately in this setup OBS gives me some import errors
info: LoadLibrary failed for 'libobs-d3d11': The specified module could not be found.

If I move libobs-d3d11.dll into the App root (right next to index.js), that error goes away and I move a little further through the startup:
Code:
info: CPU Name: Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz
info: CPU Speed: 2400MHz
info: Physical Cores: 4, Logical Cores: 8
info: Physical Memory: 7897MB Total, 955MB Free
info: Windows Version: 10.0 Build 18362 (release: 1903; revision: 900; 64-bit)
info: Running as administrator: false
info: Aero is Enabled (Aero is always on for windows 8 and above)
info: Windows 10 Gaming Features:
info:     Game DVR: On
info: Sec. Software Status:
info:     Windows Defender Antivirus: enabled (AV)
info:     Windows Firewall: enabled (FW)
info: ---------------------------------
info: Initializing D3D11...
info: Available Video Adapters:
info:     Adapter 0: Intel(R) UHD Graphics 630
info:       Dedicated VRAM: 134217728
info:       Shared VRAM:    4140423168
info:       PCI ID:         8086:3e9b
info:       Driver Version: 26.20.100.7985
info:       output 0: pos={0, 0}, size={1920, 1080}, attached=true, refresh=59, name=DELL S2340L
info:       output 1: pos={-1920, 0}, size={1536, 864}, attached=true, refresh=60, name=
info:     Adapter 1: NVIDIA GeForce GTX 1650
info:       Dedicated VRAM: 4156555264
info:       Shared VRAM:    4140423168
info:       PCI ID:         10de:1f91
info:       Driver Version: 26.21.14.4274
info: Loading up D3D11 on adapter Intel(R) UHD Graphics 630 (0)
info: D3D11 loaded successfully, feature level used: b000
info: DXGI increase maximum frame latency success
debug: gs_effect_create_from_file: Null 'file' parameter
debug: gs_effect_create_from_file: Null 'file' parameter
debug: gs_effect_create_from_file: Null 'file' parameter
debug: gs_effect_create_from_file: Null 'file' parameter
debug: gs_effect_create_from_file: Null 'file' parameter
debug: gs_effect_create_from_file: Null 'file' parameter
debug: gs_effect_create_from_file: Null 'file' parameter
debug: gs_effect_create_from_file: Null 'file' parameter
debug: gs_effect_create_from_file: Null 'file' parameter
debug: gs_effect_create_from_file: Null 'file' parameter
info: Freeing OBS context data

To fix this error, I looked at the directory structure for the OBS studio release and replicated that. Problem is, that means I have to place a bunch of .effect files two directories above the App's root directory. So the structure would look like this
----
- data
- libobs​
area.effect​
bicubic_scale.effect​
(the other .effect files...)​
- App parent folder
- App root​
index.ts <-- Entry point​
libobs-d3d11.dll​
----
When I use this layout, the app works perfectly and I'm able to launch OBS and initialise the video and audio systems as expected. Great! But this structure is clearly very inconvenient, both because of the .effect files being outside of the app's directory and libobs-d3d11.dll (and I assume other dlls if I use more OBS features?) being laid out flat in the App root. I don't think I can change the CWD passed to OBS.dll, so I'm not able to just bury the required structure within App root subfolders.

Is there a way I can change where OBS looks for these files? Ideally so that I can structure the application in the way I outlined earlier.
I couldn't seem to find any description of this behaviour in the OBS docs so I'm not sure exactly where I should be setting this option. Or, if there isn't an easy config built in to OBS, I suppose I could modify the source code to manually fit my structure if someone could point me in the right direction.

Any ideas welcome, thanks in advance!
 

R1CH

Forum Admin
Developer
Is it possible to move your index.ts within the obs/bin/ directory? If you still need it outside of the OBS structure, perhaps a simple launcher script in your app root which changes to the obs/bin directory and launches index.ts from there?
 

JustChap

New Member
Yep, just tried that out and it appears to be the simplest solution. Thanks R1CH!

For those interested, I didn't end up using a start up script, I instead just switched working directories in Node with process.chdir() (duh) and then called obs_startup() from there. That works great as I can load other non-OBS dependencies beforehand without having to move them out of their current structure.
Here's how the app is structured now:
----
App root
- obs​
- bin / x64​
OBSBinding.node​
libobs-d3d11.dll​
(other dlls...)​
- data / libobs​
area.effect​
(other .effect files...)​
index.ts <-- entry point​
----
 

JustChap

New Member
Back at it again and I've run into some more trouble with dependencies, this time trying to load OBS plugins.

I'm using the same structure as I last posted, now with the addition of a plugins/x64 folder in the App root/obs directory. Right now I'm trying to load obs-ffmpeg.dll and obs-x264.dll.

The CWD is still in bin/x64 after initial setup (with OBS.dll, etc.), then I call obs_load_all_modules() and get the following:

Code:
Initializing OBS...
info: CPU Name: Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz
info: CPU Speed: 2400MHz
info: Physical Cores: 4, Logical Cores: 8
info: Physical Memory: 7897MB Total, 1635MB Free
info: Windows Version: 10.0 Build 18362 (release: 1903; revision: 900; 64-bit)
info: Running as administrator: false
info: Aero is Enabled (Aero is always on for windows 8 and above)
info: Windows 10 Gaming Features:
info:   Game DVR: On
info: Sec. Software Status:
info:   Windows Defender Antivirus: enabled (AV)
info:   Windows Firewall: enabled (FW)
info: ---------------------------------
info: Initializing D3D11...
...graphics info...
info: D3D11 loaded successfully, feature level used: b000
info: DXGI increase maximum frame latency success
info: ---------------------------------
info: video settings reset:
    base resolution:   1920x1080
    output resolution: 1920x1080
    downscale filter:  Disabled
    fps:               30/1
    format:            RGBA
    YUV mode:          None
info: ---------------------------------
info: audio settings reset:
    samples per sec: 48000
    speakers:        2
OBS started
Loading modules
debug: ---------------------------------
info: LoadLibrary failed for 'c:\codeprojects\node-obs-test\obs\plugins\x64/obs-ffmpeg.dll': The specified module could not be found.
 (126)
warning: Module 'c:\codeprojects\node-obs-test\obs\plugins\x64/obs-ffmpeg.dll' not loaded
debug: Failed to load module file 'c:\codeprojects\node-obs-test\obs\plugins\x64/obs-ffmpeg.dll': -2
debug: ---------------------------------
debug: Loading module: obs-x264.dll
debug: source 'Main' (scene) created

As you can see the obs-x264.dll loads fine (and I can successfully create an x264 encoder), but the ffmpeg one fails. obs-ffmpeg.dll is definitely in the right spot and I know the ffmpeg plugin works on my system as I can use it in OBS Studio. So I'm guessing the dll is trying to link with something it can't find. I can see that it depends on some of the core OBS dlls in Dependency Walker, but they're all in the working directory so it should have access to them, right?

I've also tried:
  • Placing all the core OBS dlls in the plugins/x64 folder alongside obs-ffmpeg.dll
  • Copying the obs-ffmpeg.dll from the official OBS Studio install (rather than my local build)
I must be missing something here but I'm just not sure what. Any ideas?
 

R1CH

Forum Admin
Developer
That usually means a dependent DLL failed, use a tool like dependency walker to see what DLLs your obs-ffmpeg.dll depends on that might not be in the path.
 

JustChap

New Member
I had the same thought R1CH, but when I ran it through it said that all the dependencies were good. It looks like the only dlls it needs (aside from some Windows ones) are those core OBS dlls I mentioned earlier, which are in bin/x64 (which is the working directory).

1593044551432.png
 
Top