diff --git a/Create-Clip.cmd b/Create-Clip.cmd new file mode 100644 index 0000000..5bf3586 --- /dev/null +++ b/Create-Clip.cmd @@ -0,0 +1,17 @@ +@echo off +for /f "delims=" %%i in ('where Create-Clip.ps1 2^>nul') do set "_script=%%i" & goto :found +echo Error: Create-Clip.ps1 not found in PATH +exit /b 1 +:found +set "_src=%~1" +set "_frames=%~2" +shift +shift +set "_rest=" +:loop +if "%~1"=="" goto done +set "_rest=%_rest% %1" +shift +goto loop +:done +pwsh.exe -NoProfile -ExecutionPolicy Bypass -File "%_script%" -Source "%_src%" -Frames "%_frames%"%_rest% diff --git a/Create-Clip.ps1 b/Create-Clip.ps1 new file mode 100644 index 0000000..167fd49 --- /dev/null +++ b/Create-Clip.ps1 @@ -0,0 +1,63 @@ +<# +.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 diff --git a/Crop-ClipsKling.ps1 b/Crop-ClipsKling.ps1 index fbeac75..e81339e 100644 --- a/Crop-ClipsKling.ps1 +++ b/Crop-ClipsKling.ps1 @@ -108,20 +108,16 @@ foreach ($video in $videos) { } $inRes = "{0}x{1}" -f $inInfo.Width, $inInfo.Height - $inFpsText = if ($inInfo.Fps) { "{0:0.###}" -f $inInfo.Fps } else { 'unknown' } - $inQuality = Format-Quality -BitRate $inInfo.BitRate - $inAudioText = if ($inInfo.HasAudio) { 'yes' } else { 'no' } $is1072 = ($inInfo.Height -eq 1072 -and ($inInfo.Width -eq 1920 -or $inInfo.Width -eq 1928)) $is1916x1080 = ($inInfo.Width -eq 1916 -and $inInfo.Height -eq 1080) + $is1920x1076 = ($inInfo.Width -eq 1920 -and $inInfo.Height -eq 1076) - if (-not $is1072 -and -not $is1916x1080) { + if (-not $is1072 -and -not $is1916x1080 -and -not $is1920x1076) { Write-Host "Skipping: $($inInfo.FileName) (resolution $inRes)" continue } - Write-Host "Input : Filename=$($inInfo.FileName) Resolution=$inRes FPS=$inFpsText Quality=$inQuality Audio=$inAudioText" - if ($BackupRequired) { $backupPath = Join-Path $video.DirectoryName ($video.BaseName + '.bak' + $video.Extension) if ($PSCmdlet.ShouldProcess($backupPath, 'Create backup of original video')) {