-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcommands.spec.ts
258 lines (222 loc) · 7.67 KB
/
commands.spec.ts
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
import { test, expect, Page } from '@playwright/test';
// Annotate entire file as serial.
test.describe.configure({ mode: 'serial' });
let page: Page;
test.describe('FFmpeg create command', async () => {
/**
* Get index page and wait until ffmpeg is ready
*/
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
await page.goto('http://localhost:5173/');
const ready = await page.evaluate(async () => {
if (!ffmpeg.isReady) {
await new Promise<void>((resolve) => {
ffmpeg.whenReady(resolve);
});
}
return ffmpeg.isReady;
});
expect(ready).toBe(true);
});
test('test that basic command can be created', async () => {
const command = await page.evaluate(async () => {
return await ffmpeg
.input({ source: 'abc.mp4' })
.ouput({ format: 'mp3' })
.command();
});
expect(command.length).toBe(3);
expect(command.at(0)).toBe('-i');
expect(command.at(1)).toBe('abc.mp4');
expect(command.at(-1)?.endsWith('.mp3')).toBe(true);
});
test('test that new input resets exisiting ones', async () => {
const command = await page.evaluate(async () => {
ffmpeg
.input({ source: 'abc.mp4' })
.ouput({ format: 'mp3', duration: 20 });
return await ffmpeg
.input({ source: 'rrr.mp4' })
.ouput({ format: 'm4v', duration: 10 })
.command();
});
expect(command.length).toBe(5);
expect(command.at(0)).toBe('-i');
expect(command.at(1)).toBe('rrr.mp4');
expect(command.at(2)).toBe('-t');
expect(command.at(3)).toBe('10');
expect(command.at(-1)?.endsWith('.m4v')).toBe(true);
});
test('test that input seeking works', async () => {
const command = await page.evaluate(async () => {
return await ffmpeg
.input({ source: 'cba.mp3', seek: 40 })
.ouput({ format: 'wav' })
.command();
});
expect(command.length).toBe(5);
expect(command.at(0)).toBe('-ss');
expect(command.at(1)).toBe('40');
expect(command.at(2)).toBe('-i');
expect(command.at(3)).toBe('cba.mp3');
expect(command.at(-1)?.endsWith('.wav')).toBe(true);
});
test('test that using an image sequence as input works', async () => {
const command = await page.evaluate(async () => {
return await ffmpeg
.input({
sequence: ['my-image-0001.png', 'my-image-0002.png'],
framerate: 30,
})
.ouput({ format: 'm4v' })
.command();
});
expect(command.length).toBe(5);
expect(command.at(0)).toBe('-framerate');
expect(command.at(1)).toBe('30');
expect(command.at(2)).toBe('-i');
// make sure the pattern has been matched correctly
expect(command.at(3)).toBe('my-image-%04d.png');
expect(command.at(-1)?.endsWith('.m4v')).toBe(true);
});
test('test that adding filters works', async () => {
const command = await page.evaluate(async () => {
return await ffmpeg
.input({ source: 'ccc.mp4' })
.videoFilter('rotate=90')
.audioFilter('silencedetect=noise=0.0001')
.ouput({ format: 'm4v', seek: 10 })
.command();
});
expect(
command
.join(' ')
.startsWith(
'-i ccc.mp4 -vf rotate=90 -af silencedetect=noise=0.0001 -ss 10'
)
).toBe(true);
expect(command.at(-1)?.endsWith('.m4v')).toBe(true);
});
test('test that adding a filter to multiple inputs throws error', async () => {
const result = await page.evaluate(async () => {
try {
await ffmpeg
.input({ source: 'abc.mov' })
.input({ source: 'xyz.mov' })
.videoFilter('scale=640:360')
.ouput({ format: 'm4v' })
.command();
return false;
} catch (e) {
return true;
}
});
expect(result).toBe(true);
});
test('test that adding complex filters works', async () => {
const command = await page.evaluate(async () => {
return await ffmpeg
.input({ source: 'abc.webm' })
.input({ source: 'xyz.png' })
.complexFilter('overlay')
.ouput({ format: 'm4v' })
.command();
});
expect(command.at(0)).toBe('-i');
expect(command.at(1)).toBe('abc.webm');
expect(command.at(2)).toBe('-i');
expect(command.at(3)).toBe('xyz.png');
expect(command.at(4)).toBe('-filter_complex');
expect(command.at(5)).toBe('overlay');
expect(command.at(-1)?.endsWith('.m4v')).toBe(true);
});
test('test that adding video output options works', async () => {
const command = await page.evaluate(async () => {
return await ffmpeg
.input({ source: 'bbb.webm' })
.ouput({
format: 'm4v',
video: {
codec: 'h263',
aspectRatio: 4,
bitrate: 2_000_000,
framerate: 25,
size: { width: 640, height: 480 },
},
})
.command();
});
expect(command.includes('-c:v')).toBe(true);
expect(command.includes('h263')).toBe(true);
expect(command.indexOf('h263')).toBe(command.indexOf('-c:v') + 1);
expect(command.includes('-aspect')).toBe(true);
expect(command.includes('4')).toBe(true);
expect(command.indexOf('4')).toBe(command.indexOf('-aspect') + 1);
expect(command.includes('-b:v')).toBe(true);
expect(command.includes('2000000')).toBe(true);
expect(command.indexOf('2000000')).toBe(command.indexOf('-b:v') + 1);
expect(command.includes('-r')).toBe(true);
expect(command.includes('25')).toBe(true);
expect(command.indexOf('25')).toBe(command.indexOf('-r') + 1);
expect(command.includes('-s')).toBe(true);
expect(command.includes('640x480')).toBe(true);
expect(command.indexOf('640x480')).toBe(command.indexOf('-s') + 1);
});
test('test that video output can be disabled', async () => {
const command = await page.evaluate(async () => {
return await ffmpeg
.input({ source: 'bbb.webm' })
.ouput({
format: 'm4v',
video: { disableVideo: true },
})
.command();
});
expect(command.at(2)).toBe('-vn');
});
test('test that adding audio output options works', async () => {
const command = await page.evaluate(async () => {
return await ffmpeg
.input({ source: 'bbb.webm' })
.ouput({
format: 'm4v',
audio: {
codec: 'aac',
bitrate: 128_000,
numberOfChannels: 2,
sampleRate: 44100,
volume: 200,
},
})
.command();
});
expect(command.includes('-c:a')).toBe(true);
expect(command.includes('aac')).toBe(true);
expect(command.indexOf('aac')).toBe(command.indexOf('-c:a') + 1);
expect(command.includes('-b:a')).toBe(true);
expect(command.includes('128000')).toBe(true);
expect(command.indexOf('128000')).toBe(command.indexOf('-b:a') + 1);
expect(command.includes('-ac')).toBe(true);
expect(command.includes('2')).toBe(true);
expect(command.indexOf('2')).toBe(command.indexOf('-ac') + 1);
expect(command.includes('-ar')).toBe(true);
expect(command.includes('44100')).toBe(true);
expect(command.indexOf('44100')).toBe(command.indexOf('-ar') + 1);
expect(command.includes('-vol')).toBe(true);
expect(command.includes('200')).toBe(true);
expect(command.indexOf('200')).toBe(command.indexOf('-vol') + 1);
});
test('test that audio output can be disabled', async () => {
const command = await page.evaluate(async () => {
return await ffmpeg
.input({ source: 'bbb.webm' })
.ouput({
format: 'm4v',
audio: { disableAudio: true },
})
.command();
});
expect(command.at(2)).toBe('-an');
});
});