I'm working on automating some tasks in OBS Studio using the obs-websocket.net library. I've been able to connect to the OBS WebSocket server and perform some basic operations, but I’m running into issues with configuring settings and creating inputs.
Here’s what I have so far:
csharp
string serveraddress = "ws://localhost:4455";
string password = "ZjiOb5ZNs6C9LN06";
OBSWebsocket obs = new OBSWebsocket();
obs.ConnectAsync(serveraddress, password);
Thread.Sleep(10000);
if (obs.IsConnected)
{
Console.WriteLine("Connected to OBS WebSocket server.");
// Get the list of scenes
List<SceneBasicInfo> scenes = obs.ListScenes();
// Check if the scene already exists
string sceneName = "NewScene";
bool sceneExists = scenes.Exists(scene => scene.Name == sceneName);
if (!sceneExists)
{
obs.CreateScene(sceneName);
}
// Set the created scene as the current scene
obs.SetCurrentProgramScene(sceneName);
var defaultSettings = obs.GetInputDefaultSettings("dshow_input");
// Modify settings to use device default settings
var sourceSettings = new JObject(defaultSettings);
sourceSettings["resolution_fps_type"] = "Device Default";
sourceSettings["device_id"] = "\\\\?\\usb#vid_04f2&pid_b2ea&mi_00#7&6fe2ea7&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global";
sourceSettings["resolution"] = "640x480";
sourceSettings["fps"] = 30.00;
sourceSettings["format"] = "YUY2";
sourceSettings["flip"] = 0;
sourceSettings["buffering"] = false;
sourceSettings["hw_decode"] = false;
sourceSettings["video_device_id"] = "Integrated Camera";
sourceSettings["video_format"] = "Any";
sourceSettings["fps"] = 30;
obs.CreateInput(sceneName, "video", "dshow_input", sourceSettings, true);
// Start recording
obs.StartRecord();
Thanks in advance!
}
Here’s what I have so far:
csharp
string serveraddress = "ws://localhost:4455";
string password = "ZjiOb5ZNs6C9LN06";
OBSWebsocket obs = new OBSWebsocket();
obs.ConnectAsync(serveraddress, password);
Thread.Sleep(10000);
if (obs.IsConnected)
{
Console.WriteLine("Connected to OBS WebSocket server.");
// Get the list of scenes
List<SceneBasicInfo> scenes = obs.ListScenes();
// Check if the scene already exists
string sceneName = "NewScene";
bool sceneExists = scenes.Exists(scene => scene.Name == sceneName);
if (!sceneExists)
{
obs.CreateScene(sceneName);
}
// Set the created scene as the current scene
obs.SetCurrentProgramScene(sceneName);
var defaultSettings = obs.GetInputDefaultSettings("dshow_input");
// Modify settings to use device default settings
var sourceSettings = new JObject(defaultSettings);
sourceSettings["resolution_fps_type"] = "Device Default";
sourceSettings["device_id"] = "\\\\?\\usb#vid_04f2&pid_b2ea&mi_00#7&6fe2ea7&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global";
sourceSettings["resolution"] = "640x480";
sourceSettings["fps"] = 30.00;
sourceSettings["format"] = "YUY2";
sourceSettings["flip"] = 0;
sourceSettings["buffering"] = false;
sourceSettings["hw_decode"] = false;
sourceSettings["video_device_id"] = "Integrated Camera";
sourceSettings["video_format"] = "Any";
sourceSettings["fps"] = 30;
obs.CreateInput(sceneName, "video", "dshow_input", sourceSettings, true);
// Start recording
obs.StartRecord();
Issues:
- Creating Inputs: I’m not sure if the sourceSettings JSON object is correctly configured. The video_device_id and video_format fields might need to be adjusted, but I’m not sure what the correct values should be.
- Setting Properties: When calling obs.CreateInput(), I’m unsure if the properties I’ve set in sourceSettings will work as expected. How can I verify if the settings are correctly applied?
- Error Handling: I would like to add better error handling and logging to understand if and where my code might be failing.
Questions:
- Can anyone help me with the correct format for sourceSettings when creating a video input?
- How can I verify that the settings are applied correctly?
- What are some best practices for error handling and debugging when using obs-websocket.net?
Thanks in advance!
}