<# .SYNOPSIS Creates a new clipped video file using Clone-Video.ps1, requiring the -Source and -Frames parameters from that script. The filename used for the -Target parameter is automatically derived from the -Source filename, with "-Clip" inserted before the video file extension (e.g., P01.mp4 becomes P01-Clip.mp4). Any extra parameters will be pass directly to Clone-Video.ps1, except for parameters -Source, -Frames and -Target. .PARAMETER Source Path to the input video file. Can be absolute or relative to current directory. If the path has no extension, .mp4, .webm and .mkv are tried in turn. .PARAMETER Frames 0-based frames index to extract. Supports the following formats: - start-end: Extract frames from start to end (e.g., "100-200") - positive_number: Extract frames from 0 to that number (e.g., "50") - -negative_number: Extract last N frames (e.g., "-10") - %: Represents the last frame index. Can be used alone or in ranges (e.g., "%", "10-%", "-%") - all: Extract all frames (same as "0-%") #> [CmdletBinding(SupportsShouldProcess)] param( [Parameter(Mandatory = $true)] [string]$Source, [Parameter(Mandatory = $true)] [string]$Frames, [Parameter(ValueFromRemainingArguments)] [object[]]$ExtraArgs ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' $sourcePath = $Source # Resolve source path: accept .mp4, .webm or .mkv. If the path doesn't exist as-is, # try appending each supported extension in turn (same logic as Clone-Video.ps1). $supportedSourceExts = @('.mp4', '.webm', '.mkv') if (-not (Test-Path -LiteralPath $sourcePath)) { foreach ($ext in $supportedSourceExts) { $candidate = "$sourcePath$ext" if (Test-Path -LiteralPath $candidate) { $sourcePath = $candidate break } } } # Derive the -Target path: insert "-Clip" before the file extension (e.g., P01.mp4 -> P01-Clip.mp4) $sourceExt = [System.IO.Path]::GetExtension($sourcePath) $sourceBase = [System.IO.Path]::GetFileNameWithoutExtension($sourcePath) $sourceDir = [System.IO.Path]::GetDirectoryName($sourcePath) $targetName = "$sourceBase-Clip$sourceExt" $targetPath = if ([string]::IsNullOrEmpty($sourceDir)) { $targetName } else { Join-Path $sourceDir $targetName } $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $cloneVideoScript = Join-Path $scriptDir 'Clone-Video.ps1' # Forward extra args plus common parameters to Clone-Video.ps1 $passThrough = @() if ($ExtraArgs) { $passThrough += $ExtraArgs } if ($PSBoundParameters.ContainsKey('WhatIf')) { $passThrough += '-WhatIf' } if ($PSBoundParameters.ContainsKey('Confirm')) { $passThrough += '-Confirm' } & $cloneVideoScript -Source $sourcePath -Frames $Frames -Target $targetPath @passThrough exit $LASTEXITCODE