-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGhostCam.ps1
More file actions
111 lines (90 loc) · 3.7 KB
/
GhostCam.ps1
File metadata and controls
111 lines (90 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# GhostCam Management Script for Windows
# Usage: .\GhostCam.ps1 [start|stop|install-driver|setup]
param (
[Parameter(Mandatory=$false, Position=0)]
[ValidateSet("start", "stop", "setup", "install-driver")]
[string]$Action = "start",
[string]$InputDevice = "video=Integrated Camera",
[int]$Width = 1280,
[int]$Height = 720,
[string]$BackgroundMode = "image",
[string]$BackgroundColor = "#222222",
[int]$BlurStrength = 21,
[string]$BackgroundImage = ""
)
$PSScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Definition
$VenvPath = Join-Path $PSScriptRoot ".venv"
$PythonExe = Join-Path $VenvPath "Scripts\python.exe"
if (-not $BackgroundImage) {
$BackgroundImage = Join-Path $PSScriptRoot "tests\test_background.webp"
}
function Show-Banner {
Write-Host "👻 GhostCam (Headless-VCam) Control" -ForegroundColor Cyan
Write-Host "------------------------------------"
}
function Setup-Environment {
Write-Host "[*] Setting up Python Virtual Environment..." -ForegroundColor Yellow
if (-not (Test-Path $VenvPath)) {
python -m venv .venv
}
Write-Host "[*] Installing dependencies..." -ForegroundColor Yellow
& $PythonExe -m pip install --upgrade pip
& $PythonExe -m pip install -r (Join-Path $PSScriptRoot "requirements.txt")
Write-Host "[+] Environment ready." -ForegroundColor Green
}
function Install-Driver {
Write-Host "[*] Installing UnityCapture Driver..." -ForegroundColor Yellow
$DriverPath = Join-Path $PSScriptRoot "drivers\UnityCapture\Install\Install.bat"
if (Test-Path $DriverPath) {
Start-Process "cmd.exe" -ArgumentList "/c `"$DriverPath`"" -Verb RunAs -Wait
Write-Host "[+] Driver installation triggered (Check the pop-up window)." -ForegroundColor Green
} else {
Write-Host "[!] Driver path not found: $DriverPath" -ForegroundColor Red
}
}
function Start-GhostCam {
if (-not (Test-Path $PythonExe)) {
Setup-Environment
}
$ArgsList = @(
(Join-Path $PSScriptRoot "src\ghostcam\main.py"),
"--input", $InputDevice,
"--width", $Width,
"--height", $Height,
"--background-mode", $BackgroundMode,
"--background-color", $BackgroundColor,
"--blur-strength", $BlurStrength
)
if ($BackgroundImage -and (Test-Path $BackgroundImage)) {
$ArgsList += "--background-image"
$ArgsList += $BackgroundImage
}
Write-Host "[>] Starting GhostCam Service..." -ForegroundColor Green
Write-Host "[i] Device: $InputDevice"
Write-Host "[i] Resolution: ${Width}x${Height}"
Write-Host "[i] Background Mode: $BackgroundMode"
Write-Host "------------------------------------"
Write-Host "Press Ctrl+C to stop the service."
& $PythonExe @ArgsList
}
function Stop-GhostCam {
Write-Host "[*] Stopping GhostCam service and restoring the default camera..." -ForegroundColor Yellow
if (Get-Command pm2 -ErrorAction SilentlyContinue) {
pm2 stop ghostcam | Out-Null
pm2 delete ghostcam | Out-Null
}
Get-Process ghostcam -ErrorAction SilentlyContinue | Stop-Process -Force
Get-CimInstance Win32_Process -Filter "Name = 'python.exe'" -ErrorAction SilentlyContinue |
Where-Object { $_.CommandLine -like "*ghostcam*" } |
ForEach-Object { Stop-Process -Id $_.ProcessId -Force }
Get-Process WindowsCamera, ApplicationFrameHost -ErrorAction SilentlyContinue | Stop-Process -Force
Write-Host "[+] GhostCam stopped. Camera apps can now reacquire Integrated Camera." -ForegroundColor Green
}
# Main Execution
Show-Banner
switch ($Action) {
"setup" { Setup-Environment }
"install-driver" { Install-Driver }
"start" { Start-GhostCam }
"stop" { Stop-GhostCam }
}