-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze-track.js
81 lines (70 loc) · 2 KB
/
analyze-track.js
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
import * as Path from 'node:path';
import * as fs from 'node:fs';
import { parseArgs } from 'node:util';
//import equal from "fast-deep-equal";
import { analyzeTrack } from './src/analyze-track.js';
const args = parseArgs({
options: {
input: {
type: 'string',
short: 'i',
},
startTime: {
type: 'string',
short: 's',
},
},
});
const inputPath = args.values.input;
if (!inputPath || inputPath.length < 1) {
console.error('input is required (-i or --input)');
process.exit(1);
}
if (!fs.existsSync(inputPath)) {
console.error("input path doesn't exist: ", inputPath);
process.exit(1);
}
const opts = {
minGapDurationInSecs: 0.5,
};
let analysis = await analyzeTrack('analyze-run', inputPath, opts);
/*
// DEBUG: used this to verify that multiple calls to ffprobe will return the same result.
// there was a bug where this wasn't always the case, but it's fixed now.
if (1) {
let n = 1;
let maxRuns = 3;
do {
const ctxName = `analyze-run-${n + 1}`;
const run2 = await analyzeTrack(ctxName, inputPath);
if (equal(analysis, run2)) break;
console.warn(
"Warning: ffprobe analysis returned different result on %s",
ctxName
);
console.log("gaps: ", analysis.gaps, run2.gaps);
console.log(analysis);
console.log("-----");
console.log(run2);
analysis = run2;
} while (++n < maxRuns);
if (n >= maxRuns) {
throw new Error(`ffprobe output diverged after ${maxRuns} runs`);
}
}
*/
console.log(analysis);
if (args.values.startTime) {
const startTs = parseFloat(args.values.startTime);
if (!Number.isFinite(startTs)) {
throw new Error('invalid startTs: ', args.values.startTime);
}
const gapTimes = analysis.gaps.map((gap) => {
const { start, end } = gap;
const dur = end - start;
const gapStartTs = startTs + start * 1000;
const date = new Date(gapStartTs);
return ` ${date.toISOString()} - gap duration ${dur.toFixed(3)} s`;
});
console.log('Timestamps for gaps:\n\n', gapTimes.join('\n'));
}