Change recording name via websocket

DerSven

New Member
Hello everyone,

I would like to change the storage name of my recording via websocket.
I am using OBS 30.2.3.
I have a python script which connects well to the server and can stop/start recordings and more.
But what I can't do is change the recording name or location.

My script looks like this:

import time
from obswebsocket import obsws, requests

# Connection settings
host = "localhost"
port = 4455
password = ""

# Connect to OBS
ws = obsws(host, port, password)
ws.connect()

prefix = 'Test'
filename_format = f'{prefix}%CCYY-%MM-%DD_%hh-%mm-%ss'
print(filename_format)
recdir = ws.call(requests.GetRecordDirectory())
print(recdir)
ws.call(requests.SetRecordDirectory(RecordDirectory='C:\\VIDEO\\Test'))
recdir = ws.call(requests.GetRecordDirectory())
print(recdir)
profilepar = ws.call(requests.GetProfileParameter(ParameterCategory='Output', parameter_name='FilenameFormatting'))
print(profilepar)
ws.call(requests.SetProfileParameter(ParameterCategory='Output', parameter_name='FilenameFormatting', ParameterValue='1234'))


And this is what I get back:

Test%CCYY-%MM-%DD_%hh-%mm-%ss
<GetRecordDirectory request ({}) called: success ({'recordDirectory': 'C:\\VIDEO'})>
<GetRecordDirectory request ({}) called: success ({'recordDirectory': 'C:\\VIDEO'})>
<GetProfileParameter request ({'ParameterCategory': 'Output', 'parameter_name': 'FilenameFormatting'}) called: failed ({})>


If anyone can help or has an example of how you implemented this, I would be happy to read from you.
 

errornosignal

New Member
This is just a guess, but even though you are passing the set value as a sting in your ws request, I think OBS does some kind of auto-typing to int or long for values that can be interpreted that way. If Output FilenameFormatting will only accept a string, then it'll throw the exception you are seeing. Try passing an alphanumeric string, rather than just one that is strictly numeric and see if it works.
 

Billius44

New Member
I've just spent a day wranging with this, so happy to help!
I believe the old obswebsocket python package DOES do this, but the SDK has changed with Websocket 5.0 which is what is implemented in OBS v28+
I tried with the newer obsws-python package but the SDK for 5.0 doesn't seem to document this well
DoubleF3lix on Github solved this problem, here is the thread:


Here is their code:
connection.get_profile_parameter("Output", "FilenameFormatting").parameter_value
connection.set_profile_parameter("Output", "FilenameFormatting", "My File Name")

And here is my Python script using obsws-python package (instead of obswebsocket)

import obsws_python as obs # python lib to talk to OBS
# set up websocket connection to OBS
cl = obs.ReqClient(host='localhost', port=4455, password='XXXXXX', timeout=3)

# filename is what we pass to OBS to set as the output filename

# THIS is the call to set the output filename
cl.set_profile_parameter("Output","FilenameFormatting",filename)

# and now run code to START OBS recording
cl.start_record()

# and to stop recording
cl.stop_record()
 

errornosignal

New Member
This is just a guess, but even though you are passing the set value as a sting in your ws request, I think OBS does some kind of auto-typing to int or long for values that can be interpreted that way. If Output FilenameFormatting will only accept a string, then it'll throw the exception you are seeing. Try passing an alphanumeric string, rather than just one that is strictly numeric and see if it works.
I got some help in figuring out what was going on and correcting my inaccurate assumption. It wasn't anything in OBS' code that was casting the string I was sending to it to be cast to another type, it was Streamerbot. Sending whatever I wanted as Raw fixed the issue.

https://www.reddit.com/r/streamerbot/s/FSWoDkV6lL
 
Top