Add safe property accessor to Get-VideoInfo function for strict mode compatibility
This commit is contained in:
+9
-6
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user