Change Replay Filename With Hotkey

Arkon

New Member
Hey there,

I'm hosting drone races and want to use OBS to streamline the review process of possible missed obstacles or other reasons. I get the live video from the drones into OBS via and HDMI matrix and Capture card. I'm usually a one-man-show so I make pilots spot other pilots for bad laps. During "regular" events there are downtime between single races that can be used to review claims. I want to venture into endurance/team racing where those downtime are not available right away. So either I have to bulk review the claims at a certain point or might have a helper with me who can take on that task.

My current idea is to use the replay buffer to optimize the review process. I was thinking to hook up an Arduino or similar to act as a keyboard and provide 4 hotkeys. Four competing pilots will be placed in front of a big screen to watch the live video of another pilot each. In case there is a missed obstacle, the pilot in charge can hit the button and OBS saves a XX seconds replay a helper or me can review at an appropriate time.

For some reasons (avoid spamming, easier identification of which pilot made the mistake) I'd love to have the file names with a certain naming convention. This has to be changed by the hotkey pressed. For example:
Hotkey F13 gets pressed I want the saved file to be named "Team 1 hh:mm:ss"
Hotkey F14 gets pressed I want the saved file to be named "Team 2 hh:mm:ss"
...

Someone with an idea or example code on how to use hotkeys to change the suffix/prefix/filename for replay recordings?
 

upgradeQ

Member
You can get the path of the last replay with this code, then rename or relocate it:

Python:
import obspython as S
import threading
from datetime import datetime
from time import sleep
from types import SimpleNamespace as _G


G = _G()
G.t1_start = False
G.t2_start = False
G.file_write_delay = 1.3
G.shutdown = False


def get_replay_buffer_output():
    replay_buffer = S.obs_frontend_get_replay_buffer_output()
    cd = S.calldata_create()
    ph = S.obs_output_get_proc_handler(replay_buffer)
    S.proc_handler_call(ph, "get_last_replay", cd)
    path = S.calldata_string(cd, "path")
    S.calldata_destroy(cd)
    S.obs_output_release(replay_buffer)
    return path


def trigger_save_as(name, delay_ms):
    S.obs_frontend_replay_buffer_save()
    sleep(delay_ms)
    print(get_replay_buffer_output(), name)


def event_loop():
    while True:
        sleep(0.0001)
        if G.t1_start:
            trigger_save_as("team1", G.file_write_delay)
            G.t1_start = False
        if G.t2_start:
            trigger_save_as("team2", G.file_write_delay)
            G.t2_start = False
        if G.shutdown:
            raise KeyboardInterrupt


def path1_btn(*_):
    G.t1_start = True


def path2_btn(*_):
    G.t2_start = True


def script_properties():
    props = S.obs_properties_create()
    S.obs_properties_add_button(props, "button1", "set path 1", path1_btn)
    S.obs_properties_add_button(props, "button2", "set path 2", path2_btn)
    return props


def script_load(settings):
    t = threading.Thread(target=event_loop)
    t.start()


def script_unload():
    G.shutdown = True
Note: Save replay buffer doesn't dump to disk immediately, you have to wait a certain amount of time.
To add hotkey to this script, see example code here
 
Last edited:

AaronD

Active Member
You might look at this, instead of the replay buffer:
1686316295120.png

I don't use it myself - I just record the entire show in one file - so I don't know anything else beyond its existence. But just going by the labels, it seems like it might be closer to what you're looking for.
 
Top