From c2796c9e7083ed0533f980f23f7a9eddd5f02377 Mon Sep 17 00:00:00 2001 From: Brad Ganley Date: Mon, 21 Oct 2024 01:36:06 -0500 Subject: [PATCH] Added a windows DVR type thing or something --- Windows DVR/.gitignore | 1 + Windows DVR/WindowsDVR.ps | 26 ++++++++++++++++++++++++++ Windows DVR/WindowsDVRCleanup.ps | 19 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 Windows DVR/.gitignore create mode 100644 Windows DVR/WindowsDVR.ps create mode 100644 Windows DVR/WindowsDVRCleanup.ps diff --git a/Windows DVR/.gitignore b/Windows DVR/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/Windows DVR/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/Windows DVR/WindowsDVR.ps b/Windows DVR/WindowsDVR.ps new file mode 100644 index 0000000..6b3beda --- /dev/null +++ b/Windows DVR/WindowsDVR.ps @@ -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 \ No newline at end of file diff --git a/Windows DVR/WindowsDVRCleanup.ps b/Windows DVR/WindowsDVRCleanup.ps new file mode 100644 index 0000000..a9e852a --- /dev/null +++ b/Windows DVR/WindowsDVRCleanup.ps @@ -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 \ No newline at end of file