Skip to content

Instantly share code, notes, and snippets.

@iandouglas
Created June 1, 2022 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iandouglas/826dd014e1b2e798359f6b018dc3e497 to your computer and use it in GitHub Desktop.
Save iandouglas/826dd014e1b2e798359f6b018dc3e497 to your computer and use it in GitHub Desktop.
scene switcher in OBS
import obspython as obs
import random
def cycle():
# get a list of all scenes from OBS
scenes = obs.obs_frontend_get_scenes()
# get current scene
current_scene = obs.obs_frontend_get_current_scene()
# get index of that current scene from our list of scenes
idx = scenes.index(current_scene)
# pick a random one, just in case line 12 doesn't work
next_idx = random.choice(scenes)
if idx is not None:
# if line 12 worked, then we'll pick the "next" one in the list
next_idx = (len(scenes) + idx+1) % len(scenes)
# set OBS scene to that scene
obs.obs_frontend_set_current_scene(scenes[next_idx])
def script_properties():
# this is the "setup panel" for the script
props = obs.obs_properties_create()
# it allows a timer here between 30 seconds and 1,000 seconds, and defaults to 30 seconds
# if you want to start faster, like a 10-second switch, change the first "30000" to "10000"
# the order is "minimum value", "maximum value", and "default value"
obs.obs_properties_add_int(props, "cycle_rate", "Cycle Rate(ms)", 30000, 1000000, 30000)
return props
def script_update(settings):
'''
this is what runs the whole thing
basically, it clears any previous timers for the "cycle" method above
then it gets the "cycle rate" variable from the settings panel that you set
and then adds a timer for that cycle rate to call your "cycle" method.
'''
obs.timer_remove(cycle)
blink_rate = obs.obs_data_get_int(settings, "cycle_rate")
obs.timer_add(cycle, blink_rate) # Change scene every cycle_rate ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment