Click These:

Tuesday, August 20, 2024

Automating Timestamps in OBS: A Python Script for Seamless Scene Logging

Are you looking for a way to automatically track and save timestamps for your OBS scenes during streams or recordings? Whether you're a content creator managing gaming streams, podcasts and interviews, tutorials and reviews, tarot and astrology readings, or any other type of live or recorded content, this Python script will streamline the process. No more manual logging of scene changes—this script will generate a detailed timestamp file when you stop streaming or recording.

Why Automate Scene Timestamps?

Tracking scene transitions is crucial for organizing content, especially when you review your footage or create time-based highlights. Manual tracking can be tedious, and OBS doesn’t have a built-in feature to log timestamps in a user-friendly way. That's where automation comes in.

With this Python script, timestamps are logged and saved as a text file automatically, making the post-production process much smoother. And, it even generates hashtags that are useful for astrologers or tarot readers, making the script perfect for niche content creators!

How the Script Works

This Python script integrates seamlessly with OBS, capturing when scenes change and logging their durations. When the stream or recording ends, a timestamp file is generated and saved to your desktop. Here's a breakdown of how the script works:

  1. Scene Tracking: The script captures each scene name and its duration during the stream or recording session.
  2. Hashtag Generation: The script adds pre-configured hashtags, like #tarot #astrology #allsigns #tarotreading #love #lovereading, to the timestamp file.
  3. Timestamps and Total Duration: For each scene, a starting timestamp is logged, and once the session ends, the total stream/recording time is appended at the bottom of the file.
  4. Output: The result is a well-organized text file saved to your desktop, containing a breakdown of each scene's start time and the total session duration.

The Python Script: "timestamps.py"

import os import datetime # Generate timestamp file on stop def generate_timestamp_file(mode): global scene_history, start_time # Automatically get the desktop path for the current user desktop_path = os.path.join(os.path.expanduser("~"), "Desktop") timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S") filename = os.path.join(desktop_path, f"timestamps_{timestamp}.txt") total_duration = time.time() - start_time total_duration_str = time.strftime("%H:%M:%S", time.gmtime(total_duration)) with open(filename, 'w') as f: # Write hashtags f.write("#tarot #astrology #allsigns #tarotreading #love #lovereading\n\n") # Calculate starting time for each scene accumulated_time = 0 for i, (scene_name, duration) in enumerate(scene_history): start_time_str = time.strftime("%H:%M:%S", time.gmtime(accumulated_time)) f.write(f"{scene_name}: {start_time_str}\n") accumulated_time += duration # Add total duration after a blank line f.write("\n") if mode == "stream": f.write(f"Total stream time: {total_duration_str}\n") else: f.write(f"Total recording time: {total_duration_str}\n") print(f"Timestamps saved to {filename}")

Setting It Up

To use this script with OBS, follow these simple steps:

  1. Save the Script: Copy the Python code and paste it into a new text file. Save the file as timestamps.py on your computer.

  2. Install Python: If you don’t have Python installed, download it from the official Python website at python.org. Make sure to check the option to "Add Python to PATH" during installation.

  3. Adding the Python Path to OBS: In OBS, go to Tools > Scripts, then click on the Python Settings tab. Browse and set the Python Install Path to the folder where Python is installed (usually something like C:\Python39 or similar). OBS requires Python 3.6 - 3.9 to run Python scripts.

  4. Add the Script to OBS: In the Scripts window of OBS, click the + button, locate your saved timestamps.py file, and load it as an active script. This will trigger the functions of the script whenever a recording or stream is started, and automate timestamp logging when you stop recording or streaming.

Why This Script Stands Out

  • Automation: No manual effort is required—once set up, the script runs in the background and logs your timestamps automatically.
  • User-Friendly: The timestamp file is saved directly to your desktop for easy access.
  • Versatile: It works for both streams and recordings, ensuring you never miss out on logging important scene transitions.

Conclusion

Whether you're livestreaming games, podcasts, tarot readings, astrology sessions, educational material, or doing live or recorded content creation of any kind, this Python script helps you keep track of your scene transitions effortlessly. With timestamps and total durations neatly organized, you can easily revisit key moments in your streams or recordings.

Integrate this automation into your OBS workflow and let the script handle the heavy lifting for you!

Saturday, August 17, 2024

How to Create a Custom On Screen Timer Script for OBS that Resets with Scene Changes

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 obs
import time
from threading import Thread
import tkinter as tk

# Global variables
timer_running = False
start_time = None
timer_label = None
root = None

# Function to start the timer
def start_timer():
    global timer_running, start_time
    timer_running = True
    start_time = time.time()
    update_timer()

# Function to stop the timer
def stop_timer():
    global timer_running
    timer_running = False

# Function to reset the timer
def reset_timer():
    global start_time
    start_time = time.time()

# Function to update the timer
def update_timer():
    if timer_running:
        elapsed_time = time.time() - start_time
        hours, 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 changes
def on_event(event):
    if event == obs.OBS_FRONTEND_EVENT_SCENE_CHANGED:
        reset_timer()

# Function to create the timer window
def create_timer_window():
    global root, timer_label
    root = tk.Tk()
    root.title("OBS Timer")

    # Set the timer window to always stay on top
    root.attributes("-topmost", True)

    # Set window size
    window_width = 280
    window_height = 80

    # Set the window size and position
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()
    x = screen_width - window_width - 10
    y = screen_height - window_height - 85

    root.geometry(f"{window_width}x{window_height}+{x}+{y}")

    # Set the background color to very dark grey
    root.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 description
def 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 load
def script_load(settings):
    obs.obs_frontend_add_event_callback(on_event)
    timer_thread = Thread(target=create_timer_window)
    timer_thread.start()

# OBS script unload
def script_unload():
    stop_timer()
    if root:
        root.quit()


 Instructions for Loading the Script into OBS

  1. Save the Script: Copy the provided script and save it as a .py file on your computer.

  2. Open OBS Studio: Launch OBS Studio on your system.

  3. 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.
  4. 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!