-
Notifications
You must be signed in to change notification settings - Fork 4
/
events_test.ts
79 lines (68 loc) · 2.34 KB
/
events_test.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
import { assertInstanceOf } from "./_assertions.ts";
import {
assertEquals,
assertNotEquals,
dirname,
ensureDir,
fromFileUrl,
} from "./dev_deps.ts";
import {
EncodingEndEvent,
EncodingEvent,
EncodingInfoEvent,
EncodingStartEvent,
} from "./events.ts";
import { FFmpeg } from "./ffmpeg.ts";
const rootDir: string = dirname(fromFileUrl(import.meta.url));
const inputPath = `${rootDir}/fixtures/sample.mp4`;
function registerEventListener(encoder: FFmpeg): Array<EncodingEvent | Error> {
const events: Array<EncodingEvent | Error> = [];
encoder
.addEventListener("start", (event) => events.push(event))
.addEventListener("info", (event) => events.push(event))
.addEventListener("end", (event) => events.push(event))
.addEventListener("error", (event) => events.push(event));
return events;
}
Deno.test({
name: "encoding events",
async fn() {
const outputPath = `${rootDir}/.tmp/encoding events.mp4`;
await ensureDir(`${rootDir}/.tmp`);
const encoder = new FFmpeg()
.override(true)
.width(200)
.input(inputPath)
.output(outputPath);
const events = registerEventListener(encoder);
await encoder.encode();
const [
startEvent,
infoEvent,
endEvent,
errorEvent,
]: Array<EncodingEvent | Error> = events;
assertEquals(errorEvent, undefined);
assertInstanceOf(startEvent, EncodingStartEvent);
if (infoEvent instanceof EncodingInfoEvent) {
assertNotEquals(infoEvent.info, undefined);
assertNotEquals(infoEvent.info.format, undefined);
assertEquals(Array.isArray(infoEvent.info.streams), true);
assertEquals(infoEvent.info.streams.length > 0, true);
}
assertInstanceOf(infoEvent, EncodingInfoEvent);
if (infoEvent instanceof EncodingInfoEvent) {
assertNotEquals(infoEvent.info, undefined);
assertNotEquals(infoEvent.info.format, undefined);
assertEquals(Array.isArray(infoEvent.info.streams), true);
assertEquals(infoEvent.info.streams.length > 0, true);
}
assertInstanceOf(endEvent, EncodingEndEvent);
if (infoEvent instanceof EncodingInfoEvent) {
assertNotEquals(infoEvent.info, undefined);
assertNotEquals(infoEvent.info.format, undefined);
assertEquals(Array.isArray(infoEvent.info.streams), true);
assertEquals(infoEvent.info.streams.length > 0, true);
}
},
});