-
Notifications
You must be signed in to change notification settings - Fork 0
/
loudnorm.ps1
45 lines (45 loc) · 1.66 KB
/
loudnorm.ps1
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
#!/usr/bin/powershell
[CmdletBinding()]
param(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true,
Position = 0,
HelpMessage = "Enter a file path."
)][Alias("i", "in")][string]$InputFile,
[Parameter(
Position = 1
)][Alias("o", "out")][string]$OutputFile = $InputFile.FullName.Replace($InputFile.Extension, ".flac"),
[switch]$Help = $false,
[hashtable]$FFmpegCustomOpts
)
begin {
if ($h) {
"Normalizes audio using ebu128"
"Requires ffmpeg to be in env:path"
" -InputFile [$InputFile] for input file"
" -OutputFile [$OutputFile] for output file"
exit
}
}
Process {
Get-Item "$InputFile" | ForEach-Object {
$DefaultFFmpegBeginOpts = @{
hide_banner = $null
nostats = $null
y = $null
i = $_.FullName
}
Write-Output "Currently processing $_"
$input_json = ffmpeg @DefaultFFmpegBeginOpts -vn -af "loudnorm=I=-16:TP=-1.5:LRA=11:print_format=json" -f null - 2>&1 | Select-Object -Last 12 | ConvertFrom-Json
[double]$input_i = $input_json.input_i
[double]$input_tp = $input_json.input_tp
[double]$input_lra = $input_json.input_lra
[double]$input_thresh = $input_json.input_thresh
[double]$target_offset = $input_json.target_offset
ffmpeg @DefaultFFmpegBeginOpts -af "loudnorm=I=-16:TP=-1.5:LRA=11:measured_I='$input_i':measured_TP='$input_tp':measured_LRA='$input_lra':measured_thresh='$input_thresh':offset='$target_offset':linear=true:print_format=summary" @FFmpegCustomOpts "$OutputFile"
}
}
end {
Remove-Item "$txt"
}