-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-NormalizeVideos.ps1
149 lines (122 loc) · 5.12 KB
/
start-NormalizeVideos.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<#
.SYNOPSIS
.
.DESCRIPTION
.
.PARAMETER Path
The path to the .
.PARAMETER LiteralPath
Normalize your video audio
.EXAMPLE
C:\PS>
Start-NormalizeVideos -InputFolder c:\temp\myoldvideos -InputFileType *.mp4 -Backup
Start-NormalizeVideos -InputFolder c:\temp\myoldvideos -Backup
Start-NormalizeVideos -InputFolder c:\temp\myoldvideos -ForceRemove -InputFileType *.mkv
.NOTES
Author: Daniel Jansen
Date: June 06, 2019
#>
param (
$InputFolder, [ValidateSet("*.mp4", "*.mkv", "*.mpg", "All")]$InputFileType, [switch]$Backup,[switch]$ForceRemove
)
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
Function Start-NormalizeVideos ($InputFolder, [ValidateSet("*.mp4", "*.mkv", "*.mpg", "All")]$InputFileType, [switch]$backup,[switch]$ForceRemove){
<#if(!(Test-Path $OutputFolder)){
$reply = Read-Host -Prompt "Output Folder does not exist. Create ? [y/n]"
if ( $reply -match "[yY]" ) {
Highway to the danger zone
Write-Host "Creating output folder"
New-Item -Path $OutputFolder -ItemType Directory -Force
}else {break}
}#>
if(!$InputFileType){
write-host "Inputtype Default (*.mp4)"
$FileType = "*.mp4"
}else {
write-host "Inputtype is: $InputFileType"
$FileType = $InputFileType
}
<#if($Force -eq $true){
#write-host $Force
$reply = Read-Host -Prompt "Force enabled. This means files in output directory are overwritten. Continue ? [y/n]"
if ( $reply -match "[yY]" ) {
# Highway to the danger zone
Write-Host "Continue, files in output directory are overwritten"
$ForceParamter = "-f"
}else {break}
}#>
New-Item -Path "$InputFolder\Backup\" -ItemType Directory -Force | Out-Null
if($inputfiletype -like "All"){
$oldvids = Get-ChildItem $InputFolder -File| Move-Item -Destination "$InputFolder\Backup\"
}else{
$oldvids = Get-ChildItem $InputFolder -File|? {$_.name -like $InputFileType}| Move-Item -Destination "$InputFolder\Backup\"
}
Start-Sleep 1
$Items = Get-ChildItem -Path "$InputFolder\Backup\"
if (!$Items){
Write-Host "no Files Found"
}else {
#$oldvids | Move-Item -Destination "$InputFolder\Backup\"
$Items|% {
Write-Host "Converting: " $_.Name
$FileToConvert = '"'+ ($_.FullName).tostring() + '"'
ffmpeg-normalize $_.FullName -of $InputFolder --normalization-type peak --target-level 0 -c:a libmp3lame -b:a 256k -ext mp4 $ForceParamter
}
if($Backup){
break
}elseif($ForceRemove){
Get-ChildItem -Path "$InputFolder\Backup\"|Remove-Item
}else{
$reply = Read-Host -Prompt "WARNING! You did not choose to keep the backup the original files. Continue removing originals ? [y/n]"
if ( $reply -match "[yY]" ) {
# Highway to the danger zone
Write-Host "Clearing Backup folder"
Get-ChildItem -Path "$InputFolder\Backup\"|Remove-Item
}else {
Write-Host "No worries we saved your originals at `"$InputFolder\Backup\`""
Read-Host "Enter to exit."
break
}
}
}
}
function Register-ffmpeg ([switch]$Replace){
if($replace){
$ffmpeg = ($ENV:PATH).Split((";"))|?{$_ -like "*ffmpeg*"}
if($ffmpeg){
if(Test-Path ($ScriptDir+ "\Temp\temp.path") ){
Move-Item ($ScriptDir+ "\Temp\temp.path") ($ScriptDir+ "\Temp\temp"+(Get-Random)+ ".path") -ea Stop
}
$(($ENV:PATH).Split((";"))|?{$_ -notlike "*ffmpeg*"})|%{Add-Content -NoNewline -Value ($_ + ";") -Path ($ScriptDir+ "\Temp\temp.path") }
if(Test-Path ($ScriptDir+ "\Temp\temp.path") ){
$temppath = Get-Content ($ScriptDir+ "\Temp\temp.path") -ea Stop
$ENV:PATH = $temppath.Substring(0,$temppath.Length-1)
}
}
$Currentffmpeg = $ScriptDir + "\Source\ffmpeg\bin\ffmpeg.exe"
if(test-path $Currentffmpeg){
$ENV:PATH = "$ENV:PATH;$(($Currentffmpeg).ToString())"
}else{
Write-Warning "Could not find ffmpeg in your `$PATH or `$FFMPEG_PATH. Please install ffmpeg from http://ffmpeg.org"
break
}
}
}
# find ffmpeg
$ffmpeg = ($ENV:PATH).Split((";"))|?{$_ -like "*ffmpeg*"}
if(Test-Path $InputFolder){
if($ffmpeg){
if(!(Test-Path $ffmpeg)){
Register-ffmpeg -Replace
}
start-NormalizeVideos -InputFolder $InputFolder -OutputFolder $OutputFolder -InputFileType $InputFileType -backup $Backup
}else{
Register-ffmpeg -Replace
Start-Sleep 5
start-NormalizeVideos -InputFolder $InputFolder -OutputFolder $OutputFolder -InputFileType $InputFileType -force $Force
}
}else{
Write-Warning "Input Path not found"
Read-Host "Enter to exit."
break
}