-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode_videos_recursive.ps1
More file actions
100 lines (81 loc) · 2.63 KB
/
encode_videos_recursive.ps1
File metadata and controls
100 lines (81 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env pwsh
param (
[string]$InputDir,
[string]$PrimaryOutputDir,
[string]$FallbackOutputDir,
[int]$MinFreeSpaceGB = 50
)
# --- Interaktive Eingaben ---
if (-not $InputDir) {$InputDir = Read-Host "Pfad zum Eingabeordner"}
if (-not $PrimaryOutputDir) {$PrimaryOutputDir = Read-Host "Primärer Ausgabeordner"}
if (-not $FallbackOutputDir) {$FallbackOutputDir = Read-Host "Fallback-Ausgabeordner"}
# --- Validierung ---
foreach ($path in @($InputDir, $PrimaryOutputDir, $FallbackOutputDir)) {
if (-not (Test-Path -LiteralPath $path)) {
Write-Error "Pfad existiert nicht: $path"
exit 1
}
}
# --- Freien Speicher prüfen (am Laufwerk des PrimaryOutputDir) ---
function Get-FreeSpaceGB {
param (
[Parameter(Mandatory)]
[string]$Path
)
$resolvedPath = Resolve-Path -LiteralPath $Path
if ($IsWindows) {
$drive = (Get-Item $resolvedPath).PSDrive
return [math]::Floor($drive.Free / 1GB)
}
else {
# Unix-like Systeme: df benutzen
$dfOutput = df -Pk $resolvedPath.Path | Select-Object -Last 1
$availableKB = ($dfOutput -split '\s+')[3]
return [math]::Floor($availableKB / 1MB)
}
}
$freeSpaceGB = Get-FreeSpaceGB -Path $PrimaryOutputDir
if ($freeSpaceGB -lt $MinFreeSpaceGB) {
Write-Warning "Nur $freeSpaceGB GB frei. Nutze Fallback-Ziel."
$OutputRoot = $FallbackOutputDir
}
else {
Write-Host "Genug Speicher vorhanden ($freeSpaceGB GB). Nutze primäres Ziel."
$OutputRoot = $PrimaryOutputDir
}
# --- Dateien rekursiv verarbeiten ---
$videoFiles = Get-ChildItem -Path $InputDir -Recurse -File |
Where-Object { $_.Extension -match '\.mkv$' }
if ($videoFiles.Count -eq 0) {
Write-Warning "Keine MKV-Dateien gefunden."
exit 0
}
foreach ($file in $videoFiles) {
# Relativen Pfad berechnen
$relativePath = $file.Directory.FullName.Substring($InputDir.Length).TrimStart('/')
$targetDir = Join-Path $OutputRoot $relativePath
$targetFile = Join-Path $targetDir ($file.BaseName + ".mkv")
if (-not (Test-Path $targetDir)) {
New-Item -ItemType Directory -Path $targetDir | Out-Null
}
Write-Host "Konvertiere:`n$file -> $targetFile"
& ffmpeg `
-hwaccel_device qsv `
-i $file.FullName `
-map 0:v:0 `
-map 0:a `
-map 0:s? `
-map_chapters 0 `
-c:v av1_qsv `
-q:v 20 `
-preset slower `
-g 600 `
-pix_fmt p010le `
-c:a copy `
-c:s copy `
$targetFile
if ($LASTEXITCODE -ne 0) {
Write-Warning "Fehler bei: $($file.FullName)"
}
}
Write-Host "Konvertierung abgeschlossen."