How to Automatically Change OBS Scenes with Python

Yes, you can easily use a Python script in OBS Studio to automatically change scenes on a timer. This article provides a quick guide on how to set up Python in OBS, a ready-to-use script to cycle through your scenes, and instructions on how to run it.

OBS Studio requires a local installation of Python to run .py scripts.

  1. Download and install Python from the official Python website (ensure you install the specific version supported by your version of OBS, usually Python 3.10 or 3.11).
  2. Open OBS Studio and go to Tools > Scripts.
  3. Click on the Python Settings tab.
  4. Browse and select the path to your Python installation folder (e.g., C:/Users/YourUsername/AppData/Local/Programs/Python/Python310 on Windows).

Step 2: Create the Python Script

Create a new text file on your computer, paste the code below into it, and save it as obs_scene_rotator.py.

import obspython as obs

# Global variables
interval = 10
scene_names = []
current_index = 0

def timer_callback():
    global current_index, scene_names
    if not scene_names:
        return

    # Increment and loop the scene index
    current_index = (current_index + 1) % len(scene_names)
    next_scene_name = scene_names[current_index]

    # Find and switch to the next scene
    scenes = obs.obs_frontend_get_scenes()
    for scene in scenes:
        name = obs.obs_source_get_name(scene)
        if name == next_scene_name:
            obs.obs_frontend_set_current_scene(scene)
            break
    obs.source_list_release(scenes)

def script_description():
    return "Automatically cycles through a list of comma-separated scenes on a set timer."

def script_properties():
    props = obs.obs_properties_create()
    obs.obs_properties_add_int(props, "interval", "Timer Interval (seconds)", 1, 3600, 1)
    obs.obs_properties_add_string(props, "scenes", "Scenes (comma-separated)", obs.OBS_TEXT_DEFAULT)
    return props

def script_update(settings):
    global interval, scene_names
    interval = obs.obs_data_get_int(settings, "interval")
    scenes_string = obs.obs_data_get_string(settings, "scenes")
    
    # Parse the comma-separated scenes list
    scene_names = [s.strip() for s in scenes_string.split(",") if s.strip()]

    obs.timer_remove(timer_callback)
    if interval > 0 and len(scene_names) > 0:
        obs.timer_add(timer_callback, interval * 1000)

Step 3: Load and Configure the Script in OBS

  1. Open Tools > Scripts in OBS Studio.
  2. Under the Scripts tab, click the + (plus) icon at the bottom-left.
  3. Locate and select your obs_scene_rotator.py file.
  4. Once loaded, you will see settings on the right side of the window.
  5. In the Scenes field, type the exact names of your scenes separated by commas (e.g., Scene 1, Scene 2, Scene 3).
  6. Set your desired Timer Interval in seconds.

The script will immediately begin cycling through your specified scenes at the designated interval.