1

OBS allows you to change the pattern for the recordings filenames but there is no simple way to update the file name with any custom string before every recording.

You need to visit the options pane and change settings manualy. The default for the filename formating is: "%CCYY-%MM-%DD %hh-%mm-%ss"

Let's say you've changed the pattern to "MY-HOME-VIDEO %CCYY-%MM-%DD %hh-%mm-%ss" and recorded a file.

Then if you need to make another recording about something else with the prefix "MY-OTHER-VIDEO " you need to change the pattern again, manually.

How to update the filename formating without visiting options pane every time?

3 Answers 3

1

I've managed to achieve this using obs-websocket and simple/dirty python script. The obs-websocket plugin can get/set the pattern used by OBS to save recording files.

Steps: Install/configure obs-websocket plugin. Then use obs-cli (https://github.com/leafac/obs-cli) or obswebsocket (https://pypi.org/project/obs-websocket-py/).

cli example (under Windows os, beware of double quotes):

obs-cli-win SetFilenameFormatting="{ ""filename-formatting"": ""TESTNAME %CCYY-%MM-%DD %hh-%mm-%ss"" }" && ^
obs-cli-win StartRecording && ^
obs-cli-win SetFilenameFormatting="{ ""filename-formatting"": ""%CCYY-%MM-%DD %hh-%mm-%ss"" }" && ^
obs-cli-win GetFilenameFormatting

python example:

client = obswebsocket.obsws("localhost", 4444, "")
client.connect()
print(client.call(obswebsocket.requests.GetFilenameFormatting()))
client.call(obswebsocket.requests.SetFilenameFormatting("TESTNAME" + " - %CCYY-%MM-%DD %hh-%mm-%ss"))
client.call(obswebsocket.requests.StartRecording())
print(client.call(obswebsocket.requests.GetFilenameFormatting()))
client.call(obswebsocket.requests.SetFilenameFormatting("%CCYY-%MM-%DD %hh-%mm-%ss"))
print(client.call(obswebsocket.requests.GetFilenameFormatting()))
client.disconnect()
1

I saw your code on the OBS Forum as well and wanted to help here too.

I made some tweaks to your Python example and it worked great! I want to clarify some things in case anyone wants to do exacly what OP wanted. You should follow these steps:

  1. Install the obs-websocket plugin
  2. Install the obs-websocket-py which is the Python tool for the plugin (you can do this using pip)
  3. Create a new .py file wth this code:

Python:

import obswebsocket
from obswebsocket import obsws, events, requests

client = obswebsocket.obsws("localhost", 4444, "") #Change this if you have a different name, port or password
client.connect()
client.call(obswebsocket.requests.GetFilenameFormatting())
print("Hi! I'm your new video\nWhat's my name?\nFilename:")
client.call(obswebsocket.requests.SetFilenameFormatting(input() + " - %MM-%DD %hh-%mm")) #Custom name + date. The best of two worlds
client.call(obswebsocket.requests.StartRecording())
print(client.call(obswebsocket.requests.GetFilenameFormatting()))
client.call(obswebsocket.requests.SetFilenameFormatting("-%MM-%DD %hh-%mm-%ss"))
print(client.call(obswebsocket.requests.GetFilenameFormatting()))
client.disconnect()
  1. Open OBS and execute the code And voilà! A new window will open and it should ask you for your video's name and then start recording.

I wanted to write this bc it took me a lot of time to figure this out. So let me know if it helped you too.

1
  • Thanks for sharing.
    – wwk
    May 19, 2022 at 17:28
0

My final solution is a simple python script (for Windows) that starts OBS minimised (if not started yet), asks for the filename prefix and starts recording. Dirty but fits my needs.

#!/usr/bin/env python
import psutil
import obswebsocket
import obswebsocket.requests
import subprocess
import sys
import signal
import time

def signal_handler(sig, frame):
    print('\n\nExiting.')
    sys.exit(0)

obs_process_name = "obs64.exe"
obs_bin_dir = "C:\\Program Files\\obs-studio\\bin\\64bit\\"
obs_bin_full_path = obs_bin_dir + obs_process_name
obs_params = "--minimize-to-tray"

signal.signal(signal.SIGINT, signal_handler)

if len(sys.argv) >= 2:
    file_name_prefix = ' '.join(sys.argv[1:])
else:
    print("Enter recording name or exit with CTRL-C.")
    file_name_prefix = input("Recording name: ")

if not obs_process_name in (p.name() for p in psutil.process_iter()):
    print("Process " + obs_process_name + " not running. Starting.")
    subprocess.Popen([obs_bin_full_path, obs_params], cwd=obs_bin_dir)
else:
    print("Process " + obs_process_name + " already running.")

file_name_prefix = "".join([c for c in file_name_prefix if c.isalpha() or c.isdigit() or c == ' ']).rstrip()

print("Will use name [" + file_name_prefix + "].")

client = obswebsocket.obsws("localhost", PORT_NUMBER, "PASSWORD")

while True:
    try:
        client.connect()
    except:
        sys.stdout.write(".")
        continue
    else:
        client.call(obswebsocket.requests.SetFilenameFormatting(file_name_prefix + " - %CCYY-%MM-%DD %hh-%mm-%ss"))
        client.call(obswebsocket.requests.StartRecording())
        client.call(obswebsocket.requests.SetFilenameFormatting("%CCYY-%MM-%DD %hh-%mm-%ss"))
        client.disconnect()
        break

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.