Add safe property accessor to Get-VideoInfo function for strict mode compatibility

This commit is contained in:
2026-05-30 12:13:54 -04:00
parent d20189537f
commit 1e78cc67ae
5 changed files with 397 additions and 18 deletions
+9 -6
View File
@@ -40,8 +40,12 @@ function Get-VideoInfo {
$audioStream = $info.streams | Where-Object { $_.codec_type -eq 'audio' } | Select-Object -First 1
# Safe property accessor: returns $null when the property is absent (strict-mode friendly).
$get = { param($obj, $name) if ($obj -and ($obj.PSObject.Properties.Name -contains $name)) { $obj.$name } else { $null } }
$rFrameRate = & $get $videoStream 'r_frame_rate'
$fps = $null
if ($videoStream.r_frame_rate -and $videoStream.r_frame_rate -match '^(\d+)/(\d+)$') {
if ($rFrameRate -and $rFrameRate -match '^(\d+)/(\d+)$') {
$num = [double]$Matches[1]
$den = [double]$Matches[2]
if ($den -ne 0) {
@@ -49,10 +53,9 @@ function Get-VideoInfo {
}
}
$bitRate = $videoStream.bit_rate
if (-not $bitRate) {
$bitRate = $info.format.bit_rate
}
$videoBitRate = & $get $videoStream 'bit_rate'
$formatBitRate = & $get $info.format 'bit_rate'
$bitRate = if ($videoBitRate) { $videoBitRate } else { $formatBitRate }
[pscustomobject]@{
Path = $Path
@@ -62,7 +65,7 @@ function Get-VideoInfo {
Fps = $fps
BitRate = $bitRate
HasAudio = [bool]$audioStream
VideoBitRate = $videoStream.bit_rate
VideoBitRate = $videoBitRate
}
}