Skip to content

Instantly share code, notes, and snippets.

@joshooaj
Created January 13, 2025 20:35
Show Gist options
  • Save joshooaj/a124326c000d208c711c00f314e1c5fa to your computer and use it in GitHub Desktop.
Save joshooaj/a124326c000d208c711c00f314e1c5fa to your computer and use it in GitHub Desktop.
Export recording sequences in parallel
#requires -Modules Microsoft.PowerShell.ThreadJob
<#
This is an example of how you could parallelize exports. You _probably_ wouldn't do this specific thing in practice
but it was an easy proof of concept on a small system.
The following script will get all enabled cameras, and then get all recording sequences for todays date, and then
using the Start-ThreadJob command, it will run each export in a separate job, saving each recording sequence found
on each enabled camera to it's own MKV file in the C:\temp directory.
#>
Get-VmsCamera | Get-SequenceData -StartTime (Get-Date).Date -EndTime (Get-Date) | ForEach-Object {
Start-ThreadJob -ArgumentList $_ -ScriptBlock {
param($sequence)
$ProgressPreference = 'SilentlyContinue'
$exportParams = @{
Format = 'MKV'
Path = 'C:\temp\'
Name = '{0}_{1}.mkv' -f $sequence.EventHeader.Source.FQID.ObjectId, $sequence.EventHeader.Timestamp.Ticks
CameraIds = $sequence.EventHeader.Source.FQID.ObjectId
StartTime = $sequence.EventSequence.StartDateTime
EndTime = $sequence.EventSequence.EndDateTime
}
Start-Export @exportParams
[pscustomobject]@{
Camera = $sequence.EventHeader.Source.Name
Id = $sequence.EventHeader.Source.FQID.ObjectId
StartTime = $sequence.EventSequence.StartDateTime
EndTime = $sequence.EventSequence.EndDateTime
}
}
} | Receive-Job -Wait -AutoRemoveJob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment