50 lines
1.9 KiB
PowerShell
50 lines
1.9 KiB
PowerShell
|
param (
|
||
|
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] $files,
|
||
|
[Parameter(Mandatory = $false)] [string] $destination,
|
||
|
[Parameter(Mandatory = $false)] [int] $quality = 22,
|
||
|
[Parameter(Mandatory = $false)] [string] $preset = "fast",
|
||
|
[switch] $force
|
||
|
)
|
||
|
|
||
|
$forceArgument = ""
|
||
|
if ($force.IsPresent) {
|
||
|
Write-Host "Setting force argument."
|
||
|
$forceArgument = "-y"
|
||
|
}
|
||
|
|
||
|
$nice = "/usr/bin/nice"
|
||
|
$ffmpeg = "/usr/bin/ffmpeg"
|
||
|
|
||
|
if ($destination -eq $null) {
|
||
|
$destination = Get-Location
|
||
|
}
|
||
|
|
||
|
$files | ForEach-Object {
|
||
|
$destinationFile = [IO.Path]::Combine($destination, $_.Name.Replace("264", "265"))
|
||
|
$destinationFile = [IO.Path]::ChangeExtension($destinationFile, ".mkv")
|
||
|
New-Object -TypeName PSObject |
|
||
|
Add-Member -PassThru -MemberType NoteProperty -Name Source -Value $_.FullName |
|
||
|
Add-Member -PassThru -MemberType NoteProperty -Name Target -Value $destinationFile
|
||
|
} |
|
||
|
ForEach-Object {
|
||
|
$targetExists = [IO.File]::Exists($_.Target)
|
||
|
|
||
|
if ($targetExists) {
|
||
|
Write-Host "Target file exists: $($_.Target)"
|
||
|
if ($force.IsPresent) {
|
||
|
Write-Host "Forcing overwrite."
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
Write-Host "Target file does not exist: $($_.Target)"
|
||
|
}
|
||
|
|
||
|
if (($force.IsPresent) -or (-not $targetExists)) {
|
||
|
#$arguments = "$forceArgument -i ""$($_.Source)"" -map_metadata 0 -map 0 -c:a copy -c:s copy -c:v libx265 -crf $quality -preset $preset ""$($_.Target)"""
|
||
|
$arguments = "$forceArgument -i ""$($_.Source)"" -map_metadata 0 -map 0 -c copy -c:v libx265 -crf $quality -preset $preset ""$($_.Target)"""
|
||
|
Write-Host "$nice $ffmpeg $arguments"
|
||
|
#& $nice $ffmpeg $forceArgument -i "$($_.Source)" -map_metadata 0 -map 0:a:0 -c:a copy -map 0:s:0? -c:s copy -map 0:v:0 -c:v libx265 -crf $quality -preset $preset "$($_.Target)"
|
||
|
& $nice $ffmpeg $forceArgument -i "$($_.Source)" -map_metadata 0 -map 0 -c copy -c:v libx265 -crf $quality -preset $preset "$($_.Target)"
|
||
|
}
|
||
|
}
|