Had to change a bunch to get everything to work but it should be working now

This commit is contained in:
2026-03-27 17:03:09 -07:00
parent 2bf42e7e7f
commit d107f85d6f
7 changed files with 104 additions and 30 deletions

View File

@@ -29,7 +29,7 @@ Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Starting OBS Replay
# --- Verify required project files are accessible ---
$requiredPaths = @(
(Join-Path $PSScriptRoot '..\obs-config\global.ini')
(Join-Path $PSScriptRoot '..\obs-config\plugin_config\obs-websocket\config.json')
(Join-Path $PSScriptRoot "..\obs-config\scenes\$($config.SceneCollection).json")
(Join-Path $PSScriptRoot 'Show-ReplayTray.ps1')
$config.OBSExecutable
)
@@ -72,9 +72,54 @@ $sourceConfig = Join-Path $PSScriptRoot '..\obs-config'
New-Item -ItemType Directory -Path $obsConfigRoot -Force | Out-Null
Copy-Item -Path "$sourceConfig\global.ini" -Destination "$obsConfigRoot\global.ini" -Force
$wsConfigDir = "$obsConfigRoot\plugin_config\obs-websocket"
New-Item -ItemType Directory -Path $wsConfigDir -Force | Out-Null
Copy-Item -Path "$sourceConfig\plugin_config\obs-websocket\config.json" -Destination "$wsConfigDir\config.json" -Force
# --- Detect primary monitor device ID for OBS monitor capture ---
# Uses EnumDisplayDevices with EDD_GET_DEVICE_INTERFACE_NAME to get the exact
# device interface path for the active session's display — same source OBS uses.
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class DisplayHelper {
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DISPLAY_DEVICE {
public int cb;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string DeviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string DeviceString;
public int StateFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string DeviceID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string DeviceKey;
}
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern bool EnumDisplayDevices(string lpDevice, uint iDevNum, ref DISPLAY_DEVICE lpDisplayDevice, uint dwFlags);
public static string GetPrimaryMonitorInterfacePath() {
var adapter = new DISPLAY_DEVICE(); adapter.cb = Marshal.SizeOf(adapter);
for (uint i = 0; EnumDisplayDevices(null, i, ref adapter, 0); i++) {
if ((adapter.StateFlags & 0x4) != 0) { // DISPLAY_DEVICE_PRIMARY_DEVICE
var monitor = new DISPLAY_DEVICE(); monitor.cb = Marshal.SizeOf(monitor);
if (EnumDisplayDevices(adapter.DeviceName, 0, ref monitor, 0x1)) // EDD_GET_DEVICE_INTERFACE_NAME
return monitor.DeviceID;
}
}
return "";
}
}
"@
$monitorDeviceId = [DisplayHelper]::GetPrimaryMonitorInterfacePath()
if ($monitorDeviceId) {
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Detected monitor ID: $monitorDeviceId"
} else {
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [WARN] No monitor detected - monitor_id will be empty."
}
# --- Deploy scene collection with dynamic monitor ID ---
$scenesDir = "$obsConfigRoot\basic\scenes"
New-Item -ItemType Directory -Path $scenesDir -Force | Out-Null
$sceneJson = Get-Content -Path "$sourceConfig\scenes\$($config.SceneCollection).json" -Raw | ConvertFrom-Json
$sceneJson.sources | Where-Object { $_.id -eq 'monitor_capture' } | ForEach-Object {
$_.settings | Add-Member -MemberType NoteProperty -Name 'monitor_id' -Value $monitorDeviceId -Force
}
$sceneJson | ConvertTo-Json -Depth 20 | Set-Content -Path "$scenesDir\$($config.SceneCollection).json" -Encoding UTF8
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] OBS config files deployed to: $obsConfigRoot"
@@ -82,6 +127,9 @@ Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] OBS config files de
$profileDir = "$env:APPDATA\obs-studio\basic\profiles\$($config.ProfileName)"
New-Item -ItemType Directory -Path $profileDir -Force | Out-Null
# OBS strips one leading backslash from paths — prepend an extra one for UNC paths
$obsFilePath = if ($userCapturePath.StartsWith('\\')) { '\' + $userCapturePath } else { $userCapturePath }
Set-Content -Path "$profileDir\basic.ini" -Encoding UTF8 -Value @(
'[General]'
"Name=$($config.ProfileName)"
@@ -91,11 +139,20 @@ Set-Content -Path "$profileDir\basic.ini" -Encoding UTF8 -Value @(
'FilenameFormatting=%CCYY-%MM-%DD_%hh-%mm-%ss'
''
'[SimpleOutput]'
"FilePath=$userCapturePath"
"FilePath=$obsFilePath"
'RecFormat2=mkv'
'RecQuality=HQ'
'RecQuality=Small'
'RecEncoder=x264'
'RecRB=true'
'RecRBPrefix=Replay'
"RecRBTime=$($config.BufferSeconds)"
'RecRBSize=512'
'ABitrate=160'
'VBitrate=2500'
'UseAdvanced=false'
'Preset=veryfast'
'StreamAudioEncoder=aac'
'RecAudioEncoder=aac'
''
'[Video]'
"BaseCX=$width"