Add optional -Target parameter with automatic filename generation based on -Effect value
This commit is contained in:
+23
-12
@@ -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.
|
Path to the input video file. Can be absolute or relative to current directory. .mp4 extension is added if not provided.
|
||||||
.PARAMETER Target
|
.PARAMETER Target
|
||||||
Path to the output video file. Can be absolute or relative to current directory. .mp4 extension is added if not provided.
|
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
|
.PARAMETER Effect
|
||||||
The effect to apply to the side bars. Possible values are:
|
The effect to apply to the side bars. Possible values are:
|
||||||
black: The side bars will be black.
|
black: The side bars will be black.
|
||||||
@@ -33,8 +35,8 @@ param(
|
|||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[string]$Source,
|
[string]$Source,
|
||||||
|
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $false)]
|
||||||
[string]$Target,
|
[string]$Target = $null,
|
||||||
|
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[string]$Effect,
|
[string]$Effect,
|
||||||
@@ -183,13 +185,17 @@ function Resolve-Size {
|
|||||||
return [pscustomobject]@{ Width = $w; Height = $h }
|
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)) {
|
if (-not [System.IO.Path]::GetExtension($Source)) {
|
||||||
$Source = "$Source.mp4"
|
$Source = "$Source.mp4"
|
||||||
}
|
}
|
||||||
if (-not [System.IO.Path]::GetExtension($Target)) {
|
|
||||||
$Target = "$Target.mp4"
|
|
||||||
}
|
|
||||||
|
|
||||||
if (-not (Test-Path -LiteralPath $Source)) {
|
if (-not (Test-Path -LiteralPath $Source)) {
|
||||||
throw "Source video not found: $Source"
|
throw "Source video not found: $Source"
|
||||||
@@ -197,6 +203,17 @@ if (-not (Test-Path -LiteralPath $Source)) {
|
|||||||
|
|
||||||
$sourceFull = (Resolve-Path -LiteralPath $Source).Path
|
$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)
|
# Resolve Target to an absolute path (may not exist yet)
|
||||||
if ([System.IO.Path]::IsPathRooted($Target)) {
|
if ([System.IO.Path]::IsPathRooted($Target)) {
|
||||||
$targetFull = $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."
|
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
|
$inInfo = Get-VideoInfo -Path $sourceFull
|
||||||
|
|
||||||
$inRes = "{0}x{1}" -f $inInfo.Width, $inInfo.Height
|
$inRes = "{0}x{1}" -f $inInfo.Width, $inInfo.Height
|
||||||
|
|||||||
Reference in New Issue
Block a user