$src = (Get-Location).Path
$dst = Join-Path $src "hdhd_new"
$videoExt = @(
".mp4", ".mov", ".m4v", ".avi", ".mkv", ".webm",
".wmv", ".flv", ".mts", ".m2ts", ".3gp"
)
New-Item -ItemType Directory -Force -Path $dst | Out-Null
Get-ChildItem -LiteralPath $src -Recurse -File |
Where-Object {
-not $_.FullName.StartsWith(
$dst + [System.IO.Path]::DirectorySeparatorChar,
[System.StringComparison]::OrdinalIgnoreCase
)
} |
ForEach-Object {
$rel = $_.FullName.Substring($src.Length).TrimStart("\", "/")
$outPath = Join-Path $dst $rel
$outDir = Split-Path -Parent $outPath
New-Item -ItemType Directory -Force -Path $outDir | Out-Null
if ($videoExt -contains $_.Extension.ToLower()) {
if ($_.Extension.ToLower() -eq ".mp4") {
$outVideo = $outPath
} else {
$outVideo = "$outPath.mp4"
}
Write-Host "Перекодирую видео:" $_.FullName
ffmpeg -hide_banner -y -i $_.FullName `
-map 0:v:0 -map 0:a? `
-c:v libx264 `
-preset medium `
-crf 20 `
-profile:v high `
-level 4.1 `
-pix_fmt yuv420p `
-c:a aac `
-b:a 160k `
-ac 2 `
-movflags +faststart `
$outVideo
}
else {
Write-Host "Копирую файл:" $_.FullName
Copy-Item -LiteralPath $_.FullName -Destination $outPath -Force
}
}