media conversion powershell added
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
param (
|
||||
[Parameter(Mandatory = $true, Position = 0)]
|
||||
[string]$Ext1,
|
||||
|
||||
[Parameter(Mandatory = $true, Position = 1)]
|
||||
[string]$Ext2,
|
||||
|
||||
[int]$Jobs = 4 # Number of simultaneous conversions
|
||||
)
|
||||
|
||||
$sourceExt = $Ext1.TrimStart('.')
|
||||
$targetExt = $Ext2.TrimStart('.')
|
||||
$audioExts = @('opus', 'ogg', 'flac', 'wav')
|
||||
|
||||
$files = Get-ChildItem -File -Recurse -Filter "*.$sourceExt"
|
||||
|
||||
if ($files.Count -eq 0) {
|
||||
Write-Host "No files matching *.$sourceExt found." -ForegroundColor Yellow
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host "Starting conversion using $Jobs parallel jobs..." -ForegroundColor Green
|
||||
|
||||
$files | ForEach-Object -Parallel {
|
||||
$file = $_
|
||||
$targetExt = $using:targetExt
|
||||
$audioExts = $using:audioExts
|
||||
|
||||
$outputPath = Join-Path -Path $file.DirectoryName -ChildPath "$($file.BaseName).$targetExt"
|
||||
$relativePath = Resolve-Path -Path $file.FullName -Relative
|
||||
|
||||
Write-Host "Processing: $relativePath" -ForegroundColor Cyan
|
||||
|
||||
if ($audioExts -contains $targetExt.ToLower()) {
|
||||
ffmpeg -y -i $file.FullName -c:a libopus -b:a 128k -vbr on $outputPath 2>$null
|
||||
} else {
|
||||
# -preset 8 drastically speeds up SVT-AV1 while maintaining high quality
|
||||
ffmpeg -y -i $file.FullName -c:v libsvtav1 -crf 26 -preset 8 -c:a libopus -b:a 128k $outputPath 2>$null
|
||||
}
|
||||
} -ThrottleLimit $Jobs
|
||||
|
||||
Write-Host "Finished processing $($files.Count) file(s)." -ForegroundColor Green
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Step 1: Recursively delete all existing .sha256 files
|
||||
# -------------------------------------------------------------------------
|
||||
Write-Host "Deleting existing .sha256 files recursively..." -ForegroundColor Yellow
|
||||
Get-ChildItem -Path . -Recurse -Filter "*.sha256" -File | Remove-Item -Force
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Step 2: Run checksums in current directory and every subdirectory
|
||||
# -------------------------------------------------------------------------
|
||||
Write-Host "Generating checksums in each subfolder..." -ForegroundColor Cyan
|
||||
|
||||
# Gather current working directory and all child directories
|
||||
$allDirs = @((Get-Item .).FullName) + (Get-ChildItem -Path . -Recurse -Directory | Select-Object -ExpandProperty FullName)
|
||||
|
||||
foreach ($dir in $allDirs) {
|
||||
Push-Location $dir
|
||||
try {
|
||||
Write-Host "Updating checksums in: $dir" -ForegroundColor Gray
|
||||
checksum * -o
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Step 3: Recursively verify checksums in each directory
|
||||
# -------------------------------------------------------------------------
|
||||
Write-Host "Verifying checksums in each subfolder..." -ForegroundColor Cyan
|
||||
|
||||
foreach ($dir in $allDirs) {
|
||||
Push-Location $dir
|
||||
try {
|
||||
if (Test-Path "checksums.sha256") {
|
||||
Write-Host "Verifying: $dir" -ForegroundColor Gray
|
||||
checksum -c checksums.sha256
|
||||
}
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "All conversions, checksum creations, and verifications completed successfully." -ForegroundColor Green
|
||||
Reference in New Issue
Block a user