Add optional -Target parameter with automatic filename generation based on -Effect value

This commit is contained in:
2026-05-30 14:55:30 -04:00
parent d9c0eb3303
commit 567af452f1
+23 -12
View File
@@ -5,6 +5,8 @@
Path to the input video file. Can be absolute or relative to current directory. .mp4 extension is added if not provided.
.PARAMETER Target
Path to the output video file. Can be absolute or relative to current directory. .mp4 extension is added if not provided.
If omitted, defaults to the source filename with the -Effect value (lowercased) appended after a dash,
saved alongside the source (e.g. video.mp4 + -Effect black -> video-black.mp4).
.PARAMETER Effect
The effect to apply to the side bars. Possible values are:
black: The side bars will be black.
@@ -33,8 +35,8 @@ param(
[Parameter(Mandatory = $true)]
[string]$Source,
[Parameter(Mandatory = $true)]
[string]$Target,
[Parameter(Mandatory = $false)]
[string]$Target = $null,
[Parameter(Mandatory = $true)]
[string]$Effect,
@@ -183,13 +185,17 @@ function Resolve-Size {
return [pscustomobject]@{ Width = $w; Height = $h }
}
# Append .mp4 extension if missing
# Validate -Effect first so it can be used in the default -Target name.
$validEffects = @('black', 'white', 'standard', 'dark', 'gaussian')
$effectLower = $Effect.ToLower()
if ($effectLower -notin $validEffects) {
throw "Invalid -Effect value: $Effect. Must be one of: $($validEffects -join ', ')"
}
# Append .mp4 extension if missing on -Source
if (-not [System.IO.Path]::GetExtension($Source)) {
$Source = "$Source.mp4"
}
if (-not [System.IO.Path]::GetExtension($Target)) {
$Target = "$Target.mp4"
}
if (-not (Test-Path -LiteralPath $Source)) {
throw "Source video not found: $Source"
@@ -197,6 +203,17 @@ if (-not (Test-Path -LiteralPath $Source)) {
$sourceFull = (Resolve-Path -LiteralPath $Source).Path
# Default -Target: same directory and base name as -Source, with the effect appended
# (e.g. C:\clips\video.mp4 + -Effect Black -> C:\clips\video-black.mp4).
if ([string]::IsNullOrWhiteSpace($Target)) {
$srcDir = [System.IO.Path]::GetDirectoryName($sourceFull)
$srcBase = [System.IO.Path]::GetFileNameWithoutExtension($sourceFull)
$Target = Join-Path $srcDir "$srcBase-$effectLower.mp4"
}
elseif (-not [System.IO.Path]::GetExtension($Target)) {
$Target = "$Target.mp4"
}
# Resolve Target to an absolute path (may not exist yet)
if ([System.IO.Path]::IsPathRooted($Target)) {
$targetFull = $Target
@@ -219,12 +236,6 @@ if ($CRF -ne -1 -and ($CRF -lt 0 -or $CRF -gt 51)) {
throw "Invalid -CRF value: $CRF. Must be in range 0-51."
}
$validEffects = @('black', 'white', 'standard', 'dark', 'gaussian')
$effectLower = $Effect.ToLower()
if ($effectLower -notin $validEffects) {
throw "Invalid -Effect value: $Effect. Must be one of: $($validEffects -join ', ')"
}
$inInfo = Get-VideoInfo -Path $sourceFull
$inRes = "{0}x{1}" -f $inInfo.Width, $inInfo.Height