Control OBS recorder via N4M script

Rob Ramirez's icon

Hey everyone here's a weekend gift for those interested in augmenting their video recording capabilities via the fantastic open source OBS app and a little Node for Max script.

The basic gist is, wouldn't it be nice to trigger OBS recordings from inside Max, in order to better synchronize these recordings with whatever is going on in your patch? Well it turns out OBS has an extensive API for controlling and querying all manner of functionality, a plugin for web socket access of this API, and a node library for interacting with this plugin. So all we need for Max is a little node wrapper, and I just so happen to have one for ya.

Make sure you first install the web socket plugin for your platform here. The first time you open the patch, make sure you hit the script npm install button to install all the node dependencies.

There are tester patches for both Mac and Win, and they assume either Syphon or Spout is installed via the Package Manager. To send video from Max to OBS add either a Syphon Client of Spout2 Capture source to your OBS scene.

You probably will also want to adjust the default video output settings in OBS to record as mp4.

Very interested to know if this is useful for people, so please reply here with any comments or questions. Happy patching!

n4m-obs.zip
application/zip 15.96 KB

TConnors's icon

Nice one! Thanks.

noesbarco's icon

Thanks so much!

Iain Duncan's icon

Ah fantastic, I was going to make something like this to control OBS with my launchpads as foot pedals, so I think you just saved me hours and hours of work! :-)

matmat's icon

Oh! Thank you very much!

wbreidi's icon

Thank you, this is very useful.

testcase's icon

fantastic!

Tom Hall's icon

badass, thanks Rob

Riccardo Santalucia's icon
Icarart's icon

Very usefull for me, thank you !

jvkr's icon

This very helpful script stopped working in the more recent versions of OBS with builtin web socket. I managed to get it working again by making some adjustments. I did not deal with the recording part, just the switching of scenes. Make sure to update the version of obs-websocket-js in the package.json file to 5.0.2.

const maxApi = require('max-api');
const OBSWebSocket = require('obs-websocket-js').default;
maxApi.post("hello n4m-obs");
const obs = new OBSWebSocket();
let connected = false;
maxApi.addHandler('connect', () => {
obs.connect(
        'ws://127.0.0.1:4455'//, add password here if enabled
        // 'super-sekret'
    )
    .then(() => {
 maxApi.post(`Success! We're connected & authenticated.`);
        return obs.call('GetSceneList');
    })
    .then(data => {
        connected = true;
 
 maxApi.post(`Current Scene is ${data.currentProgramSceneName}`);
 maxApi.post(`${data.scenes.length} Available Scenes`);
 
        maxApi.outlet('scenelist');
        data.scenes.forEach(scene => {
            maxApi.outlet("scene", scene.sceneName);
        });
    })
    .catch(err => { // Promise convention dicates you have a catch on every chain.
 maxApi.post(err);
    });
});
maxApi.addHandler('set_scene', (sceneName) => {
    if(connected) {
 obs.call('SetCurrentProgramScene', {
            'sceneName': sceneName
        });
    }
    else {
 maxApi.post("not connected to OBS");
    }
});
Rob Ramirez's icon

thanks much for sharing! if you are able to make a pull request on the github repo that would be appreciated.

jvkr's icon

@Rob Ramirez: As I have no experience with github, this appears to be quite a challenge for me, apologies.

bmilbrand's icon

Does anyone have a working version of this object? I tried updating as suggested in this post, and I can't seem to get it working. Any help would be greatly appreciated. I'm trying to remotely control OBS on multiple machines based on facial tracking in live surveillance done in Max. Any help would be greatly appreciated.

Rob Ramirez's icon

Ok dusted this one off and got things working again with recent versions of OBS. There is no longer a need to install a web-socket plugin as it is now supported natively in OBS.