-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-manifest.zx.mjs
62 lines (51 loc) · 1.51 KB
/
gen-manifest.zx.mjs
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
#!/usr/bin/env zx
import 'zx/globals';
const rawTracksDir = argv['input-raw-tracks-dir'] ?? argv['i'];
const manifest = {
recordingStartTs: -1,
participants: [],
};
for (const file of fs.readdirSync(rawTracksDir)) {
const ext = path.extname(file);
if (ext !== '.webm') continue;
const re = /^(?:.+\/)*(\d+)-(.{36})-(.*)-(\d+)\.(\w+)/;
const match = file.match(re);
if (!match) {
console.error(`Filename doesn't match expected pattern: ${file}`);
continue;
}
const recStartTs = parseInt(match[1], 10);
const uuid = match[2];
const mediaType = match[3];
const trackStartTs = parseInt(match[4], 10);
const startOffsetSecs = (trackStartTs - recStartTs) / 1000;
console.log(
`rec ${recStartTs} : uuid ${uuid}, mediaType ${mediaType}, ts ${startOffsetSecs}`
);
if (
manifest.recordingStartTs >= 0 &&
recStartTs !== manifest.recordingStartTs
) {
console.error(
`Will ignore file belonging to other recording: got ${recStartTs}, expected ${manifest.recordingStartTs} based on other files in dir`
);
continue;
}
manifest.recordingStartTs = recStartTs;
let p = manifest.participants.find((p) => p.id === uuid);
if (!p) {
p = { id: uuid, tracks: [] };
manifest.participants.push(p);
}
p.tracks.push({
file,
mediaType,
startTs: trackStartTs,
startOffsetSecs,
});
}
const outFile = path.resolve(
rawTracksDir,
`raw-tracks-manifest-${manifest.recordingStartTs}.json`
);
fs.writeFileSync(outFile, JSON.stringify(manifest, null, 2) + '\n');