/
export.spec.ts
155 lines (131 loc) · 4.34 KB
/
export.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
import { test, expect, Page } from '@playwright/test';
// Annotate entire file as serial.
test.describe.configure({ mode: 'serial' });
let page: Page;
test.describe('FFmpeg basic exporting', 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 converting ogg into wav', async () => {
const length = await page.evaluate(async () => {
const result = await ffmpeg
.input({ source: 'http://localhost:5173/samples/audio.ogg' })
.ouput({ format: 'wav' })
.export();
// evaluate return type can't be Uint8Array
return result?.length;
});
expect(length).toBeGreaterThan(0);
});
test('test converting ogg to flac', async () => {
const length = await page.evaluate(async () => {
const result = await ffmpeg
.input({ source: 'http://localhost:5173/samples/audio.ogg' })
.ouput({ format: 'flac' })
.export();
return result?.length;
});
expect(length).toBeGreaterThan(0);
});
test('test converting ogg to m4v using aac encoding', async () => {
const length = await page.evaluate(async () => {
const result = await ffmpeg
.input({ source: 'http://localhost:5173/samples/audio.ogg' })
.ouput({
format: 'm4v',
audio: {
codec: 'aac',
bitrate: 64_000,
numberOfChannels: 1,
sampleRate: 11025,
},
})
.export();
return result?.length;
});
expect(length).toBeGreaterThan(0);
});
test('test converting mp3 to ogg', async () => {
const length = await page.evaluate(async () => {
const result = await ffmpeg
.input({ source: 'http://localhost:5173/samples/audio.mp3' })
.ouput({ format: 'ogg' })
.export();
return result?.length;
});
expect(length).toBeGreaterThan(0);
});
test('test cutting a mp3 and and converting it to wav', async () => {
const lengths = await page.evaluate(async () => {
const result1 = await ffmpeg
.input({ source: 'http://localhost:5173/samples/audio.mp3' })
.ouput({ format: 'wav' })
.export();
const result2 = await ffmpeg
.input({ source: 'http://localhost:5173/samples/audio.mp3', seek: 5 })
.ouput({ format: 'wav', duration: 5 })
.export();
return [result1?.length, result2?.length];
});
expect(lengths[0]).toBeGreaterThan(lengths[1] ?? 0);
});
test('test converting wav to flac', async () => {
const length = await page.evaluate(async () => {
const result = await ffmpeg
.input({ source: 'http://localhost:5173/samples/audio.wav' })
.ouput({ format: 'flac' })
.export();
return result?.length;
});
expect(length).toBeGreaterThan(0);
});
test('test converting mp4 into avi', async () => {
const length = await page.evaluate(async () => {
const result = await ffmpeg
.input({ source: 'http://localhost:5173/samples/video.mp4' })
.ouput({ format: 'avi' })
.export();
return result?.length;
});
expect(length).toBeGreaterThan(0);
});
test('test converting mp4 into gif', async () => {
const length = await page.evaluate(async () => {
const result = await ffmpeg
.input({ source: 'http://localhost:5173/samples/video.mp4' })
.ouput({ format: 'gif' })
.export();
return result?.length;
});
expect(length).toBeGreaterThan(0);
});
test('test adding wav audio track to mp4', async () => {
const length = await page.evaluate(async () => {
const result = await ffmpeg
.input({ source: 'http://localhost:5173/samples/video.mp4' })
.input({ source: 'http://localhost:5173/samples/audio.wav' })
.ouput({
format: 'mp4',
duration: 10,
video: { codec: 'copy' },
audio: { codec: 'aac' },
})
.export();
return result?.length;
});
expect(length).toBeGreaterThan(0);
});
});