Skip to content

Commit 7061dd9

Browse files
committed
Add original scripts
1 parent 88e5c5b commit 7061dd9

File tree

9 files changed

+362
-0
lines changed

9 files changed

+362
-0
lines changed

7zfolder.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
param(
2+
[int32]$jobs,
3+
[string]$path = $PWD,
4+
[switch]$h
5+
)
6+
7+
if ($jobs -eq 0) {
8+
if ($IsWindows) {
9+
$jobs = (Get-CimInstance -ClassName 'Win32_ComputerSystem').NumberOfLogicalProcessors
10+
} elseif ($IsMacOS) {
11+
$jobs = sysctl -n hw.ncpu
12+
} else {
13+
$jobs = grep.exe -c ^processor /proc/cpuinfo
14+
}
15+
}
16+
17+
if ($h) {
18+
Write-Output "Tars folders in `$path"
19+
Write-Output "Must have 7z in env:path"
20+
Write-Output "Slightly tested on *nix"
21+
Write-Output " -jobs [$jobs] for the ammount of concurrent converts"
22+
Write-Output " -path [$path] where 7z will look from and output to"
23+
exit
24+
}
25+
if (-Not (Test-Path -Path $path)) {
26+
Exit
27+
}
28+
Get-ChildItem -Directory $path | ForEach-Object {
29+
$Check = $false
30+
while ($Check -eq $false) {
31+
if ((Get-Job -State 'Running').Count -lt $jobs) {
32+
Start-Job -ArgumentList $_, $path -ScriptBlock {
33+
param($folder, $path)
34+
$folder = Get-Item $folder
35+
7z.exe a $path/$($folder.basename).tar $($folder.FullName + '/*')
36+
}
37+
$Check = $true
38+
}
39+
}
40+
Remove-Job -State Completed
41+
}

flaccl1.ps1

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
param(
2+
[string]$ext = 'm4a',
3+
[int32]$jobs,
4+
[switch]$h,
5+
[switch]$r
6+
)
7+
8+
if ($jobs -eq 0) {
9+
if ($IsWindows) {
10+
$jobs = (Get-CimInstance -ClassName 'Win32_ComputerSystem').NumberOfLogicalProcessors
11+
} elseif ($IsMacOS) {
12+
$jobs = sysctl -n hw.ncpu
13+
} else {
14+
$jobs = grep.exe -c ^processor /proc/cpuinfo
15+
}
16+
}
17+
18+
if ($h) {
19+
Write-Output "Converts [$ext] files from `$pwd recursivly to flac using CUETool's Flaccl"
20+
Write-Output "Requires CUETools.FLACCL.cmd.exe and ffmpeg to be in env:path"
21+
Write-Output "flaccl can only handle 24bit and 16 bit"
22+
Write-Output "32bit and codecs without a bitdepth will be converted to 24bit"
23+
Write-Output " -ext [$ext] for input file extension"
24+
Write-Output " -jobs [$jobs] for the ammount of concurrent converts"
25+
exit
26+
}
27+
28+
$extension = ('*.' + $ext)
29+
30+
if ($r) {
31+
$lscommands = 'Get-ChildItem -File -Recurse -filter $extension'
32+
} else {
33+
$lscommands = 'Get-ChildItem -File -filter $extension'
34+
}
35+
36+
Invoke-Expression $lscommands | ForEach-Object {
37+
$Check = $false
38+
while ($Check -eq $false) {
39+
if ((Get-Job -State 'Running').Count -ne $jobs) {
40+
Start-Job -ArgumentList $_, $ext -ScriptBlock {
41+
param($inputfile, $ext);
42+
if ($inputfile.Extension -ne '.wav') {
43+
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") {
44+
$bit = "16"
45+
} else {
46+
$bit = "24"
47+
}
48+
$tempfile = New-TemporaryFile
49+
ffmpeg.exe -y -threads 8 -loglevel fatal -i $inputfile.FullName -c:a ('pcm_s' + $bit + 'le') -f wav $tempfile.FullName
50+
Move-Item $tempfile.FullName $tempfile.FullName.Replace($tempfile.Extension, '.wav')
51+
$tempi = Get-Item $tempfile.FullName.Replace($tempfile.Extension, '.wav')
52+
} else {
53+
$tempi = Get-Item $inputfile.FullName
54+
}
55+
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')
56+
$tempfile1 = New-TemporaryFile
57+
Move-Item $tempfile1.FullName $tempfile1.FullName.Replace($tempfile1.Extension, '.flac')
58+
CUETools.FLACCL.cmd.exe -8 --cpu-threads 8 --ignore-chunk-sizes -o $tempfile1.FullName.Replace($tempfile1.Extension, '.flac') $tempi.FullName
59+
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')
60+
if (ffprobe.exe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 -i $inputfile) {
61+
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") {
62+
$type = ".jpg"
63+
} else {
64+
$type = ".png"
65+
}
66+
ffmpeg.exe -i $inputfile -an -c:v copy -sn $inputfile.FullName.Replace($inputfile.extension, $type)
67+
metaflac.exe --import-picture-from $inputfile.FullName.Replace($inputfile.extension, $type) $inputfile.FullName.Replace($inputfile.Extension, '.flac')
68+
Remove-Item $inputfile.FullName.Replace($inputfile.extension, $type)
69+
}
70+
if ($inputfile.Extension -ne '.wav') { Remove-Item $tempfile.FullName.Replace($tempfile.Extension, '.wav') }
71+
Remove-Item $inputfile.FullName.Replace($inputfile.Extension, '.txt')
72+
Remove-Item $tempfile1.FullName.Replace($tempfile1.Extension, '.flac')
73+
}
74+
$Check = $true
75+
}
76+
}
77+
Remove-Job -State Completed
78+
}

losslesstest.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
param(
2+
[string]$i,
3+
$encoders = ("ffv1", "libx264", "libx265", "libvpx-vp9", "libaom-av1", "nvenc_hevc", "nvenc")
4+
)
5+
$i = Get-Item $i
6+
foreach ($b in $encoders) {
7+
$argument = switch ($b) {
8+
ffv1 { '-context 1' }
9+
libx264 { '-preset placebo -qp 0' }
10+
libx265 { '-preset placebo -x265-params lossless=1' }
11+
libvpx-vp9 { '-lossless:v 1 -deadline:v best -cpu-used:v 0 -b:v 0 -crf 0' }
12+
libaom-av1 { '-strict experimental -crf 0 -b:v 0' }
13+
nvenc* { '-preset:v lossless' }
14+
Default { '-lossless:v 1' }
15+
}
16+
Measure-Command -Expression { Invoke-Expression "ffmpeg -y -threads 8 -hide_banner -i $i -c:v $b $argument -c:a copy -sn $($b).mkv 2>&1 | Out-File $($b + '.txt')"
17+
}
18+
}

loudnorm.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
param(
2+
[string]$i = 'm4a',
3+
[string]$o = 'flac',
4+
[int32]$jobs,
5+
[switch]$h
6+
)
7+
8+
if ($jobs -eq 0) {
9+
if ($IsWindows) {
10+
$jobs = (Get-CimInstance -ClassName 'Win32_ComputerSystem').NumberOfLogicalProcessors
11+
} elseif ($IsMacOS) {
12+
$jobs = sysctl -n hw.ncpu
13+
} else {
14+
$jobs = grep.exe -c ^processor /proc/cpuinfo
15+
}
16+
}
17+
18+
if ($h) {
19+
Write-Output "Normalizes audio using ebu128"
20+
Write-Output "Requires ffmpeg to be in env:path"
21+
Write-Output "Resamples audio to 48k"
22+
Write-Output " -i [$i] for input file extension"
23+
Write-Output " -o [$o] for output file extension"
24+
Write-Output " -jobs [$jobs] for the ammount of concurrent converts"
25+
exit
26+
}
27+
28+
Get-ChildItem -Recurse -Filter "$('*.' + $i)" | ForEach-Object {
29+
$path = $_.FullName
30+
$txt = $_.FullName.Replace($_.Extension, '.txt')
31+
$outfile = $_.FullName.Replace($_.Extension, "$('.' + $o)")
32+
Get-Variable _
33+
ffmpeg.exe -hide_banner -nostats -i $path -af "loudnorm=I=-16:TP=-1.5:LRA=11:print_format=json" -f null - 2>&1 | grep.exe "input\|target" | Out-File -Encoding UTF8 "$txt"
34+
$input_i = Get-Content "$txt" | grep.exe "input_i" | grep.exe -Eo -- "[-+]?[0-9]+\.[0-9]+"
35+
$input_tp = Get-Content "$txt" | grep.exe "input_tp" | grep.exe -Eo -- "[-+]?[0-9]+\.[0-9]+"
36+
$input_lra = Get-Content "$txt" | grep.exe "input_lra" | grep.exe -Eo -- "[-+]?[0-9]+\.[0-9]+"
37+
$input_thresh = Get-Content "$txt" | grep.exe "input_thresh" | grep.exe -Eo -- "[-+]?[0-9]+\.[0-9]+"
38+
$target_offset = Get-Content "$txt" | grep.exe "target_offset" | grep.exe -Eo -- "[-+]?[0-9]+\.[0-9]+"
39+
ffmpeg.exe -hide_banner -nostats -y -i $path -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" -ar 48k $outfile
40+
Remove-Item "$txt"
41+
}

loudnorm1.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
param(
2+
[string]$inf = 'm4a',
3+
[string]$outf = 'flac',
4+
[int32]$jobs,
5+
[switch]$h
6+
)
7+
8+
if ($jobs -eq 0) {
9+
if ($IsWindows) {
10+
$jobs = (Get-CimInstance -ClassName 'Win32_ComputerSystem').NumberOfLogicalProcessors
11+
} elseif ($IsMacOS) {
12+
$jobs = sysctl -n hw.ncpu
13+
} else {
14+
$jobs = grep.exe -c ^processor /proc/cpuinfo
15+
}
16+
}
17+
18+
Get-ChildItem -Recurse -Filter "$('*.' + $inf)" | ForEach-Object {
19+
$Check = $false
20+
while ($Check -eq $false) {
21+
if ((Get-Job -State 'Running').Count -ne $jobs) {
22+
Start-Job -ArgumentList $_, $outf, $inf -ScriptBlock {
23+
param($inputfile, $outf, $inf);
24+
$txt = New-TemporaryFile
25+
ffmpeg.exe -hide_banner -nostats -i $inputfile.FullName -af "loudnorm=I=-16:TP=-1.5:LRA=11:print_format=json" -f null - 2>&1 | grep.exe "input\|target" | Out-File -Encoding UTF8 $txt
26+
$input_i = Get-Content $txt | grep.exe "input_i" | grep.exe -Eo -- "[-+]?[0-9]+\.[0-9]+"
27+
$input_tp = Get-Content $txt | grep.exe "input_tp" | grep.exe -Eo -- "[-+]?[0-9]+\.[0-9]+"
28+
$input_lra = Get-Content $txt | grep.exe "input_lra" | grep.exe -Eo -- "[-+]?[0-9]+\.[0-9]+"
29+
$input_thresh = Get-Content $txt | grep.exe "input_thresh" | grep.exe -Eo -- "[-+]?[0-9]+\.[0-9]+"
30+
$target_offset = Get-Content $txt | grep.exe "target_offset" | grep.exe -Eo -- "[-+]?[0-9]+\.[0-9]+"
31+
ffmpeg.exe -hide_banner -nostats -y -i $inputfile.FullName -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" -ar 48k $inputfile.FullName.Replace($inputfile.Extension, $('.' + $outf))
32+
Remove-Item $txt
33+
}
34+
$Check = $true
35+
}
36+
}
37+
Remove-Job -State Completed
38+
}

multiencode.ps1

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
param(
2+
[Parameter(Mandatory = $true)][string]$i = ".jpg",
3+
[Parameter(Mandatory = $true)][string]$o = ".webp",
4+
[int]$jobs,
5+
[string]$ve,
6+
[string]$vc,
7+
[string]$ae,
8+
[string]$ac
9+
)
10+
11+
if ($jobs -eq 0) {
12+
if ($IsWindows) {
13+
$jobs = (Get-CimInstance -ClassName 'Win32_ComputerSystem').NumberOfLogicalProcessors
14+
} elseif ($IsMacOS) {
15+
$jobs = sysctl -n hw.ncpu
16+
} else {
17+
$jobs = grep.exe -c ^processor /proc/cpuinfo
18+
}
19+
}
20+
21+
Get-Item ('*' + $i) | ForEach-Object {
22+
$Check = $false
23+
while ($Check -eq $false) {
24+
if ((Get-Job -State 'Running').Count -ne 8) {
25+
Start-Job -ArgumentList $_, $i, $o, $ve, $vc, $ae, $ac -ScriptBlock {
26+
param($inputfile, $informat, $outformat, $ve, $vc, $ae, $ac);
27+
$infile = Get-Item $inputfile
28+
$audioencoder = ("-c:a " + $ae)
29+
$videoencoder = ("-c:v " + $ve)
30+
if ([string]::IsNullOrEmpty($ve)) {
31+
if ([string]::IsNullOrEmpty($ae)) {
32+
Write-Output "w/o both"
33+
ffmpeg.exe -threads 8 -y -i $infile.FullName $infile.FullName.Replace($infile.Extension, $outformat)
34+
} else {
35+
Write-Output "w/o video"
36+
ffmpeg.exe -threads 8 -y -i $infile.FullName $audioencoder $infile.FullName.Replace($infile.Extension, $outformat)
37+
}
38+
} else {
39+
if ([string]::IsNullOrEmpty($ae)) {
40+
Write-Output "w/o audio"
41+
Write-Output $videoencoder
42+
Write-Output $vc
43+
ffmpeg.exe -threads 8 -v 100 -y -i $infile.FullName -c:v $ve -lossless:v 1 -pix_fmt bgra $infile.FullName.Replace($infile.Extension, $outformat)
44+
} else {
45+
Write-Output "w both"
46+
ffmpeg.exe -threads 8 -y -i $infile.FullName $videoencoder $audioencoder $infile.FullName.Replace($infile.Extension, $outformat)
47+
}
48+
}
49+
50+
51+
# Write-Output $infile.FullName $videoencoder $audioencoder ((join-path $infile.DirectoryName $infile.BaseName) + $outformat)
52+
# ffmpeg -threads 8 -y -i $infile.FullName $videoencoder $audioencoder ((join-path $infile.DirectoryName $infile.BaseName) + $outformat)
53+
# $inputfile.FullName.Replace($inputfile.Extension,$('.' + $outf))
54+
}
55+
$Check = $true
56+
}
57+
}
58+
# Remove-Job -State Completed
59+
}

splitencode.ps1

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
param(
2+
[Parameter(Mandatory = $true)][string]$i,
3+
[int32]$s = 300,
4+
[int32]$jobs,
5+
[switch]$h
6+
)
7+
8+
if ($jobs -eq 0) {
9+
if ($IsWindows) {
10+
$jobs = (Get-CimInstance -ClassName 'Win32_ComputerSystem').NumberOfLogicalProcessors
11+
} elseif ($IsMacOS) {
12+
$jobs = sysctl -n hw.ncpu
13+
} else {
14+
$jobs = grep.exe -c ^processor /proc/cpuinfo
15+
}
16+
}
17+
18+
$infile0 = Get-Item $i
19+
mkdir -Force $infile0.BaseName > $null
20+
ffmpeg.exe -threads 8 -loglevel fatal -y -i $infile0.FullName -c copy -map 0 -segment_time $s -f segment -reset_timestamps 1 ($infile0.BaseName + "/%03d" + $infile0.Extension)
21+
22+
Set-Location $infile0.BaseName
23+
$Workpwd = Get-ChildItem -Directory -Filter $infile0.BaseName
24+
Get-ChildItem -File -Filter ('*' + $infile0.Extension) | ForEach-Object {
25+
$Check = $false
26+
while ($Check -eq $false) {
27+
if ((Get-Job -State 'Running').Count -ne $jobs) {
28+
Start-Job -ArgumentList $_, $Workpwd -ScriptBlock {
29+
param($inputfile, $Workpwd)
30+
$tmpfile = New-TemporaryFile
31+
Set-Location $Workpwd
32+
ffmpeg.exe -threads 8 -y -i $inputfile.FullName -c:v libx265 -preset veryslow -c:a libopus -f matroska $tmpfile
33+
Move-Item -Force $tmpfile $inputfile.FullName
34+
}
35+
$Check = $true
36+
}
37+
}
38+
Remove-Job -State Completed
39+
}
40+
Get-ChildItem -Filter "*.mkv" -name | ForEach-Object { Write-Output "file '$_'" } | Out-File -Encoding utf8 cat.txt
41+
(Get-Content cat.txt -Raw).Replace("`r`n", "`n") | Set-Content cat.txt -Force
42+
ffmpeg.exe -threads 8 -y -f concat -safe 0 -i cat.txt -c copy ('../' + $infile0.BaseName + 'new' + $infile0.Extension)
43+
Set-Location ..

splitvideo.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
param(
2+
[Parameter(Mandatory = $true)][string]$i,
3+
[int32]$s = 300
4+
)
5+
6+
$infile = Get-Item $i
7+
mkdir $infile.BaseName 2>1 | Out-Null
8+
ffmpeg.exe -threads 8 -loglevel fatal -i $infile.FullName -c copy -map 0 -segment_time $s -f segment -reset_timestamps 1 ($infile.BaseName + "/%03d" + $infile.Extension)

volnorm.ps1

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
param(
2+
[string]$inf = 'm4a',
3+
[string]$outf = 'flac',
4+
[int32]$jobs,
5+
[switch]$h
6+
)
7+
8+
if ($jobs -eq 0) {
9+
if ($IsWindows) {
10+
$jobs = (Get-CimInstance -ClassName 'Win32_ComputerSystem').NumberOfLogicalProcessors
11+
} elseif ($IsMacOS) {
12+
$jobs = sysctl -n hw.ncpu
13+
} else {
14+
$jobs = grep.exe -c ^processor /proc/cpuinfo
15+
}
16+
}
17+
18+
Get-ChildItem -Recurse -File -Filter "$('*.' + $inf)" | ForEach-Object {
19+
$Check = $false
20+
while ($Check -eq $false) {
21+
if ((Get-Job -State 'Running').Count -ne $jobs) {
22+
Start-Job -ArgumentList $_, $inf -ScriptBlock {
23+
param($inputfile, $inf);
24+
$tempfile = New-TemporaryFile
25+
$bit = ffprobe.exe -v error -select_streams a:0 -show_entries stream=bits_per_raw_sample -of default=noprint_wrappers=1:nokey=1 -i $inputfile
26+
$gain = (ffmpeg.exe -hide_banner -nostats -i $inputfile -af "replaygain" -f null NULL 2>&1 | grep.exe "track_gain" | cut.exe -d ' ' -f 6-) | Out-String
27+
ffmpeg.exe -y -hide_banner -nostats -threads 8 -i $inputfile.FullName -af "volume=$gain" -c:a ('pcm_s' + $bit + 'le') -f wav $tempfile.FullName
28+
ffmpeg.exe -y -hide_banner -nostats -threads 8 -i $tempfile.FullName -c:a flac $inputfile.FullName.Replace($inputfile.Extension, '.flac')
29+
Remove-Item $tempfile.FullName
30+
}
31+
$Check = $true
32+
}
33+
}
34+
# Remove-Job -State Completed
35+
}
36+
#-filter_complex "[0:a]volume=$gain[1:a];[1:a]volume=+6dB[outa]" -map "[outa]"

0 commit comments

Comments
 (0)