1. The Python Script
Save this code as camera_switcher.py:
import obspython as obs
playlist = []
current_idx = 0
active_buffer = "Cam_A"
patrol_enabled = False
interval = 15000
def update_source(source_name, url, is_visible):
source = obs.obs_get_source_by_name(source_name)
if source:
settings = obs.obs_data_create()
items = obs.obs_data_array_create()
if url:
item = obs.obs_data_create()
obs.obs_data_set_string(item, "value", url)
obs.obs_data_array_push_back(items, item)
obs.obs_data_release(item)
obs.obs_data_set_array(settings, "playlist", items)
obs.obs_source_update(source, settings)
obs.obs_source_set_enabled(source, is_visible)
obs.obs_data_array_release(items)
obs.obs_data_release(settings)
obs.obs_source_release(source)
def switch_logic():
global current_idx, active_buffer
if not playlist: return
current_idx = (current_idx + 1) % len(playlist)
url = playlist[current_idx]
if active_buffer == "Cam_A":
update_source("Cam_B", url, True)
update_source("Cam_A", "", False)
active_buffer = "Cam_B"
else:
update_source("Cam_A", url, True)
update_source("Cam_B", "", False)
active_buffer = "Cam_A"
t_src = obs.obs_get_source_by_name("Cam_Number")
if t_src:
t_set = obs.obs_source_get_settings(t_src)
obs.obs_data_set_string(t_set, "text", "Camera " + str(current_idx + 1))
obs.obs_source_update(t_src, t_set)
obs.obs_data_release(t_set)
obs.obs_source_release(t_src)
def timer_callback():
if patrol_enabled:
switch_logic()
def btn_patrol_callback(props, prop):
global patrol_enabled, current_idx, active_buffer
patrol_enabled = not patrol_enabled
if patrol_enabled:
current_idx = -1
active_buffer = "Cam_B"
switch_logic()
return True
def script_properties():
props = obs.obs_properties_create()
obs.obs_properties_add_text(props, "url_list", "Paste RTSP Links Here", obs.OBS_TEXT_MULTILINE)
obs.obs_properties_add_button(props, "patrol_btn", "START STOP PATROL", btn_patrol_callback)
return props
def script_update(settings):
global playlist
raw_urls = obs.obs_data_get_string(settings, "url_list")
playlist = [line.strip() for line in raw_urls.split('\n') if line.strip()]
obs.timer_remove(timer_callback)
obs.timer_add(timer_callback, interval)
def script_unload():
obs.timer_remove(timer_callback)
2. Video Description / Tutorial Steps
Step 1: Setup Your Sources
Create three sources in your OBS Scene with these EXACT names:
Cam_A (VLC Video Source)
Cam_B (VLC Video Source)
Cam_Number (Text GDI+ Source)
Step 2: Install the Script
Go to Tools then Scripts.
Under Python Settings, ensure your Python Install Path is set.
Under Scripts, click the plus sign and load camera_switcher.py.
Step 3: Add Your Cameras
Paste your RTSP links (one per line) into the text box in the Scripts window.
Click the RELOAD icon (circular arrow).
Click the START STOP PATROL button.
Step 4: Make it Smooth
Go to the Scene Transitions dock.
Select Fade.
Set the duration to 1000ms for a professional 1-second dissolve.
Why this is better:
This script uses "Dual Buffering." While you watch Cam A, it kills the connection to Cam B. When it's time to switch, it starts Cam B and then kills Cam A. This saves massive amounts of internet bandwidth compared to standard playlists!