If you're a streamer or video creator, having a custom timer in OBS (Open Broadcaster Software) can be incredibly useful. Whether you're timing events, managing segments, or just keeping track of time, a custom timer script can enhance your streaming experience. In this article, we'll walk you through creating a custom timer script in Python that integrates with OBS, automatically resetting each time the scene changes.
Why Use a Custom Timer?
A custom timer allows you to:
- Track time spent on different scenes or segments.
- Display time in a way that fits your stream's aesthetics.
- Have a timer that resets automatically with scene changes, keeping your stream organized.
Requirements
- OBS Studio
- Python installed on your system
- Tkinter library (usually included with Python)
The Script
Here's a Python script that creates a timer popup window for OBS. The timer resets every time the scene changes and always remains on top of other windows.
import obspython as obsimport timefrom threading import Threadimport tkinter as tk# Global variablestimer_running = Falsestart_time = Nonetimer_label = Noneroot = None# Function to start the timerdef start_timer():global timer_running, start_timetimer_running = Truestart_time = time.time()update_timer()# Function to stop the timerdef stop_timer():global timer_runningtimer_running = False# Function to reset the timerdef reset_timer():global start_timestart_time = time.time()# Function to update the timerdef update_timer():if timer_running:elapsed_time = time.time() - start_timehours, rem = divmod(elapsed_time, 3600)minutes, seconds = divmod(rem, 60)timer_label.config(text="{:02}:{:02}:{:02}".format(int(hours)\, int(minutes), int(seconds)))root.after(1000, update_timer)# OBS callback when the scene changesdef on_event(event):if event == obs.OBS_FRONTEND_EVENT_SCENE_CHANGED:reset_timer()# Function to create the timer windowdef create_timer_window():global root, timer_labelroot = tk.Tk()root.title("OBS Timer")# Set the timer window to always stay on toproot.attributes("-topmost", True)# Set window sizewindow_width = 280window_height = 80# Set the window size and positionscreen_width = root.winfo_screenwidth()screen_height = root.winfo_screenheight()x = screen_width - window_width - 10y = screen_height - window_height - 85root.geometry(f"{window_width}x{window_height}+{x}+{y}")# Set the background color to very dark greyroot.configure(bg="#1a1a1a")timer_label = tk.Label(root, text="00:00:00", font=("Pricedown Bl", 48)\, fg="purple", bg="#1a1a1a")timer_label.pack()start_timer()root.mainloop()# OBS script descriptiondef script_description():return "Timer popup that resets on scene change, always visible on top \of other windows, and positioned in the lower right corner."# OBS script loaddef script_load(settings):obs.obs_frontend_add_event_callback(on_event)timer_thread = Thread(target=create_timer_window)timer_thread.start()# OBS script unloaddef script_unload():stop_timer()if root:root.quit()
Instructions for Loading the Script into OBS
Save the Script: Copy the provided script and save it as a
.py
file on your computer.Open OBS Studio: Launch OBS Studio on your system.
Add the Script:
- Go to
Tools
in the top menu. - Select
Scripts
from the dropdown. - In the Scripts dialog, click the
+
button to add a new script. - Browse to the location of your saved Python script and select it.
- Go to
Run the Script: The script will now start running, and you should see a timer window appear in the lower right corner of your screen. This timer will reset every time you switch scenes in OBS.
With this custom timer script, you can keep track of time more effectively during your streams or recordings. The integration with OBS ensures that your timer resets with each scene change, making it a valuable tool for managing live content. Enjoy your enhanced streaming setup!
Feel free to adjust or expand upon this draft as needed!
No comments:
Post a Comment