Added a windows DVR type thing or something

This commit is contained in:
Brad Ganley 2024-10-21 01:36:06 -05:00
parent 4e7b0ed2cf
commit c2796c9e70
3 changed files with 46 additions and 0 deletions

1
Windows DVR/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.env

26
Windows DVR/WindowsDVR.ps Normal file
View File

@ -0,0 +1,26 @@
# Load the .env file
$envFilePath = ".\env"
if (Test-Path $envFilePath) {
Get-Content $envFilePath | ForEach-Object {
if ($_ -match "^(.*?)=(.*)$") {
$name = $matches[1]
$value = $matches[2]
[System.Environment]::SetEnvironmentVariable($name, $value)
}
}
} else {
Write-Output ".env file not found"
exit
}
# Retrieve variables from environment
$outputPath = [System.Environment]::GetEnvironmentVariable("OUTPUT_PATH")
$rtspUrl = [System.Environment]::GetEnvironmentVariable("RTSP_URL")
$chunkSize = [System.Environment]::GetEnvironmentVariable("CHUNK_SIZE")
$maxAge = [System.Environment]::GetEnvironmentVariable("MAX_AGE")
# FFmpeg arguments for recording in 10-minute segments
$arguments = "-i $rtspUrl -c copy -f segment -segment_time $chunkSize -segment_format mp4 -strftime 1 $outputPath\%Y-%m-%d_%H-%M-%S.mp4"
# Start FFmpeg in the background
Start-Process -FilePath $ffmpegPath -ArgumentList $arguments -WindowStyle Hidden

View File

@ -0,0 +1,19 @@
$envFilePath = ".\env"
if (Test-Path $envFilePath) {
Get-Content $envFilePath | ForEach-Object {
if ($_ -match "^(.*?)=(.*)$") {
$name = $matches[1]
$value = $matches[2]
[System.Environment]::SetEnvironmentVariable($name, $value)
}
}
} else {
Write-Output ".env file not found"
exit
}
$maxAge = [System.Environment]::GetEnvironmentVariable("MAX_AGE")
$outputPath = [System.Environment]::GetEnvironmentVariable("OUTPUT_PATH")
# Get files older than MAX_AGE hours and delete them
Get-ChildItem -Path $outputPath -File | Where-Object { $_.LastWriteTime -lt (Get-Date).AddHours($maxAge) } | Remove-Item