Add WebM/MKV support with automatic transcoding to H.264/AAC for MP4 compatibility
This commit is contained in:
+20
-12
@@ -158,24 +158,28 @@ function Resolve-Size {
|
||||
throw "Invalid -Size value: $Value. Use a named preset (480p, 720p, 1080p, HD, 1440p, 2K, 2160p, 4K) or 'width:height'."
|
||||
}
|
||||
|
||||
# Compute the minimum 16:9 frame that fully contains the source
|
||||
$minWidthFromHeight = [int][math]::Ceiling($SourceHeight * 16.0 / 9.0)
|
||||
$minHeightFromWidth = [int][math]::Ceiling($SourceWidth * 9.0 / 16.0)
|
||||
# Pick the smallest standard 16:9 preset whose longer side (width) is at least
|
||||
# the source's longer side. The foreground is scaled down with
|
||||
# 'force_original_aspect_ratio=decrease', so the source is allowed to shrink
|
||||
# to fit; we only need the preset to be "big enough" relative to the source's
|
||||
# largest dimension. This produces the documented behavior:
|
||||
# 1080x1920 portrait -> 1920x1080 (vertical bars on either side)
|
||||
# 720x1280 portrait -> 1280x720
|
||||
# 2560x1080 landscape -> 2560x1440 (horizontal bars top/bottom)
|
||||
$longSide = [math]::Max($SourceWidth, $SourceHeight)
|
||||
|
||||
$neededWidth = [math]::Max($SourceWidth, $minWidthFromHeight)
|
||||
$neededHeight = [math]::Max($SourceHeight, $minHeightFromWidth)
|
||||
|
||||
# Pick the smallest standard 16:9 size that contains the source
|
||||
$unique = $standards | Sort-Object { $_.Width } -Unique
|
||||
foreach ($s in $unique) {
|
||||
if ($s.Width -ge $neededWidth -and $s.Height -ge $neededHeight) {
|
||||
if ($s.Width -ge $longSide) {
|
||||
return [pscustomobject]@{ Width = $s.Width; Height = $s.Height }
|
||||
}
|
||||
}
|
||||
|
||||
# Source larger than any standard preset: use exact computed dimensions (rounded to even)
|
||||
$w = $neededWidth + ($neededWidth % 2)
|
||||
$h = $neededHeight + ($neededHeight % 2)
|
||||
# Source larger than any standard preset: build a 16:9 frame whose width
|
||||
# matches the source's longer side (rounded to even).
|
||||
$w = $longSide + ($longSide % 2)
|
||||
$h = [int][math]::Ceiling($w * 9.0 / 16.0)
|
||||
if ($h % 2) { $h++ }
|
||||
return [pscustomobject]@{ Width = $w; Height = $h }
|
||||
}
|
||||
|
||||
@@ -349,7 +353,11 @@ if ($PSCmdlet.ShouldProcess($targetFull, 'Create pillar-boxed video with ffmpeg'
|
||||
Remove-Item -LiteralPath $targetFull -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
$ffmpegOutput | ForEach-Object { Write-Error $_ }
|
||||
# Use Write-Host (not Write-Error) so the full ffmpeg output is shown;
|
||||
# under $ErrorActionPreference = 'Stop' a piped Write-Error would terminate
|
||||
# on the first line, swallowing the rest of the diagnostic output and the
|
||||
# final 'throw' below.
|
||||
$ffmpegOutput | ForEach-Object { Write-Host $_ }
|
||||
Write-Host "ffmpeg $($ffArgs -join ' ')"
|
||||
throw "ffmpeg failed while creating pillar-boxed video: $($inInfo.FileName)"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user