Add -LTX parameter to select closest LTX-2 canonical resolution for specified aspect ratio when using -Size with HD/1080p/720p/480p presets
This commit is contained in:
+78
-2
@@ -41,6 +41,14 @@
|
||||
Honours all other parameters (StartFrame/EndFrame range, Size, FPS, CRF, container choice, etc.).
|
||||
Audio is NOT reversed; it is processed exactly as it would be without -Reverse (trimmed/replaced/copied as applicable) and plays forward alongside the reversed video.
|
||||
Forces a video re-encode, since the reverse filter cannot be applied to a stream-copied video.
|
||||
.PARAMETER LTX
|
||||
When present, overrides the dimensions selected by -Size with the closest LTX-2 (Wan2GP by DeepBeepMeep)
|
||||
canonical resolution for the source's aspect ratio. Only valid when -Size is one of HD, 1080p, 720p or 480p.
|
||||
The closest aspect ratio is picked from the following buckets:
|
||||
- HD / 1080p: 1920x1088 (16:9), 1088x1920 (9:16), 1664x960 (21:9), 960x1664 (9:21)
|
||||
- 720p: 1280x704 (16:9), 704x1280 (9:16), 1088x576 (21:9), 576x1088 (9:21)
|
||||
- 480p: 832x448 (16:9), 448x832 (9:16), 896x512 (4:3), 512x896 (3:4)
|
||||
Forces a video re-encode (same as -Size).
|
||||
.DESCRIPTION
|
||||
This script uses ffmpeg to clone (copy) a video file with optional frame range and audio exclusion.
|
||||
When Sequence is provided, it extracts a specific frame to PNG and then clones the video accordingly.
|
||||
@@ -82,7 +90,10 @@ param(
|
||||
[switch]$Metadata,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[switch]$Reverse
|
||||
[switch]$Reverse,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[switch]$LTX
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
@@ -261,6 +272,67 @@ if (-not $totalFrames -or $totalFrames -notmatch '^\d+$') {
|
||||
$totalFramesInt = [int]$totalFrames
|
||||
$maxFrameIndex = $totalFramesInt - 1
|
||||
|
||||
# Probe source video dimensions (used by -LTX to pick the closest aspect-ratio bucket).
|
||||
$ffprobeDimOutput = & ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0:s=x -- $SourcePath 2>&1
|
||||
$sourceWidth = 0
|
||||
$sourceHeight = 0
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
$dimLine = $ffprobeDimOutput | Select-Object -First 1
|
||||
if ($dimLine) {
|
||||
$dimText = ([string]$dimLine).Trim()
|
||||
if ($dimText -match '^(\d+)x(\d+)$') {
|
||||
$sourceWidth = [int]$Matches[1]
|
||||
$sourceHeight = [int]$Matches[2]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($LTX) {
|
||||
$ltxKey = $Size
|
||||
if ($ltxKey -eq 'HD') { $ltxKey = '1080p' }
|
||||
$ltxMap = @{
|
||||
'1080p' = @(
|
||||
@{ W = 1920; H = 1088 },
|
||||
@{ W = 1088; H = 1920 },
|
||||
@{ W = 1664; H = 960 },
|
||||
@{ W = 960; H = 1664 }
|
||||
)
|
||||
'720p' = @(
|
||||
@{ W = 1280; H = 704 },
|
||||
@{ W = 704; H = 1280 },
|
||||
@{ W = 1088; H = 576 },
|
||||
@{ W = 576; H = 1088 }
|
||||
)
|
||||
'480p' = @(
|
||||
@{ W = 832; H = 448 },
|
||||
@{ W = 448; H = 832 },
|
||||
@{ W = 896; H = 512 },
|
||||
@{ W = 512; H = 896 }
|
||||
)
|
||||
}
|
||||
if (-not $ltxMap.ContainsKey($ltxKey)) {
|
||||
Write-Error '-LTX requires -Size to be one of: 480p, 720p, 1080p, HD'
|
||||
exit 1
|
||||
}
|
||||
if ($sourceWidth -le 0 -or $sourceHeight -le 0) {
|
||||
Write-Error 'Could not determine source video dimensions; -LTX cannot pick an aspect-ratio bucket.'
|
||||
exit 1
|
||||
}
|
||||
$srcRatio = [double]$sourceWidth / [double]$sourceHeight
|
||||
$best = $null
|
||||
$bestDiff = [double]::MaxValue
|
||||
foreach ($entry in $ltxMap[$ltxKey]) {
|
||||
$r = [double]$entry.W / [double]$entry.H
|
||||
$d = [Math]::Abs($r - $srcRatio)
|
||||
if ($d -lt $bestDiff) {
|
||||
$bestDiff = $d
|
||||
$best = $entry
|
||||
}
|
||||
}
|
||||
$scaleWidth = $best.W
|
||||
$scaleHeight = $best.H
|
||||
}
|
||||
|
||||
$ffprobeBitrateOutput = & ffprobe -v error -select_streams v:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 -- $SourcePath 2>&1
|
||||
$ffprobeExit = $LASTEXITCODE
|
||||
|
||||
@@ -384,7 +456,11 @@ if ($AudioPath -and $externalAudioCodec) {
|
||||
}
|
||||
Write-Host (' Frame range: {0} to {1} ({2} frames)' -f $StartFrame, $actualEndFrame, $frameCount)
|
||||
if ($scaleWidth -gt 0) {
|
||||
Write-Host (' Size: {0}x{1}' -f $scaleWidth, $scaleHeight)
|
||||
if ($LTX) {
|
||||
Write-Host (' Size: {0}x{1} (LTX-2)' -f $scaleWidth, $scaleHeight)
|
||||
} else {
|
||||
Write-Host (' Size: {0}x{1}' -f $scaleWidth, $scaleHeight)
|
||||
}
|
||||
}
|
||||
if ($FPS -gt 0) {
|
||||
Write-Host (' FPS: {0}' -f $FPS)
|
||||
|
||||
Reference in New Issue
Block a user