aatikturk / obsws-python Goto Github PK
View Code? Open in Web Editor NEWA Python SDK for OBS Studio WebSocket v5.0
License: GNU General Public License v3.0
A Python SDK for OBS Studio WebSocket v5.0
License: GNU General Public License v3.0
Trying to use this module to replace obs-websocket-py
and I'm using Python 3.11.0b5.
I'm trying the sample code provided in the Readme:
import obsstudio_sdk as obs
self.obs = obs.ReqClient(self.server_address, self.server_port, self.server_password)
and I'm getting this error:
AttributeError: module 'obsstudio_sdk' has no attribute 'ReqClient'
Any idea where I'm going wrong?
Is there a part in the code that allows you to change the value of a Text or an image?
Hi,
Does obsws-python support batch requests? There's only one place in the source that batches are mentioned (in the documentation for sleep()), which implies both that batches aren't supported (because they aren't otherwise mentioned), and that they are supported (because sleep() isn't useful outside of batches).
Could you please clarify? Thanks!
Since websockets are pure I/O, there would be significant advantages in providing an async-compliant interface for asynchronous scripts and programs. Has this been considered?
I have a simple script, and step 1 is : import obsws_python as obs
It works great when run as python script.py
But then when I do a pyinstaller --onefile script.py
It keeps missing obsws. When I run the resulting EXE i get:
Traceback (most recent call last):
File "myscript.py", line 7, in <module>
import obsws_python as obs
ModuleNotFoundError: No module named 'obsws_python'
[4408] Failed to execute script 'myscript' due to unhandled exception!
Is there something you can include in the package so that obsws can be included in a pwinstaller? I have tried the usual --include-hidden type options already.
Note: all my other import modules are working fine.
ta
Hi, I have an issue with fetching the responses. This package helps a lot with all of the OBS functionalities, but I am unable to fetch and store the response in a variable.
I can only print the response on screen using debug logging, but there seems to be no way to fetch and store the variable. Am I missing something here?
Hi,
I am assuming I need to use set_output_settings but I don't know how to fill in the field. For example say I wanted the video saved to be called "TestFile.mp4", how would I achieve this?
Thanks!
I am looking to set a scene to full screen on one of my monitors but can't seem to find a way. I tried using the open_source_projector or open video mix, only to get an error that the object has no attribute. Here is the reference to the official websocket protocol:
Is there a way to do this that I am missing?
It's amazing of obs websocket. Your code is simple and useful. Further, I want to use it to synchronize obs with other DAQ system.
I see this code work for me. However, how to register that like 'Event: RecordStatusChanged'.
cl.start_record()
cl.stop_record()
Hello, I've sent you an email through the site if you could let me know your thoughts when you get a spare moment.
Thank you.
Is it possible to set a Timeout for the connection request ? I'm having issues where occasionally the connection just hangs
Hello!
I am trying to run a bit of code to show and then hide a scene item. (example, show video, then hide)
The problem is that it will only work partly. For example if I send:
cl.trigger_hot_key_by_name('libobs.show_scene_item.FLASHBANG')
(my scene name is FLASHBANG, a short video)
it will successfully play, but then when I send:
cl.trigger_hot_key_by_name('libobs.hide_scene_item.FLASHBANG')
nothing happens.
The weirdest part, sometimes this only works the other way around.
I stripped all my code until I got the simplest bit with the error:
`import obsws_python as obs
from time import sleep
cl = obs.ReqClient()
cl.trigger_hot_key_by_name('libobs.show_scene_item.FLASHBANG')
sleep(2)
cl.trigger_hot_key_by_name('libobs.hide_scene_item.FLASHBANG')`
I'll also include my config.toml if that helps (removing my password of course)
[connection] host = "192.168.0.21" port = #### password = "####"
Last thing to mention; I've tried this with multiple scenes (text, image), same issue all around.
I am trying to grab the path of the newly recoreded video file that OBS puts out when stopping a recording. I am currently using cl.stop_record()
and this does not seem to be possible. The StopRecord request returns the outputPath when called. Would it be possible to implement this or find a workaround?
Thanks!
First off, I'm on windows 10, obs 29, and python 3.10, writing a python script. I wasn't getting the config.toml to provide connection details via a parameterless call to ReqClient(), so I stepped through with vscode via a launch.json set to attach to the obs process id and justmycode set to false. So, I load my script in obs with a breakpoint on _conn_from_toml and it turns out Path.cwd() in baseclient.py:40 is returning my obs path, not the script's path. Technically I can handle that by just putting the file in there, but this behavior is contrary to the readme so I thought I should reach out for documentation's sake.
Hello,
I have working script that fails after after few hours of successful run.
This is how I start the connection
cl = obs.ReqClient(host='localhost', port=4455, password='foo', timeout=30)
After a while it stops with a timeout.
websocket._exceptions.WebSocketTimeoutException: Connection timed out
Any suggestions other than restarting?
In Python, I am working on some code that changes text in OBS and then centers the text element.
Here is the relevant code:
# OBS_REQUEST_CLIENT, TEXT_SOURCE_NAME, text_item_id, and text are all assigned before this point
OBS_REQUEST_CLIENT.set_input_settings(TEXT_SOURCE_NAME, {"text": text}, True)
text_item_transform = OBS_REQUEST_CLIENT.get_scene_item_transform("Scene", text_item_id).scene_item_transform
text_item_width = text_item_transform["sourceWidth"]
text_item_height = text_item_transform["sourceHeight"]
OBS_REQUEST_CLIENT.set_scene_item_transform(
"Scene",
text_item_id,
{
"scaleX": 1.0,
"scaleY": 1.0,
"positionX": (SCENE_WIDTH - text_item_width) / 2,
"positionY": (SCENE_HEIGHT - text_item_height) / 2,
}
)
However, having these two calls one after the other often results in stale data for the text item's width and height. I have to put a sleep(0.1)
call after the call to OBS_REQUEST_CLIENT.set_input_settings(...)
to prevent this. This does not seem like expected behavior unless I am mistaken.
def set_scene_item_index(self, scene_name, item_id, item_index):
"""
Sets the index position of a scene item in a scene.
Scenes and Groups
:param scene_name: Name of the scene the item is in
:type scene_name: str
:param item_id: Numeric ID of the scene item (>= 0)
:type item_id: int
:param item_index: New index position of the scene item (>= 0)
:type item_index: int
"""
payload = {
"sceneName": scene_name,
"sceneItemId": item_id,
"sceneItemLocked": item_index, <--- this should be sceneItemIndex
}
self.send("SetSceneItemIndex", payload)
There are no explicit "disconnect methods" in both ReqClient and EventClient. How can I safely close the connection?
Hi!
Thanks for your package! It's been a pleasure to work with it. Things are simple enough yet powerful as the obsws is. I think I might have found something tiny, though. Most prolly the prob is in my end but decided to report this anyway.
I accidentally added timeout to my EventClient call, which seemed to cause weird timeout error regardless if the connection was made or not. I got a timeout error on Python side but the connection showed up in the OBS WS window in OBS. ReqClient works fine with or without timeout.
Not putting anything on the timeout argument fixed the problem.
Whether ReqClient is made or not doesn't have an effect on the outcome.
Here's the versions, code and error message
Happy holidays and/or new year!
Issue originally raised by @jussikiova
I am trying to locate requests.SetFilenameFormatting()
method to set file name of the recording. Can you please help me locate this?
Thank you!
I am sure this is a user error rather than a bug as such, but I am trying to get the file name of a recording, either before start, on start, during recording, on stop or after stop, I dont mind.
Appreciate the tool and help.
import obsstudio_sdk as obs
import time
# load conn info from config.toml
cl = obs.ReqClient()
start = cl.start_record()
#print(start.attrs())
time.sleep(4)
stop = cl.stop_record()
print(stop.attrs())
myfile = cl.get_record_state_changed()
print(myfile.attrs())
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.