Advanced Scene Switcher

Advanced Scene Switcher 1.29.2

Warmuptill

Active Member
@Warmuptill
Is there a way, or could it be added :), a way to run a windows CMD directly from AdvSS?
Currently I use the FILE command to echo out the code syntax to a .bat file, then use the RUN command to execute it.
I am not sure to honest.
If I would do that I would likely have to support all kinds of shells / environments to avoid confusion, which I would want to avoid.

You could however "build your own" action type using the scripting interface.
I assume something like this could do the trick:

Python:
import obspython as obs

# Required by advss helpers
import threading
from typing import NamedTuple

# Required for the custom action
import subprocess

###############################################################################

# Define the settings available for the user for this action type
def get_action_properties():
    props = obs.obs_properties_create()
    obs.obs_properties_add_text(props, "script_to_run", "Script", obs.OBS_TEXT_MULTILINE)
    return props


# Set default values for each setting
def get_action_defaults():
    default_settings = obs.obs_data_create()
    obs.obs_data_set_default_string(default_settings, "script_to_run", "echo \"hello world!\"")
    return default_settings


# The settings for each instance of this action the will be passed in the
# "data" argument
def run_cmd_action(data, instance_id):
    script = obs.obs_data_get_string(data, "script_to_run")
    # Build a single line command to run
    command = " & ".join(script.splitlines())
    result = subprocess.run(command, shell=True, capture_output=True, text=True)
    obs.script_log(obs.LOG_INFO, result.stdout)
    obs.script_log(obs.LOG_INFO, result.stderr)

###############################################################################


def script_load(settings):
    # Register the custom action
    advss_register_action(
        "CMD",
        run_cmd_action,
        get_action_properties,
        get_action_defaults(),
    )

def script_unload():
    advss_deregister_action("CMD")


###############################################################################

# Advanced Scene Switcher helper functions below:
# Omitted for brevity - can be found here:
# https://github.com/WarmUpTill/SceneSwitcher/blob/master/scripting/examples.py#L195-L461
# Just copy paste to the end of the script

I attached the full script to this message. (never mind, can't do that apparently)

Simply import it in the scripts dialog.
1743699655795.png


1743699573700.png


Let me know if you run into any issues!

Is it possible to do this within a single macro? I'd love to not have to make a separate one for each program I would like to open at launch, but if I have to then so be it. At least the copy process won't make it too difficult.
I don't think something like this is possible in a single macro.

Just for my understanding: What are your exact concerns with splitting it up into multiple macros?
If you simply don't want to "clutter" the macro list with too many macros you can group those macros:
Example.gif


Hello! Thank you so much for the plugin!
I'm experiencing the difficulties with setting up Macro to make it work. This is what I'm trying to do:
IF: Twitch - [Within the last 10.00 seconds / no duration] - [selected channel] - Points reward redeemed - [selected reward] - Check using account [selected] (all permissions are given)
ACTION: Scene item visibility - [selected scene] - Show - [selected source]

If I click Run Macro it works. If I redeem the selected reward it doesn't work. Any thoughts what can be wrong?
Thank you in advance!

OBS 31.0.2
Advanced Switcher 1.29.2
I can't spot any obvious issue in the macro you have set up.

Can you please enable verbose logging and share an OBS log file of when you are trying to reproduce the issue?
Are you able to receive other events like for example "Stream went live" after going live?
 

ArdSagart

New Member
I can't spot any obvious issue in the macro you have set up.

Can you please enable verbose logging and share an OBS log file of when you are trying to reproduce the issue?
Are you able to receive other events like for example "Stream went live" after going live?

Verbose enabled. Log file looks like:
Code:
22:27:22.685: [adv-ss] started
22:27:22.685: [adv-ss] try to sleep for 300
22:27:22.986: [adv-ss] Twitch GET request to https://api.twitch.tv/helix/users?login=ardsagart began
22:27:23.251: [adv-ss] condition twitch returned 0
22:27:23.251: [adv-ss] Twitch EventSub connect started for ArdSagart
22:27:23.251: [adv-ss] Macro Reward returned 0
22:27:23.252: [adv-ss] try to sleep for 34
22:27:23.287: [adv-ss] condition twitch returned 0
22:27:23.287: [adv-ss] Macro Reward returned 0
22:27:23.287: [adv-ss] Twitch POST request to https://api.twitch.tv/helix/eventsub/subscriptions? began
22:27:23.287: [adv-ss] try to sleep for 300
22:27:23.394: [adv-ss] Twitch EventSub connection opened
22:27:23.398: [adv-ss] Discarding Twitch EventSub with invalid timestamp
22:27:23.563: [adv-ss] failed to register Twitch EventSub (400)
22:27:23.588: [adv-ss] condition twitch returned 0
22:27:23.588: [adv-ss] Macro Reward returned 0
22:27:23.588: [adv-ss] Twitch POST request to https://api.twitch.tv/helix/eventsub/subscriptions? began
22:27:23.589: [adv-ss] try to sleep for 300
22:27:23.847: [adv-ss] failed to register Twitch EventSub (400)
22:27:23.890: [adv-ss] condition twitch returned 0
22:27:23.890: [adv-ss] Macro Reward returned 0
22:27:23.890: [adv-ss] Twitch POST request to https://api.twitch.tv/helix/eventsub/subscriptions? began
22:27:23.891: [adv-ss] try to sleep for 300
22:27:24.155: [adv-ss] failed to register Twitch EventSub (400)
22:27:24.191: [adv-ss] condition twitch returned 0
22:27:33.398: [adv-ss] Discarding Twitch EventSub with invalid timestamp
22:27:33.490: [adv-ss] failed to register Twitch EventSub (400)
22:27:33.531: [adv-ss] condition twitch returned 0
22:27:33.532: [adv-ss] Macro Reward returned 0
22:27:33.532: [adv-ss] Twitch POST request to https://api.twitch.tv/helix/eventsub/subscriptions? began
22:27:33.532: [adv-ss] try to sleep for 300
22:27:33.797: [adv-ss] failed to register Twitch EventSub (400)
22:27:33.833: [adv-ss] condition twitch returned 0

22:27:43.471: [adv-ss] Macro Reward returned 0
22:27:43.471: [adv-ss] Twitch EventSub connect started for ArdSagart
22:27:43.471: [adv-ss] try to sleep for 300
22:27:43.772: [adv-ss] condition twitch returned 0
22:27:43.772: [adv-ss] Macro Reward returned 0
22:27:43.772: [adv-ss] try to sleep for 300
22:27:44.074: [adv-ss] condition twitch returned 0
22:27:44.074: [adv-ss] Macro Reward returned 0
22:27:44.074: [adv-ss] try to sleep for 300
22:27:44.375: [adv-ss] condition twitch returned 0
I tried another option - "chat message received", it also not works.
 

DaZuru

New Member
Great plugin! I have a few macros that kick off on a scheduled date that work fine but I am not able to setup an automated streaming set of macros. My scenario is that my daughter-in-law is wanting to stream my grandchildren's sporting events to the rest of the family. I have her setup to use vdo.ninja to send video from her phone to OBS and I stream it out via Owncast. I would love to find a way to have it automatically detect that she is sending video to OBS Studio and then kick off a stream and start recording. I have tried detecting video changes and was able to get everything started but I can't find a way to stop it when she stops sending video. I've gotten close, but I think my macros are fighting each other. I turned on Visual settings and I think my Start and Stop macros are firing against each other, causing them to not execute when I expect them to. Not sure what conditions I should use to start on video source sending data and what to use to detect her video has ended and then stop everything. Any ideas on what I could try next?
 

yukon92

Member
I am not sure to honest.
If I would do that I would likely have to support all kinds of shells / environments to avoid confusion, which I would want to avoid.

You could however "build your own" action type using the scripting interface.
I assume something like this could do the trick:

Python:
import obspython as obs

# Required by advss helpers
import threading
from typing import NamedTuple

# Required for the custom action
import subprocess

###############################################################################

# Define the settings available for the user for this action type
def get_action_properties():
    props = obs.obs_properties_create()
    obs.obs_properties_add_text(props, "script_to_run", "Script", obs.OBS_TEXT_MULTILINE)
    return props


# Set default values for each setting
def get_action_defaults():
    default_settings = obs.obs_data_create()
    obs.obs_data_set_default_string(default_settings, "script_to_run", "echo \"hello world!\"")
    return default_settings


# The settings for each instance of this action the will be passed in the
# "data" argument
def run_cmd_action(data, instance_id):
    script = obs.obs_data_get_string(data, "script_to_run")
    # Build a single line command to run
    command = " & ".join(script.splitlines())
    result = subprocess.run(command, shell=True, capture_output=True, text=True)
    obs.script_log(obs.LOG_INFO, result.stdout)
    obs.script_log(obs.LOG_INFO, result.stderr)

###############################################################################


def script_load(settings):
    # Register the custom action
    advss_register_action(
        "CMD",
        run_cmd_action,
        get_action_properties,
        get_action_defaults(),
    )

def script_unload():
    advss_deregister_action("CMD")


###############################################################################

# Advanced Scene Switcher helper functions below:
# Omitted for brevity - can be found here:
# https://github.com/WarmUpTill/SceneSwitcher/blob/master/scripting/examples.py#L195-L461
# Just copy paste to the end of the script

I attached the full script to this message. (never mind, can't do that apparently)

Simply import it in the scripts dialog.
View attachment 112588

View attachment 112587

Let me know if you run into any issues!


I don't think something like this is possible in a single macro.

Just for my understanding: What are your exact concerns with splitting it up into multiple macros?
If you simply don't want to "clutter" the macro list with too many macros you can group those macros:
View attachment 112589


I can't spot any obvious issue in the macro you have set up.

Can you please enable verbose logging and share an OBS log file of when you are trying to reproduce the issue?
Are you able to receive other events like for example "Stream went live" after going live?
I THINK I get what you are saying. Take the code, put it into a file called "cmd_action.py"
Load that script into OBS.
Then a "CMD" option should be available. I've tried it a couple of different ways, but I'm not seeing anything appear.
(ran as admin, ran in fresh install etc). What you are showing in your script example above is exactly what I am looking for.
1743734117413.png
 

Warmuptill

Active Member
I THINK I get what you are saying. Take the code, put it into a file called "cmd_action.py"
Load that script into OBS.
Then a "CMD" option should be available. I've tried it a couple of different ways, but I'm not seeing anything appear.
(ran as admin, ran in fresh install etc). What you are showing in your script example above is exactly what I am looking for.
View attachment 112596
I have uploaded the full script here:

Please try using that one. :)

How can I go about converting/mapping values from an HTTP GET action of JSON into a variable, or access the JSON response to parse into variables?
Assuming the GET request returns the json string {"data": "test"} and you would want to access the field named data and assign it to a variable you could use a setup like this:

1743785056743.png


Great plugin! I have a few macros that kick off on a scheduled date that work fine but I am not able to setup an automated streaming set of macros. My scenario is that my daughter-in-law is wanting to stream my grandchildren's sporting events to the rest of the family. I have her setup to use vdo.ninja to send video from her phone to OBS and I stream it out via Owncast. I would love to find a way to have it automatically detect that she is sending video to OBS Studio and then kick off a stream and start recording. I have tried detecting video changes and was able to get everything started but I can't find a way to stop it when she stops sending video. I've gotten close, but I think my macros are fighting each other. I turned on Visual settings and I think my Start and Stop macros are firing against each other, causing them to not execute when I expect them to. Not sure what conditions I should use to start on video source sending data and what to use to detect her video has ended and then stop everything. Any ideas on what I could try next?
Can you maybe share screenshots of your macro setup or better export your settings to a file or export the relevant macros and share the import code?

Maybe you could introduce some sort of state handling and pause / unpause the macros which are not relevant to the current state?
(Sorry for being so vague, but I need more information to give concrete tips / instructions :))

Verbose enabled. Log file looks like:
Code:
22:27:22.685: [adv-ss] started
22:27:22.685: [adv-ss] try to sleep for 300
22:27:22.986: [adv-ss] Twitch GET request to https://api.twitch.tv/helix/users?login=ardsagart began
22:27:23.251: [adv-ss] condition twitch returned 0
22:27:23.251: [adv-ss] Twitch EventSub connect started for ArdSagart
22:27:23.251: [adv-ss] Macro Reward returned 0
22:27:23.252: [adv-ss] try to sleep for 34
22:27:23.287: [adv-ss] condition twitch returned 0
22:27:23.287: [adv-ss] Macro Reward returned 0
22:27:23.287: [adv-ss] Twitch POST request to https://api.twitch.tv/helix/eventsub/subscriptions? began
22:27:23.287: [adv-ss] try to sleep for 300
22:27:23.394: [adv-ss] Twitch EventSub connection opened
22:27:23.398: [adv-ss] Discarding Twitch EventSub with invalid timestamp
22:27:23.563: [adv-ss] failed to register Twitch EventSub (400)
22:27:23.588: [adv-ss] condition twitch returned 0
22:27:23.588: [adv-ss] Macro Reward returned 0
22:27:23.588: [adv-ss] Twitch POST request to https://api.twitch.tv/helix/eventsub/subscriptions? began
22:27:23.589: [adv-ss] try to sleep for 300
22:27:23.847: [adv-ss] failed to register Twitch EventSub (400)
22:27:23.890: [adv-ss] condition twitch returned 0
22:27:23.890: [adv-ss] Macro Reward returned 0
22:27:23.890: [adv-ss] Twitch POST request to https://api.twitch.tv/helix/eventsub/subscriptions? began
22:27:23.891: [adv-ss] try to sleep for 300
22:27:24.155: [adv-ss] failed to register Twitch EventSub (400)
22:27:24.191: [adv-ss] condition twitch returned 0
22:27:33.398: [adv-ss] Discarding Twitch EventSub with invalid timestamp
22:27:33.490: [adv-ss] failed to register Twitch EventSub (400)
22:27:33.531: [adv-ss] condition twitch returned 0
22:27:33.532: [adv-ss] Macro Reward returned 0
22:27:33.532: [adv-ss] Twitch POST request to https://api.twitch.tv/helix/eventsub/subscriptions? began
22:27:33.532: [adv-ss] try to sleep for 300
22:27:33.797: [adv-ss] failed to register Twitch EventSub (400)
22:27:33.833: [adv-ss] condition twitch returned 0

22:27:43.471: [adv-ss] Macro Reward returned 0
22:27:43.471: [adv-ss] Twitch EventSub connect started for ArdSagart
22:27:43.471: [adv-ss] try to sleep for 300
22:27:43.772: [adv-ss] condition twitch returned 0
22:27:43.772: [adv-ss] Macro Reward returned 0
22:27:43.772: [adv-ss] try to sleep for 300
22:27:44.074: [adv-ss] condition twitch returned 0
22:27:44.074: [adv-ss] Macro Reward returned 0
22:27:44.074: [adv-ss] try to sleep for 300
22:27:44.375: [adv-ss] condition twitch returned 0
I tried another option - "chat message received", it also not works.
Thanks for sharing the log!
It seems like I made a mistake verifying the timestamps sent out by Twitch by not taking time zones into consideration.

A build with a fix will be available here in a few minutes:
You will have to be logged into GitHub to be able to download it.
Let me know if that should be a problem and I can try to share it via other means.

I would appreciate if you could confirm if this does indeed resolve the issue!
Thanks again! :)
 
Last edited:

ArdSagart

New Member
Thanks for sharing the log!
It seems like I made a mistake verifying the timestamps sent out by Twitch by not taking time zones into consideration.

A build with a fix will be available here in a few minutes:
You will have to be logged into GitHub to be able to download it.
Let me know if that should be a problem and I can try to share it via other means.

I would appreciate if you could confirm if this does indeed resolve the issue!
Thanks again! :)
I need a build for Windows. I'll wait for it. Of course I'll post my feedback if it woks or not! Thank you!
 

ArdSagart

New Member

Tallicia

Member
@Warmuptill Thank you for this! This has been helpful!

I am encountering what feels like very inelegant ways to get multiple nested values from the json, I'll post screenshots and examples soon, if there isn't a config file that is easier to post. but basically I have to take the response into a temp and then drill through the temp to each item, and then start the drill from the original response using temp to finally get the value in it's nested depth to the variable du jour.
 

gantzz

New Member
Hey, I didn't use OBS for a while, I updated it (31.0.03) and suddenly Advanced Scene Switcher disappeared. I then downloaded the newest version of Advanced Scene Switcher, installed it again and the plugin still doesn't show up inside OBS. When I go the Tools tab it's not even listed there. I checked and there's not even an advanced scene switcher config folder for in C:\Users\<Your Username Here>\AppData\Roaming\obs-studio\plugin_config\ ...
Is advanced scene switcher not supported by the newest OBS versions anymore?
I'm on Win10 btw and I made sure to run the installer as admin + restarted OBS after the install, too.
 
Last edited:

Gunthrek

New Member
I've been using this plugin extensively for a while, but I've started doing minimal video editing to cut out portions where I've been talking, which removed my need for it since I end up having to render the video with the overlays I was using this plugin to display anyway. My video editing has pretty much only been to cut out portions where I'm not talking, and I just discovered the microphone detection part of the plugin that allows me to pause the video when mic output drops below a set threshold, basically making it to where the recording pauses when I stop talking.

My question is twofold:

1. Is there a way to buffer about a second's worth of video while the recording is technically paused so that when the plugin automatically unpauses it inserts a half second or second worth of what happened right before the unpause button was pressed so there's no clipped returns to talking, and;

2. Is there a way to make it so that the mic output doesn't trigger a pause unless the output is lower than the threshold for a set number of seconds? I don't want every breath or second of thought to provoke a pause.

My goal here is to make it so that the recording pauses when I'm not talking for more than a second or two, continuously buffers a second of video during the pause, then pastes that second of buffered video before the actual unpause so I don't get my speech clipped off the front because the unpause doesn't react fast enough. It would probably be more like .5 seconds, but you get the idea.

I'm aware that there is editing options that will do this automatically, but most of them are $1-300 or require a monthly subscription, and I really don't want to fork over that much money for something as simple as removing portions of my videos where I'm not talking.
 

Warmuptill

Active Member
1. Is there a way to buffer about a second's worth of video while the recording is technically paused so that when the plugin automatically unpauses it inserts a half second or second worth of what happened right before the unpause button was pressed so there's no clipped returns to talking, and;
Unfortunately, the plugin cannot modify the behavior of OBS' functionality to pause recordings.
You might maybe be able to set up something similar using the "Replay buffer" functionality.

1744041211191.png


But this will of course be a separate recording file, which you would then have to manually stick back together with you main recording.

2. Is there a way to make it so that the mic output doesn't trigger a pause unless the output is lower than the threshold for a set number of seconds? I don't want every breath or second of thought to provoke a pause.
Yes that is possible using duration modifiers for your conditions.
For example:
1744041368659.png


I hope that helps!
 

Gunthrek

New Member
Unfortunately, the plugin cannot modify the behavior of OBS' functionality to pause recordings.
You might maybe be able to set up something similar using the "Replay buffer" functionality.

View attachment 112685

But this will of course be a separate recording file, which you would then have to manually stick back together with you main recording.


Yes that is possible using duration modifiers for your conditions.
For example:
View attachment 112686

I hope that helps!
The first part defeats the purpose for trying to use the function the way I am to avoid video editing, but I was pretty sure that was the case already, so thanks for the confirmation. Any ideas on ways to make the process a bit more anticipatory? I don't necessarily need there to be a bunch of space before the unpause, just always enough to prevent the first part of the first word getting clipped off.

I knew there was a way to adjust durations for things, just forgot that it was the clock button...duh me, lol. Thanks for the reminder!
 

yukon92

Member
@Warmuptill

Made some headway, got the CMD to install as per your additional instructions.

It doesn't work, but I do see an error in the log. It appears for me regardless of whatever i put in the box for "Script" I get the same error message in the log. Anything I should check closer?

1744068676089.png
 
Top