Pages

Saturday, March 8, 2025

OBS PLUGIN - Advanced Scene Switcher

 Advanced Scene Switcher


Advanced Scene Switcher | OBS Forums

The basis of Advanced scene switcher is to detect the presence (or lack thereof) of a condition in OBS and follow a set of subsequent steps


Here are some examples:

SCENE

If a Specific Scene is Displayed -> Setup something in Preview
A real world condition might be if you go to a camera that is setup as a close up some someone, perhaps you would want to automatically set the preview screen with their name at the bottom.

If Advanced scene Switcher detects a specific scene in program, it can automatically ensure a specific scene is put into the preview monitor.  

Here we have 2 scenes, a closeup shot in preview (left) and a wide shot in program (right)


Useing AsS we can have a 3rd scene set into preview automatically with their name ready to be cut in using a rule like this:


This rule is 
If the current (program) scene matches (IE Camera 1 Closeup) 
then
Put the scene "Camera 1 Closeup with Name" into the preview window. 

So with out AsS running, when you go to the closeup shot in program, the prewiew window will switch to the old program window. 


BUT with AsS running with the rule as above, you will get this instead happen:


CLIPBOARD

Here we've created a scene with a wideshot and the text "This is a news flash"

Now we'll create a rule that if the computers clipboard contains the next "Breaking News", this scene will automatically be displayed.





CURSOR

Trigger something to happen depending on where the cursor is, if it detects motion or if a left, middle or right mouse button is selected.

In this example, we will set OBS to automatically go to the wide shot if the cursor is put into the upper left corner of the screen.

If the cursor moves to position X=0 and Y=0  (upper left corner of screen), it will automatically switch to the wide shot.


Current view



Mouse pointer goes to upper left corner

The shot becomes this:



DATE

   Have something occur at a specific date


In this example, at 13.:44 everyday, the system will start recording.

You could then have another macro that would stop the recording everyday at 15:00

DISPLAY

If OBS detects a certain display to be part of the system, it can send a specific video to that monitor.



FILE

You can have something occur in OBS if a file is present, or contains data. 
 In this example, we have a file called Closeup Activation.txt in the folder
C:\OBS Advanced Scene Switcher

If the content of this file has "Present" in it, OBS will automatically switch to the "Camera 1 Closeup"



The file looks like:




FILTER

Trigger an event if the "FILTER" on a specific scene or Source is active 

In this example, if the chroma filter is applied to the source called "Closeup Chroma" (which is an image in front of a green screen) then it will switch to a new scene applying a background (winter snow) to the image.  If its not there, it will disable it.   This uses the "ELSE" fuction.

The result:


FOLDER WATCH

If an event happens in a folder, have it do something in OBS.

In this example, although we show several specific options, if OBS detects ANY change in a folder, it will switch the scene to a wideshot.

HOTKEY

This allows a macro to be triggered based on a hotkey.  When selected, the hotkey NAME in the macro will match to a hotkey entry in the settings portion of OBS.


LOG

You can add log entries into your OBS logo (in windows its in %appdata% in obs-studio -> logs)
C:\Users\X\AppData\Roaming\obs-studio\logs



It is a great way for debugging scripts.  Doesn't add load, I've had hundreds of these being sent to the log regularly.

You can send variables states stored in ADVSS in your log files.  The variable name is case sensitive.
add in a ${VarName} to your log message. 



IDLE

If the system detects no key or mouse movements, it will trigger.  

In this example, after 5 seconds, OBS will go to a Wide shot.

WEBSOCKETS - 

There doesn't really seem to be a lot of sensical information on how this thing works with its command structure.  Not that this document is any better, but I'll put what I know to make this work.

For relevance, the examples below are using two computers with an instance of OBS on each one.
OBS 1 is the "switcher" sending video, and Websocket commands, to OBS 2 "graphics machine" to start recording.

We will be using Advanced Scene Switcher plugin.

Steps:

Activate Websockets in your Second OBS.    

Set a password and check the enable box.


I wont dive into ADVanced Scene Switcher here, but in your macro, you select Websocket, select "OBS websocket Message".  This plugin is only required on the sending computer.

To establish the initial connection to the machine running websockets, 
select the gear icon 
You create a name for this connection, and enter in the IP, port and password of the machine.




Here's an example of a json message in the websocket OBS window

Example Script
This will let you turn recording on/off


{

"d":

{

"requestData": {},

"requestId": "",

"requestType": "ToggleRecord"

},

"op": 6

}


The Code syntax for the following commands is as below

{

"d":

{

"requestData": {},

"requestId": "",

"requestType": "XXXXX"

},

"op": 6

}


You can substitute the XXXXX with some of the following examples:

StartRecord

StopRecrod

ToggleRecord

StartReplayBuffer

StopReplayBuffer

SaveReplayBuffer

StartVirtualCam

StopVirtualCam

ToggleVirtualCam



Heres some other commands.  Use this syntax


This will let you change the scene of a remote OBS.  
The command is "SetCurrentProgramScene"

But substitute "XXXXX" for your Scene Name

{

"op": 6,

"d":

{

"requestType": "SetCurrentProgramScene",

"requestId": "2",

"requestData":

{

"sceneName": "XXXXXX"

}

}

}




You can verify that a connection is happening if you look at the Websockets config page on your receiving machine.  You should see some references to the IP of your source computer




Here's a link to the github site with all the commands that you could potentially use.

obs-websocket/docs/generated/protocol.md at master · obsproject/obs-websocket · GitHub



WebSocket client disconnect code


UnknownReason = 4000,


The server was unable to decode the incoming websocket message

MessageDecodeError = 4001,

// The specified `messageType` was invalid

UnknownMessageType = 4002,

// The client sent a websocket message without first sending `Identify` message

NotIdentified = 4003,

// The client sent an `Identify` message while already identified

AlreadyIdentified = 4004,

// The authentication attempt (via `Identify`) failed

AuthenticationFailed = 4005,

// There was an invalid parameter the client's `Identify` message

InvalidIdentifyParameter = 4006,

// A `Request` or `RequestBatch` was missing its `requestId`

RequestMissingRequestId = 4007,

// The websocket session has been invalidated by the obs-websocket server.

SessionInvalidated = 4008,

// The server detected the usage of an old version of the obs-websocket protocol.

UnsupportedProtocolVersion = 4009,




HTML


I wanted to send a command from OBS to Vmix.  In this situation, OBS is the switcher, vMIX is the replay, so during a replay, i wanted to remote trigger vmix without needing an operator to do it.


vMIX can take web requests.  So in this example, I'm triggering the request using an HTTP request in the Advanced Scene Switcher.


The configuration looks like this. 


This is the syntax
http://VMIX-IP:PORT/api/?Function=COMMAND

Here's a list of possible commands that could be sent.

No comments:

Post a Comment

Feel free to leave a comment! If you have any information that you think should be included, please do so here and I'll get it added in.