Control OBS recorder via N4M script
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!
Nice one! Thanks.
Thanks so much!
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! :-)
Oh! Thank you very much!
Thank you, this is very useful.
fantastic!
badass, thanks Rob
super!
Very usefull for me, thank you !
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");
}
});
thanks much for sharing! if you are able to make a pull request on the github repo that would be appreciated.
@Rob Ramirez: As I have no experience with github, this appears to be quite a challenge for me, apologies.
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.
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.