Skip to content

Instantly share code, notes, and snippets.

@flerouwu
Last active March 29, 2025 18:29
obs-replay

Requirements

Installation

  1. Copy obs-replay.py to /usr/local/bin/obs-replay.
  2. Run sudo chmod +x /usr/local/bin/obs-replay.
  3. Configure OBS:
    1. Open Tools > WebSocket Server Settings.
    2. Check Enable WebSocket server.
    3. Uncheck Enable Authentication.
  4. Configure Replay Buffer in OBS:
    1. Open Settings > Output.
    2. Set Output Mode to Advanced.
    3. Click the Replay Buffer tab.
    4. Check Enable Replay Buffer.
    5. Set Maximum Replay Time to your wanted value (I used 120 seconds).
  5. Set a KDE global shortcut:
    1. Open the System Settings app in KDE Plasma.
    2. Navigate to Keyboard > Shortcuts.
    3. Click Add New > Command or Script....
    4. Set Command to /usr/local/bin/obs-replay.
    5. Click Add.
    6. Click + Add... under Custom shortcuts, and press your desired hotkeys.
  6. Test it :3
#!/usr/bin/python3
import asyncio
import obsws_python as obs
from desktop_notifier import DesktopNotifier, Urgency
class OBSReplay:
client: obs.ReqClient
notifier: DesktopNotifier
def __init__(self):
self.client = obs.ReqClient()
self.notifier = DesktopNotifier(
app_name = "obs-replay"
)
async def notify(self, title: str, content: str, urgency: Urgency = Urgency.Normal):
await self.notifier.send(
title = title,
message = content,
urgency = urgency
)
async def save_replay(self) -> bool:
if not self.client.get_replay_buffer_status().output_active:
await self.notify("Save Replay Failed", "Replay buffer output is not active.")
return False
self.client.save_replay_buffer()
return True
def is_recording(self):
return self.client.get_record_status().output_active
async def start_record(self) -> bool:
if self.is_recording():
await self.notify("Start Record Failed", "Record output is already active.")
return False
self.client.start_record()
return True
async def stop_record(self) -> bool:
if not self.is_recording():
await self.notify("Stop Record Failed", "Record output is not active.")
return False
self.client.stop_record()
return True
async def main(app: OBSReplay):
if app.is_recording(): # Stop recording
if not await app.stop_record():
return
await app.notify("Recording Stopped", "Reinvoke to save replay and start recording.")
else: # Save replay and start recording
if not await app.save_replay():
return
if not await app.start_record():
return
await app.notify("Replay Saved; Recording", "Replay saved and recording stated. Reinvoke to stop recording.")
async def main_wrapper():
app = OBSReplay()
try:
await main(app)
except Exception as exception:
await app.notify("Failed", exception)
if __name__ == "__main__":
asyncio.run(main_wrapper())
@Cooperly
Copy link

RUFF
RUFF
RUFF
RUFF
RUFF
RUFF
RUFF
RUFF
RUFF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment