-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflaccl1.ps1
More file actions
78 lines (73 loc) · 4.03 KB
/
flaccl1.ps1
File metadata and controls
78 lines (73 loc) · 4.03 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
param(
[string]$ext = 'm4a',
[int32]$jobs,
[switch]$h,
[switch]$r
)
if ($jobs -eq 0) {
if ($IsWindows) {
$jobs = (Get-CimInstance -ClassName 'Win32_ComputerSystem').NumberOfLogicalProcessors
} elseif ($IsMacOS) {
$jobs = sysctl -n hw.ncpu
} else {
$jobs = grep.exe -c ^processor /proc/cpuinfo
}
}
if ($h) {
Write-Output "Converts [$ext] files from `$pwd recursivly to flac using CUETool's Flaccl"
Write-Output "Requires CUETools.FLACCL.cmd.exe and ffmpeg to be in env:path"
Write-Output "flaccl can only handle 24bit and 16 bit"
Write-Output "32bit and codecs without a bitdepth will be converted to 24bit"
Write-Output " -ext [$ext] for input file extension"
Write-Output " -jobs [$jobs] for the ammount of concurrent converts"
exit
}
$extension = ('*.' + $ext)
if ($r) {
$lscommands = 'Get-ChildItem -File -Recurse -filter $extension'
} else {
$lscommands = 'Get-ChildItem -File -filter $extension'
}
Invoke-Expression $lscommands | ForEach-Object {
$Check = $false
while ($Check -eq $false) {
if ((Get-Job -State 'Running').Count -ne $jobs) {
Start-Job -ArgumentList $_, $ext -ScriptBlock {
param($inputfile, $ext);
if ($inputfile.Extension -ne '.wav') {
if ((ffprobe.exe -v error -select_streams a:0 -show_entries stream=bits_per_raw_sample -of default=noprint_wrappers=1:nokey=1 -i $inputfile) -eq "16") {
$bit = "16"
} else {
$bit = "24"
}
$tempfile = New-TemporaryFile
ffmpeg.exe -y -threads 8 -loglevel fatal -i $inputfile.FullName -c:a ('pcm_s' + $bit + 'le') -f wav $tempfile.FullName
Move-Item $tempfile.FullName $tempfile.FullName.Replace($tempfile.Extension, '.wav')
$tempi = Get-Item $tempfile.FullName.Replace($tempfile.Extension, '.wav')
} else {
$tempi = Get-Item $inputfile.FullName
}
ffmpeg.exe -y -threads 8 -loglevel fatal -i $inputfile.FullName -map_metadata 0 -map_metadata:s:v 0:s:v -map_metadata:s:a 0:s:a -f ffmetadata $inputfile.FullName.Replace($inputfile.Extension, '.txt')
$tempfile1 = New-TemporaryFile
Move-Item $tempfile1.FullName $tempfile1.FullName.Replace($tempfile1.Extension, '.flac')
CUETools.FLACCL.cmd.exe -8 --cpu-threads 8 --ignore-chunk-sizes -o $tempfile1.FullName.Replace($tempfile1.Extension, '.flac') $tempi.FullName
ffmpeg.exe -y -threads 8 -loglevel fatal -i $tempfile1.FullName.Replace($tempfile1.Extension, '.flac') -i $inputfile.FullName.Replace($inputfile.Extension, '.txt') -map_metadata 1 -c copy $inputfile.FullName.Replace($inputfile.Extension, '.flac')
if (ffprobe.exe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 -i $inputfile) {
if ((ffprobe.exe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 -i $inputfile) -eq "mjpeg") {
$type = ".jpg"
} else {
$type = ".png"
}
ffmpeg.exe -i $inputfile -an -c:v copy -sn $inputfile.FullName.Replace($inputfile.extension, $type)
metaflac.exe --import-picture-from $inputfile.FullName.Replace($inputfile.extension, $type) $inputfile.FullName.Replace($inputfile.Extension, '.flac')
Remove-Item $inputfile.FullName.Replace($inputfile.extension, $type)
}
if ($inputfile.Extension -ne '.wav') { Remove-Item $tempfile.FullName.Replace($tempfile.Extension, '.wav') }
Remove-Item $inputfile.FullName.Replace($inputfile.Extension, '.txt')
Remove-Item $tempfile1.FullName.Replace($tempfile1.Extension, '.flac')
}
$Check = $true
}
}
Remove-Job -State Completed
}