How to Customize obs Studio

gcm.hyd

New Member
obs studio is connected programetically but i need to disply same video in my view page below is my code.
public IActionResult Index()

{
string serverAddress = "ws://localhost:4455";
string password = "ZjiOb5ZNs6C9LN06"; // replace with your actual OBS WebSocket server password

try
{
OBSWebsocket obs = new OBSWebsocket();
obs.ConnectAsync(serverAddress, password);
Thread.Sleep(5000); // Wait for connection to establish

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 sourceSettings = new JObject
{

{ "device", "Integrated Camera" },
//{ "fps", 30 },
//{ "width", 1280 },
//{ "height", 720 },
{ "deactivate_when_not_showing", false }, // Keep the device active
{ "use_preset", true } // Use default preset
};

// Try a different input kind
string inputName = "Video Capture Device";
string inputKind = "dshow_input";
if (inputName != null)
{
obs.CreateInput(sceneName, inputName, inputKind, sourceSettings, true);

}

// Apply settings again if necessary
obs.SetInputSettings(inputName, sourceSettings);


obs.OpenInputPropertiesDialog(inputName);
Thread.Sleep(2000);

// Start recordings

KeyboardHelper.PressEnterKey("Properties for 'Video Capture Device'"); // Use the exact title of the window
var streamSettings = new OBSStreamSettings
{
Server = "rtmp://your_rtmp_server/live",
Key = "stream_key",
UseAuth = false
};

// Apply the streaming settings
/obs.SetStreamServiceSettings("rtmp_custom", streamSettings);
//string rtmpUrl = "rtmp://Gcm_rtmp_server_address/stream_key";
//obs.("rtmp_common", new JObject
//{
// { "server", rtmpUrl },
// { "key", "stream_key" }
//}, true);
// obs.StartRecord();
// StartRecording();
//Thread.Sleep(10000);
//obs.StopRecord();

// Disconnect when done
//obs.Disconnect();
}
else
{
Console.WriteLine("Failed to connect to OBS WebSocket server.");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error connecting to OBS WebSocket server: {ex.Message}");
}


return View();
}


public IActionResult StartRecording()
{
// Start OBS recording
//OBSWebsocket obs = new OBSWebsocket();
obs.ConnectAsync(serverAddress, password);
Thread.Sleep(5000); // Wait for connection to establish

if (obs.IsConnected)
{
obs.StartRecord();
}
return Ok();
}

public IActionResult StopRecording()
{
// Stop OBS recording
//OBSWebsocket obs = new OBSWebsocket();
obs.ConnectAsync(serverAddress, password);
Thread.Sleep(5000);
if (obs.IsConnected)
{
obs.StopRecord();
}
return Ok();
}
 
Top