Last active
February 22, 2024 23:12
-
-
Save joshooaj/fce5b11ec4a5526b6d671bc0ad575c2d to your computer and use it in GitHub Desktop.
Watch a live stream of XProtect camera stream properties including resolution, codec, fps, and bitrate.
This file contains 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
function Watch-CameraStream { | |
<# | |
.SYNOPSIS | |
Stream the current video stream properties for the provided camera stream. | |
.DESCRIPTION | |
The `Watch-CameraStream` cmdlet uses MilestonePSTools and the MIP SDK to | |
retrieve the current video stream properties for the provided camera stream | |
from the recording server using the GetVideoDeviceStatistics method of the | |
RecorderStatusService2 API. | |
This command will run until you interrupt it by pressing CTRL+C. | |
The information returned includes ImageResolution, VideoFormat, ImageSizeInBytes, | |
FPSRequested, StreamId, Name, RecordingStream, LiveStream, LiveStreamDefault, | |
LiveStreamRunAlways, BPS, and FPS. | |
.PARAMETER Stream | |
Specifies a camera stream object as returned by Get-VmsCameraStream | |
.PARAMETER RefreshInterval | |
Specifies refresh interval as a [TimeSpan] object. The default is 1-second between updates. | |
.EXAMPLE | |
$camera = Select-Camera -SingleSelect | |
$stream = $camera | Get-VmsCameraStream -LiveDefault | |
$stream | Watch-CameraStream | |
Prompts for a camera selection, then returns the current stream properties for | |
the default live stream to the terminal once per second. | |
.EXAMPLE | |
$camera = Select-Camera -SingleSelect | |
$stream = $camera | Get-VmsCameraStream -RecordingTrack Primary | |
$stream | Watch-CameraStream -RefreshInterval (New-TimeSpan -Seconds 10) | |
Prompts for a camera selection, then returns the current stream properties for | |
the primary recorded stream to the terminal once every 10 seconds. | |
.EXAMPLE | |
$camera = Select-Camera -SingleSelect | |
$stream = $camera | Get-VmsCameraStream -LiveDefault | |
$columns = @( | |
'Name', | |
@{ | |
Name = 'Resolution' | |
Expression = { | |
'{0}x{1}' -f ([int]$_.ImageResolution.Width), ([int]$_.ImageResolution.Height) | |
} | |
}, | |
'VideoFormat', | |
'BPS', | |
'FPS', | |
'ImageSizeInBytes' | |
) | |
$stream | Watch-CameraStream | Select-Object $columns | Format-Table | |
Prompts for a camera selection, then returns the current stream properties for | |
the default live stream the terminal once every 10 seconds as a table with the | |
colums: Name, Resolution, VideoFormat, BPS, FPS, and ImageSizeInBytes. | |
.NOTES | |
This command will run until you interrupt it by pressing CTRL+C. | |
#> | |
[CmdletBinding()] | |
[OutputType([VideoOS.Platform.SDK.Proxy.Status2.VideoStreamStatistics])] | |
param ( | |
[Parameter(Mandatory, Position = 0, ValueFromPipeline)] | |
[object] | |
$Stream, | |
[Parameter()] | |
[timespan] | |
$RefreshInterval = (New-TimeSpan -Seconds 1) | |
) | |
process { | |
try { | |
$item = Get-VmsVideoOSItem -Id $Stream.Camera.Id -Kind Camera | |
$streamId = $Stream.StreamReferenceId | |
$svc = Get-RecorderStatusService2 -Uri $item.FQID.ServerId.Uri | |
while ($true) { | |
$stats = $svc.GetVideoDeviceStatistics((Get-VmsToken), $item.FQID.ObjectId) | |
$streamStats = ($stats | Select-Object -First 1).VideoStreamStatisticsArray | Where-Object StreamId -eq $streamId | |
if ($streamStats) { | |
$streamStats | |
} else { | |
Write-Warning "Video stream ""$($Stream.DisplayName)"" with ID $streamId is not available." | |
} | |
Start-Sleep -Milliseconds $RefreshInterval.TotalMilliseconds | |
} | |
} finally { | |
if ($svc) { | |
$svc.Dispose() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment