Last active
January 22, 2025 23:08
-
-
Save joshooaj/5a90537a58c1327362bbce6bbb1ca2b5 to your computer and use it in GitHub Desktop.
Convert all video in one or more XProtect database to mkv files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#require -Modules MilestonePSTools, MilestoneSystems.PowerShell.MediaDB | |
param( | |
# Specifies the path to a folder containing one or more XProtect media database folders. | |
[Parameter()] | |
[string] | |
$Source, | |
# Specifies the path to a folder where MKV files will be saved. | |
[Parameter()] | |
[string] | |
$Destination | |
) | |
$Source = (Resolve-Path -Path $Source).Path | |
if (Test-Path -Path $Source -PathType Leaf) { | |
Write-Error "Source path must be a directory." | |
return | |
} | |
$Destination = (Resolve-Path -Path $Destination).Path | |
if (Test-Path -Path $Destination -PathType Leaf) { | |
Write-Error "Destination path must be a directory." | |
return | |
} | |
foreach ($cacheFilePath in [io.directory]::EnumerateFiles($Source, 'cache.xml', [io.searchoption]::AllDirectories)) { | |
try { | |
Open-MediaDatabase -LiteralPath $cacheFilePath | |
# Process each camera found in the cache.xml file | |
foreach ($camera in Get-MdbCamera) { | |
# List all available recording sequences | |
foreach ($sequence in $camera | Get-MdbSequence) { | |
# Split any recording sequence longer than 1 hour into max 1 hour sequences | |
foreach ($newSequence in $sequence | Split-MdbSequence -MaxDuration (New-TimeSpan -Hours 1)) { | |
# Export recording sequence for current camera to it's own MKV file with StartDateTime value in the file name. | |
$outputFile = Join-Path $Destination ('{0}_{1}.mkv' -f $camera.Name, $newSequence.Start.ToString('yyyy-MM-dd_HH-mm-ss')) | |
$camera | Export-MdbMkv -Start $newSequence.Start -End $newSequence.End -Path $outputFile | |
} | |
} | |
} | |
} finally { | |
Close-MediaDatabase | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment