-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RoughDraft.tests.ps1
266 lines (228 loc) · 10.2 KB
/
RoughDraft.tests.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
if ($PSVersionTable.Platform -eq 'Unix') {
$ffMpegInPath = $ExecutionContext.SessionState.InvokeCommand.GetCommand('ffmpeg', 'Application')
if (-not $ffMpegInPath -and $env:GITHUB_WORKFLOW) {
"::group::Installing FFMpeg" | Out-Host
sudo apt update | Out-Host
sudo apt install ffmpeg | Out-Host
"::endgroup::" | Out-Host
}
}
describe Convert-Media {
it 'Can convert media between formats' {
$tmpOutPath = Join-Path ([IO.Path]::GetTempPath()) "testsrc$(Get-Random).mkv"
$mp4Path = Join-Path ([IO.Path]::GetTempPath()) "testsrc$(Get-Random).mp4"
$converted = New-Media -TestSource testsrc -OutputPath $tmpOutPath -Duration "00:00:01" |
Convert-Media -OutputPath $mp4Path
$converted |
Select-Object -ExpandProperty Extension |
Should -Be .mp4
$converted |
Get-Media |
Select-Object -ExpandProperty Duration |
Should -Be "00:00:01"
Remove-Item $tmpOutPath
Remove-Item $converted.Fullname
}
it 'Can turn a still image into a video' {
$tmpOutPath = Join-Path ([IO.Path]::GetTempPath()) "testsrc$(Get-Random).png"
$converted = New-Media -TestSource testsrc -OutputPath $tmpOutPath -Duration "00:00:01" |
Convert-Media -OutputPath mp4 -Duration "00:15:00"
$converted |
Select-Object -ExpandProperty Extension |
Should -Be .mp4
$converted |
Get-Media |
Select-Object -ExpandProperty Duration |
Should -Be "00:15:00"
Remove-Item $tmpOutPath
Remove-Item $converted.Fullname
}
it 'Can use an extension to -Resize while converting' {
$tmpOutPath = Join-Path ([IO.Path]::GetTempPath()) "testsrc$(Get-Random).mp4"
$tmpOutPath2 = Join-Path ([IO.Path]::GetTempPath()) "testsrc$(Get-Random).mp4"
$converted = New-Media -TestSource testsrc -OutputPath $tmpOutPath -Duration "00:00:05" |
Convert-Media -OutputPath $tmpOutPath2 -Resize '1024x720'
$converted | Get-Media | Select-Object -ExpandProperty Resolution | Should -Be '1024x720'
Remove-Item $tmpOutPath
Remove-Item $tmpOutPath2
}
context "Error Handling" {
it 'Will complain when no codec is found' {
$tmpOutPath = Join-Path ([IO.Path]::GetTempPath()) "testsrc$(Get-Random).png"
New-Media -TestSource testsrc -OutputPath $tmpOutPath -Duration "00:00:05"
$err = @()
Get-Item $tmpOutPath | Convert-Media -Codec askljska -ErrorAction SilentlyContinue -OutputPath .\test.mp4 -ErrorVariable err
$err[-1] | Should -BeLike '*codec*fullname*'
Remove-Item $tmpOutPath
}
}
}
describe ConvertTo-GIF {
it 'Can make gifs' {
$tmpOutPath = Join-Path ([IO.Path]::GetTempPath()) "sine$(Get-Random).mp3"
$tmpOutPath2 = Join-Path ([IO.Path]::GetTempPath()) "sine$(Get-Random).mp4"
$tmpOutPath3 = Join-Path ([IO.Path]::GetTempPath()) "sine$(Get-Random).gif"
$waveform = New-Media -Sine -OutputPath $tmpOutPath -Duration "00:00:05" |
Edit-Media -ShowWaveform -ShowWaveformMode line -OutputPath $tmpOutPath2
$waveform |
ConvertTo-Gif -OutputPath $tmpOutPath3 |
Get-Media |
Select-Object -ExpandProperty Duration |
Should -BeLike "00:00:05*"
Remove-Item $tmpOutPath
Remove-Item $tmpOutPath2
Remove-Item $tmpOutPath3
}
}
describe Edit-Media {
it 'Can edit media' {
$tmpOutPath = Join-Path ([IO.Path]::GetTempPath()) "colorspectrum$(Get-Random).mp4"
$edited = New-Media -TestSource rgbtestsrc -OutputPath $tmpOutPath -Duration "00:00:05" |
Edit-media -Sepia
$edited.Name | should -belike *_Sepia*
$edited |
Get-Media |
Select-Object -ExpandProperty Duration |
Should -BeLike '00:00:05*'
Remove-Item $edited.FullName
Remove-Item $tmpOutPath
}
context "Error Handling" {
it 'Will complain when no codec is found' {
$tmpOutPath = Join-Path ([IO.Path]::GetTempPath()) "testsrc$(Get-Random).png"
New-Media -TestSource testsrc -OutputPath $tmpOutPath -Duration "00:00:05"
$err = @()
Get-Item $tmpOutPath | Edit-Media -Codec askljska -ErrorAction SilentlyContinue -OutputPath .\test.mp4 -ErrorVariable err -FadeIn
$err[-1] | Should -BeLike '*codec*fullname*'
Remove-Item $tmpOutPath
}
}
}
describe Get-Media {
it 'Can detect volume' {
$tmpOutPath = Join-Path ([IO.Path]::GetTempPath()) "sine$(Get-Random).mp3"
New-Media -Sine -OutputPath $tmpOutPath -Duration "00:00:05" |
Get-Media -VolumeLevel |
Out-String |
Should -BeLike *mean_volume*
Remove-Item $tmpOutPath
}
}
describe Join-Media {
it 'Can combine an audio file and a video file' {
$videoTmpPath = Join-Path ([IO.Path]::GetTempPath()) "Video$(Get-Random).mp4"
$audioTmpPath = Join-Path ([IO.Path]::GetTempPath()) "Audio$(Get-Random).mp3"
$avTmpPath = Join-Path ([IO.Path]::GetTempPath()) "AV$(Get-Random).mp4"
@(
New-Media -TestSource rgbtestsrc -Duration "00:00:30" -OutputPath $videoTmpPath
New-Media -Sine -Duration "00:00:15" -OutputPath $audioTmpPath
) | Join-Media -OutputPath $avTmpPath -Shortest |
Get-Media |
Select-Object -ExpandProperty Duration |
Select-Object -ExpandProperty Seconds |
Should -Be 15
Remove-Item $avTmpPath
Remove-Item $audioTmpPath
Remove-Item $videoTmpPath
}
it 'Can join files of different codecs' {
$videoTmpPaths = @(
Join-Path ([IO.Path]::GetTempPath()) "Video$(Get-Random).mp4"
Join-Path ([IO.Path]::GetTempPath()) "Video$(Get-Random).mp4"
Join-Path ([IO.Path]::GetTempPath()) "JoinedVideo$(Get-Random).mp4"
)
$audioTmpPaths = @(
Join-Path ([IO.Path]::GetTempPath()) "Audio$(Get-Random).mp3"
Join-Path ([IO.Path]::GetTempPath()) "Audio$(Get-Random).wav"
Join-Path ([IO.Path]::GetTempPath()) "JoinedAudio$(Get-Random).mp3"
)
@(
New-Media -TestSource rgbtestsrc -Duration "00:00:30" -OutputPath $videoTmpPaths[0]
New-Media -TestSource rgbtestsrc -Duration "00:00:30" -OutputPath $videoTmpPaths[1]
) | Join-Media -OutputPath $videoTmpPaths[2] |
Get-Media |
Select-Object -ExpandProperty Duration |
Select-Object -ExpandProperty Minutes |
Should -Be 1
@(
New-Media -sine -Duration "00:00:15" -OutputPath $audioTmpPaths[0]
New-Media -sine -Duration "00:00:45" -OutputPath $audioTmpPaths[1]
) | Join-Media -OutputPath $audioTmpPaths[2] |
Get-Media |
Select-Object -ExpandProperty Duration |
Select-Object -ExpandProperty Minutes |
Should -Be 1
$videoTmpPaths | Remove-Item
}
it 'Can make a timelapse from a series of images' {
$tmpOutPaths =
foreach ($n in 1..30) {
Join-Path ([IO.Path]::GetTempPath()) "lapsePart$(Get-Random).jpg"
}
$newImages = $tmpOutPaths | New-Media -OutputPath { $_ } -TestSource rgbtestsrc
$lapseOutPath = Join-Path ([IO.Path]::GetTempPath()) "lapse$(Get-Random).mp4"
$lapseFile = $newImages | Join-Media -OutputPath $lapseOutPath -TimeLapse
$lapseFile | Get-Media | Select-Object -ExpandProperty Duration | Should -BeLike '00:00:01*'
$tmpOutPaths | Remove-Item
$lapseFile | Remove-Item
}
}
describe New-Media {
it 'Can create A test source' {
$tmpOutPath = Join-Path ([IO.Path]::GetTempPath()) "testsrc$(Get-Random).mp4"
New-Media -TestSource testsrc -OutputPath $tmpOutPath -Duration "00:00:05" |
Get-Media |
Select-Object -ExpandProperty Duration |
Should -Be "00:00:05"
Remove-Item $tmpOutPath
}
it 'Can create audio' {
$tmpOutPath = Join-Path ([IO.Path]::GetTempPath()) "sine$(Get-Random).mp3"
New-Media -Sine -OutputPath $tmpOutPath -Duration "00:00:05" |
Get-Media |
Select-Object -ExpandProperty Duration |
Should -BeLike "00:00:05*"
Remove-Item $tmpOutPath
}
it 'Can make a fractal' {
$tmpOutPath = Join-Path ([IO.Path]::GetTempPath()) "mandelbrot$(Get-Random).mp4"
New-Media -Mandelbrot -OutputPath $tmpOutPath -Duration "00:00:05" |
Get-Media |
Select-Object -ExpandProperty Duration |
Select-Object -ExpandProperty Seconds |
Should -Be 5
Remove-Item $tmpOutPath
}
}
describe Set-Media {
it 'Can set media metadata' {
$tmpOutPath = Join-Path ([IO.Path]::GetTempPath()) "sine$(Get-Random).mp3"
New-Media -Sine -OutputPath $tmpOutPath -Duration "00:00:05" |
Set-Media -Property @{title='sine'}
Get-Item $tmpOutPath | Get-Media | Select-Object -ExpandProperty title | should -BeLike sine*
Remove-Item $tmpOutPath
}
it 'Can set album artwork' {
$tmpOutPath = Join-Path ([IO.Path]::GetTempPath()) "sine$(Get-Random).mp3"
$tmpOutPath2 = Join-Path ([IO.Path]::GetTempPath()) "sine$(Get-Random).jpg"
New-Media -TestSource rgbtestsrc -OutputPath $tmpOutPath2
New-Media -Sine -OutputPath $tmpOutPath -Duration "00:00:05" |
Set-Media -AlbumArt $tmpOutPath2
$metadata = Get-Media -InputPath $tmpOutPath
$metadata.Codecs[-1] | Should -Be mjpeg
Remove-Item $tmpOutPath
Remove-Item $tmpOutPath2
}
}
describe Split-Media {
it 'Can Split on a timespan' {
$tmpOutPath = Join-Path ([IO.Path]::GetTempPath()) "sine$(Get-Random).mp3"
New-Media -Sine -OutputPath $tmpOutPath -Duration "00:00:05" |
Split-Media -Start "00:00:02.1230300" |
Get-Media |
Select-Object -ExpandProperty Duration |
Select-Object -ExpandProperty Seconds |
Should -be 2
Remove-Item $tmpOutPath
}
}