drone-path 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +3 -3
- package/THIRD-PARTY-NOTICES.md +7 -7
- package/app/ipc.mjs +178 -0
- package/app/main.mjs +4 -198
- package/dist/appsession.js +25 -59
- package/dist/appstate.js +22 -20
- package/dist/cammeta.js +4 -5
- package/dist/cli.js +3 -21
- package/dist/config.js +190 -129
- package/dist/ff.js +2 -19
- package/dist/frametime.js +32 -0
- package/dist/png.js +1 -18
- package/dist/render.js +35 -112
- package/dist/run.js +49 -112
- package/dist/telemetry-json.js +33 -27
- package/dist/telemetry-math.js +2 -1
- package/dist/telemetry.js +18 -14
- package/dist/tiles.js +30 -86
- package/package.json +7 -8
- package/dist/renderer/leaflet.js +0 -1
- package/dist/tracing.js +0 -184
package/dist/cli.js
CHANGED
|
@@ -8,13 +8,12 @@ import { collectRecordings } from './inputs.js';
|
|
|
8
8
|
import { requireTools } from './ff.js';
|
|
9
9
|
import { resolveFfTools } from './fftools.js';
|
|
10
10
|
import { runBatch } from './run.js';
|
|
11
|
-
import { createTracing } from './tracing.js';
|
|
12
11
|
export function buildProgram() {
|
|
13
12
|
const program = new Command();
|
|
14
13
|
program
|
|
15
14
|
.name('drone-path')
|
|
16
15
|
.description('Render flight-path map overlay videos from DJI drone recordings (telemetry ' +
|
|
17
|
-
'from the
|
|
16
|
+
'from the embedded CAM-meta stream or the .SRT sidecar) at exactly the source ' +
|
|
18
17
|
'frame rate and frame count.')
|
|
19
18
|
.version(VERSION)
|
|
20
19
|
.argument('<inputs...>', 'video files and/or folders (folders are scanned for *.mp4)');
|
|
@@ -86,7 +85,7 @@ function createLogger(config) {
|
|
|
86
85
|
process.stderr.write(`[drone-path] ${msg}\n`);
|
|
87
86
|
};
|
|
88
87
|
}
|
|
89
|
-
async function runPipeline(invocation,
|
|
88
|
+
async function runPipeline(invocation, log) {
|
|
90
89
|
const { inputs, config, configPath } = invocation;
|
|
91
90
|
const tools = resolveFfTools(config);
|
|
92
91
|
await requireTools(tools);
|
|
@@ -101,34 +100,17 @@ async function runPipeline(invocation, tracing, log) {
|
|
|
101
100
|
}
|
|
102
101
|
};
|
|
103
102
|
const result = await runBatch(videos, config, log, emit, {
|
|
104
|
-
trace: { tracer: tracing.tracer },
|
|
105
103
|
tools,
|
|
106
104
|
});
|
|
107
105
|
log(`done: ${result.ok} ok, ${result.skipped} skipped, ${result.failed} failed`);
|
|
108
106
|
if (result.failed > 0)
|
|
109
107
|
process.exitCode = 1;
|
|
110
108
|
}
|
|
111
|
-
async function withTracingShutdown(tracing, log, body) {
|
|
112
|
-
try {
|
|
113
|
-
await body();
|
|
114
|
-
}
|
|
115
|
-
finally {
|
|
116
|
-
try {
|
|
117
|
-
await tracing.shutdown();
|
|
118
|
-
}
|
|
119
|
-
catch (e) {
|
|
120
|
-
log(`warning: tracing shutdown failed: ${errorMessage(e)}`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
109
|
export async function main(argv = process.argv) {
|
|
125
110
|
try {
|
|
126
111
|
const invocation = resolveInvocation(argv);
|
|
127
112
|
const log = createLogger(invocation.config);
|
|
128
|
-
|
|
129
|
-
if (tracing.enabled)
|
|
130
|
-
log(`tracing: enabled (OTLP/HTTP protobuf)`);
|
|
131
|
-
await withTracingShutdown(tracing, log, () => runPipeline(invocation, tracing, log));
|
|
113
|
+
await runPipeline(invocation, log);
|
|
132
114
|
}
|
|
133
115
|
catch (e) {
|
|
134
116
|
if (isCommanderExit(e)) {
|
package/dist/config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
export const CONFIG_FILE_NAME = '.dronepath.json';
|
|
2
3
|
export const CONFIG_FILE_OPTION = {
|
|
3
4
|
flags: '--config <path>',
|
|
@@ -44,86 +45,112 @@ export function formatHud(hud) {
|
|
|
44
45
|
parts.push('speed');
|
|
45
46
|
return parts.length ? parts.join(',') : 'none';
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
const invalidValue = (name) => (issue) => `invalid value for ${name}: ${String(issue.input)}`;
|
|
49
|
+
const invalidNumber = (name) => (issue) => `invalid number for ${name}: ${String(issue.input)}`;
|
|
50
|
+
export function parseValue(schema, value) {
|
|
51
|
+
const result = schema.safeParse(value);
|
|
52
|
+
if (result.success)
|
|
53
|
+
return result.data;
|
|
54
|
+
// The legacy key loops ran before the value checks; surface an unknown-key
|
|
55
|
+
// issue first so multi-error input keeps reporting in that order.
|
|
56
|
+
const issue = result.error.issues.find((i) => i.code === 'unrecognized_keys') ??
|
|
57
|
+
result.error.issues[0];
|
|
58
|
+
throw new Error(issue.message, { cause: result.error });
|
|
52
59
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
export function strictShape(shape, wording) {
|
|
61
|
+
return z.strictObject(shape, {
|
|
62
|
+
error: (issue) => issue.code === 'unrecognized_keys'
|
|
63
|
+
? wording.unknownKey(issue.keys[0])
|
|
64
|
+
: wording.invalid,
|
|
65
|
+
});
|
|
58
66
|
}
|
|
59
|
-
function
|
|
60
|
-
|
|
61
|
-
throw new Error(`invalid value for ${name}: ${String(value)}`);
|
|
62
|
-
}
|
|
63
|
-
return value;
|
|
67
|
+
export function numberValue(name) {
|
|
68
|
+
return z.number({ error: invalidNumber(name) });
|
|
64
69
|
}
|
|
65
|
-
function
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return value;
|
|
70
|
+
function stringValue(name) {
|
|
71
|
+
return z
|
|
72
|
+
.string({ error: invalidValue(name) })
|
|
73
|
+
.min(1, { error: invalidValue(name) });
|
|
70
74
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
throw new Error(`invalid value for ${name}: ${String(value)} (use ${allowed.join(' | ')})`);
|
|
74
|
-
}
|
|
75
|
-
return value;
|
|
75
|
+
function boolValue(name) {
|
|
76
|
+
return z.boolean({ error: invalidValue(name) });
|
|
76
77
|
}
|
|
77
|
-
function
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
function enumValue(name, values) {
|
|
79
|
+
return z.enum(values, {
|
|
80
|
+
error: (issue) => `invalid value for ${name}: ${String(issue.input)} (use ${values.join(' | ')})`,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function nullableStringValue(name) {
|
|
84
|
+
return z
|
|
85
|
+
.nullable(z.string({ error: invalidValue(name) }))
|
|
86
|
+
.transform((value) => (value === '' ? null : value));
|
|
87
|
+
}
|
|
88
|
+
// The legacy key loops ran Object.keys on any object, arrays included;
|
|
89
|
+
// spreading keeps exactly those keys visible to the strict shapes below.
|
|
90
|
+
const keyedObjectInput = (value) => typeof value === 'object' && value !== null ? { ...value } : value;
|
|
91
|
+
// The whitespace tolerance matches the legacy trim-before-match so the error
|
|
92
|
+
// can echo the raw untrimmed input.
|
|
93
|
+
const TRAIL_COLOR_RX = /^\s*#?([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})\s*$/i;
|
|
94
|
+
function canonicalTrailColor(value) {
|
|
95
|
+
const hex = value.trim().replace(/^#/, '').toLowerCase();
|
|
96
|
+
return `#${hex.length <= 4 ? [...hex].map((c) => c + c).join('') : hex}`;
|
|
97
|
+
}
|
|
98
|
+
function trailColorValue(name) {
|
|
99
|
+
const bad = (issue) => `invalid value for ${name}: ${String(issue.input)} (use hex like #e63946 or #e63946cc)`;
|
|
100
|
+
return z
|
|
101
|
+
.union([z.null(), z.literal(''), z.string().regex(TRAIL_COLOR_RX, { error: bad })], { error: bad })
|
|
102
|
+
.transform((value) => value === null || value === '' ? null : canonicalTrailColor(value));
|
|
81
103
|
}
|
|
82
|
-
const TRAIL_COLOR_RX = /^#?([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
83
104
|
export function asTrailColor(value, name) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
105
|
+
return parseValue(trailColorValue(name), value);
|
|
106
|
+
}
|
|
107
|
+
function hudSpecSchema(name) {
|
|
108
|
+
return z.preprocess(keyedObjectInput, strictShape({
|
|
109
|
+
heading: boolValue(`${name}: heading`),
|
|
110
|
+
alt: boolValue(`${name}: alt`),
|
|
111
|
+
speed: boolValue(`${name}: speed`),
|
|
112
|
+
}, {
|
|
113
|
+
invalid: `invalid value for ${name}`,
|
|
114
|
+
unknownKey: (key) => `unknown key ${key} in ${name}`,
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
function patchHud(value, name) {
|
|
118
|
+
if (value === undefined || value === null)
|
|
119
|
+
return undefined;
|
|
120
|
+
return typeof value === 'string'
|
|
121
|
+
? parseHud(parseValue(stringValue(name), value))
|
|
122
|
+
: parseValue(hudSpecSchema(name), value);
|
|
96
123
|
}
|
|
97
124
|
export const CONFIG_OPTIONS = [
|
|
98
125
|
{
|
|
99
126
|
key: 'outDir',
|
|
100
127
|
cli: { flags: '--out-dir <dir>', help: 'output folder' },
|
|
101
128
|
default: 'out',
|
|
102
|
-
normalize: (v, name) => ({ outDir:
|
|
129
|
+
normalize: (v, name) => ({ outDir: parseValue(nullableStringValue(name), v) }),
|
|
103
130
|
},
|
|
104
131
|
{
|
|
105
132
|
key: 'outSuffix',
|
|
106
133
|
cli: { flags: '--out-suffix <suffix>', help: 'output name = <basename><suffix>.mp4' },
|
|
107
134
|
default: '_map',
|
|
108
|
-
normalize: (v, name) => ({ outSuffix:
|
|
135
|
+
normalize: (v, name) => ({ outSuffix: parseValue(stringValue(name), v) }),
|
|
109
136
|
},
|
|
110
137
|
{
|
|
111
138
|
key: 'width',
|
|
112
139
|
cli: { flags: '--width <px>', help: 'canvas width in pixels (rounded down to even)', parse: cliNumber },
|
|
113
140
|
default: 768,
|
|
114
|
-
normalize: (v, name) => ({ width:
|
|
141
|
+
normalize: (v, name) => ({ width: parseValue(numberValue(name), v) }),
|
|
115
142
|
},
|
|
116
143
|
{
|
|
117
144
|
key: 'height',
|
|
118
145
|
cli: { flags: '--height <px>', help: 'canvas height in pixels (rounded down to even)', parse: cliNumber },
|
|
119
146
|
default: 768,
|
|
120
|
-
normalize: (v, name) => ({ height:
|
|
147
|
+
normalize: (v, name) => ({ height: parseValue(numberValue(name), v) }),
|
|
121
148
|
},
|
|
122
149
|
{
|
|
123
150
|
key: 'style',
|
|
124
151
|
cli: { flags: '--style <name>', help: 'map look', choices: STYLE_VALUES },
|
|
125
152
|
default: 'satellite',
|
|
126
|
-
normalize: (v, name) => ({ style:
|
|
153
|
+
normalize: (v, name) => ({ style: parseValue(enumValue(name, STYLE_VALUES), v) }),
|
|
127
154
|
},
|
|
128
155
|
{
|
|
129
156
|
key: 'view',
|
|
@@ -133,31 +160,31 @@ export const CONFIG_OPTIONS = [
|
|
|
133
160
|
choices: VIEW_VALUES,
|
|
134
161
|
},
|
|
135
162
|
default: 'follow',
|
|
136
|
-
normalize: (v, name) => ({ view:
|
|
163
|
+
normalize: (v, name) => ({ view: parseValue(enumValue(name, VIEW_VALUES), v) }),
|
|
137
164
|
},
|
|
138
165
|
{
|
|
139
166
|
key: 'zoom',
|
|
140
167
|
cli: { flags: '--zoom <n>', help: 'fixed view zoom level (0 = auto-fit to the track)', parse: cliNumber },
|
|
141
168
|
default: 0,
|
|
142
|
-
normalize: (v, name) => ({ zoom:
|
|
169
|
+
normalize: (v, name) => ({ zoom: parseValue(numberValue(name), v) }),
|
|
143
170
|
},
|
|
144
171
|
{
|
|
145
172
|
key: 'zoomOut',
|
|
146
173
|
cli: { flags: '--zoom-out <n>', help: 'auto-fit only: pull back n zoom levels', parse: cliNumber },
|
|
147
174
|
default: 1,
|
|
148
|
-
normalize: (v, name) => ({ zoomOut:
|
|
175
|
+
normalize: (v, name) => ({ zoomOut: parseValue(numberValue(name), v) }),
|
|
149
176
|
},
|
|
150
177
|
{
|
|
151
178
|
key: 'introSec',
|
|
152
179
|
cli: { flags: '--intro-sec <s>', help: 'intro: zoom in from one level out over s seconds', parse: cliNumber },
|
|
153
180
|
default: 2,
|
|
154
|
-
normalize: (v, name) => ({ introSec:
|
|
181
|
+
normalize: (v, name) => ({ introSec: parseValue(numberValue(name), v) }),
|
|
155
182
|
},
|
|
156
183
|
{
|
|
157
184
|
key: 'outroSec',
|
|
158
185
|
cli: { flags: '--outro-sec <s>', help: 'outro: zoom back out over s seconds', parse: cliNumber },
|
|
159
186
|
default: 2,
|
|
160
|
-
normalize: (v, name) => ({ outroSec:
|
|
187
|
+
normalize: (v, name) => ({ outroSec: parseValue(numberValue(name), v) }),
|
|
161
188
|
},
|
|
162
189
|
{
|
|
163
190
|
key: 'trailColor',
|
|
@@ -175,61 +202,61 @@ export const CONFIG_OPTIONS = [
|
|
|
175
202
|
help: 'comma list of heading,alt,speed - or none (alt hides when unavailable)',
|
|
176
203
|
},
|
|
177
204
|
default: { heading: true, alt: false, speed: false },
|
|
178
|
-
normalize: (v, name) => ({ hud: parseHud(
|
|
205
|
+
normalize: (v, name) => ({ hud: parseHud(parseValue(stringValue(name), v)) }),
|
|
179
206
|
},
|
|
180
207
|
{
|
|
181
208
|
key: 'workers',
|
|
182
209
|
cli: { flags: '--workers <n>', help: 'parallel browser pages', parse: cliNumber },
|
|
183
210
|
default: 4,
|
|
184
|
-
normalize: (v, name) => ({ workers:
|
|
211
|
+
normalize: (v, name) => ({ workers: parseValue(numberValue(name), v) }),
|
|
185
212
|
},
|
|
186
213
|
{
|
|
187
214
|
key: 'capture',
|
|
188
215
|
cli: { flags: '--capture <mode>', help: 'frame capture mode (canvas is parked)', choices: CAPTURE_VALUES },
|
|
189
216
|
default: 'jpeg',
|
|
190
|
-
normalize: (v, name) => ({ capture:
|
|
217
|
+
normalize: (v, name) => ({ capture: parseValue(enumValue(name, CAPTURE_VALUES), v) }),
|
|
191
218
|
},
|
|
192
219
|
{
|
|
193
220
|
key: 'codec',
|
|
194
221
|
cli: { flags: '--codec <name>', help: 'video codec (mp4 container)', choices: CODEC_VALUES },
|
|
195
222
|
default: 'h264',
|
|
196
|
-
normalize: (v, name) => ({ codec:
|
|
223
|
+
normalize: (v, name) => ({ codec: parseValue(enumValue(name, CODEC_VALUES), v) }),
|
|
197
224
|
},
|
|
198
225
|
{
|
|
199
226
|
key: 'quality',
|
|
200
227
|
cli: { flags: '--quality <level>', help: 'encoding quality', choices: QUALITY_VALUES },
|
|
201
228
|
default: 'high',
|
|
202
|
-
normalize: (v, name) => ({ quality:
|
|
229
|
+
normalize: (v, name) => ({ quality: parseValue(enumValue(name, QUALITY_VALUES), v) }),
|
|
203
230
|
},
|
|
204
231
|
{
|
|
205
232
|
key: 'preset',
|
|
206
233
|
cli: { flags: '--preset <name>', help: 'encoding speed', choices: PRESET_VALUES },
|
|
207
234
|
default: 'medium',
|
|
208
|
-
normalize: (v, name) => ({ preset:
|
|
235
|
+
normalize: (v, name) => ({ preset: parseValue(enumValue(name, PRESET_VALUES), v) }),
|
|
209
236
|
},
|
|
210
237
|
{
|
|
211
238
|
key: 'tileCache',
|
|
212
239
|
cli: { flags: '--tile-cache <dir>', help: 'tile cache directory (default: per-user cache dir)' },
|
|
213
240
|
default: '',
|
|
214
|
-
normalize: (v, name) => ({ tileCache:
|
|
241
|
+
normalize: (v, name) => ({ tileCache: parseValue(stringValue(name), v) }),
|
|
215
242
|
},
|
|
216
243
|
{
|
|
217
244
|
key: 'browser',
|
|
218
245
|
cli: { flags: '--browser <path>', help: 'Chromium/Chrome/Edge executable (default: system Chrome/Edge)' },
|
|
219
246
|
default: null,
|
|
220
|
-
normalize: (v, name) => ({ browser:
|
|
247
|
+
normalize: (v, name) => ({ browser: parseValue(nullableStringValue(name), v) }),
|
|
221
248
|
},
|
|
222
249
|
{
|
|
223
250
|
key: 'ffmpeg',
|
|
224
251
|
cli: { flags: '--ffmpeg <path>', help: 'ffmpeg executable (default: embedded binary, then PATH)' },
|
|
225
252
|
default: null,
|
|
226
|
-
normalize: (v, name) => ({ ffmpeg:
|
|
253
|
+
normalize: (v, name) => ({ ffmpeg: parseValue(nullableStringValue(name), v) }),
|
|
227
254
|
},
|
|
228
255
|
{
|
|
229
256
|
key: 'ffprobe',
|
|
230
257
|
cli: { flags: '--ffprobe <path>', help: 'ffprobe executable (default: embedded binary, then PATH)' },
|
|
231
258
|
default: null,
|
|
232
|
-
normalize: (v, name) => ({ ffprobe:
|
|
259
|
+
normalize: (v, name) => ({ ffprobe: parseValue(nullableStringValue(name), v) }),
|
|
233
260
|
},
|
|
234
261
|
{
|
|
235
262
|
key: 'skipExisting',
|
|
@@ -238,13 +265,13 @@ export const CONFIG_OPTIONS = [
|
|
|
238
265
|
help: 'skip recordings whose output already exists and matches the source',
|
|
239
266
|
},
|
|
240
267
|
default: false,
|
|
241
|
-
normalize: (v, name) => ({ skipExisting:
|
|
268
|
+
normalize: (v, name) => ({ skipExisting: parseValue(boolValue(name), v) }),
|
|
242
269
|
},
|
|
243
270
|
{
|
|
244
271
|
key: 'recurse',
|
|
245
272
|
cli: { flags: '--recurse', help: 'scan input folders recursively' },
|
|
246
273
|
default: false,
|
|
247
|
-
normalize: (v, name) => ({ recurse:
|
|
274
|
+
normalize: (v, name) => ({ recurse: parseValue(boolValue(name), v) }),
|
|
248
275
|
},
|
|
249
276
|
{
|
|
250
277
|
key: 'telemetryJson',
|
|
@@ -253,21 +280,27 @@ export const CONFIG_OPTIONS = [
|
|
|
253
280
|
help: 'write one JSON document with per-frame telemetry to <file> (one recording per run)',
|
|
254
281
|
},
|
|
255
282
|
default: null,
|
|
256
|
-
normalize: (v, name) => ({ telemetryJson:
|
|
283
|
+
normalize: (v, name) => ({ telemetryJson: parseValue(nullableStringValue(name), v) }),
|
|
257
284
|
},
|
|
258
285
|
{
|
|
259
286
|
key: 'json',
|
|
260
287
|
cli: { flags: '--json', help: 'print one NDJSON summary line per recording on stdout' },
|
|
261
288
|
default: false,
|
|
262
|
-
normalize: (v, name) => ({ json:
|
|
289
|
+
normalize: (v, name) => ({ json: parseValue(boolValue(name), v) }),
|
|
263
290
|
},
|
|
264
291
|
{
|
|
265
292
|
key: 'quiet',
|
|
266
293
|
cli: { flags: '-q, --quiet', help: 'suppress progress output' },
|
|
267
294
|
default: false,
|
|
268
|
-
normalize: (v, name) => ({ quiet:
|
|
295
|
+
normalize: (v, name) => ({ quiet: parseValue(boolValue(name), v) }),
|
|
269
296
|
},
|
|
270
297
|
];
|
|
298
|
+
const CLI_NUMBER_RX = /^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;
|
|
299
|
+
function cliNumber(raw) {
|
|
300
|
+
if (typeof raw !== 'string' || !CLI_NUMBER_RX.test(raw.trim()))
|
|
301
|
+
return raw;
|
|
302
|
+
return Number(raw);
|
|
303
|
+
}
|
|
271
304
|
export function cliDefaultOf(key) {
|
|
272
305
|
const row = CONFIG_OPTIONS.find((r) => r.key === key);
|
|
273
306
|
if (!row)
|
|
@@ -282,14 +315,15 @@ export function cliDefaultOf(key) {
|
|
|
282
315
|
export const DEFAULT_CONFIG = Object.freeze(Object.fromEntries(CONFIG_OPTIONS.map((row) => [row.key, row.default])));
|
|
283
316
|
Object.freeze(DEFAULT_CONFIG.hud);
|
|
284
317
|
const OVERRIDE_NORMALIZERS = Object.fromEntries(CONFIG_OPTIONS.map((row) => [row.key, row.normalize]));
|
|
318
|
+
const OVERRIDE_SHAPE = Object.fromEntries(CONFIG_OPTIONS.map((row) => [row.key, z.unknown().optional()]));
|
|
285
319
|
export function normalizeOverrides(raw, origin) {
|
|
320
|
+
parseValue(strictShape(OVERRIDE_SHAPE, {
|
|
321
|
+
invalid: `invalid config overrides in ${origin}`,
|
|
322
|
+
unknownKey: (key) => `unknown config key ${key} in ${origin}`,
|
|
323
|
+
}), raw);
|
|
286
324
|
const out = {};
|
|
287
325
|
for (const key of Object.keys(raw)) {
|
|
288
|
-
const normalize =
|
|
289
|
-
? OVERRIDE_NORMALIZERS[key]
|
|
290
|
-
: null;
|
|
291
|
-
if (!normalize)
|
|
292
|
-
throw new Error(`unknown config key ${key} in ${origin}`);
|
|
326
|
+
const normalize = OVERRIDE_NORMALIZERS[key];
|
|
293
327
|
const value = raw[key];
|
|
294
328
|
if (value === undefined)
|
|
295
329
|
continue;
|
|
@@ -330,20 +364,18 @@ export const SETTINGS_KEYS = [
|
|
|
330
364
|
'quality',
|
|
331
365
|
'preset',
|
|
332
366
|
];
|
|
367
|
+
const SETTINGS_SHAPE = Object.fromEntries(SETTINGS_KEYS.map((key) => [key, z.unknown().optional()]));
|
|
333
368
|
export function parseSettingsPatch(raw, origin) {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
369
|
+
parseValue(strictShape(SETTINGS_SHAPE, {
|
|
370
|
+
invalid: `invalid settings in ${origin}`,
|
|
371
|
+
unknownKey: (key) => `unknown settings key ${key} in ${origin}`,
|
|
372
|
+
}), raw);
|
|
337
373
|
const flat = { ...raw };
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
if (flat.hud !== undefined && flat.hud !== null && typeof flat.hud !== 'string') {
|
|
344
|
-
flat.hud = formatHud(parseHudObject(flat.hud, `${origin}: hud`));
|
|
345
|
-
}
|
|
346
|
-
const patch = normalizeOverrides(flat, origin);
|
|
374
|
+
const hud = patchHud(flat.hud, `${origin}: hud`);
|
|
375
|
+
delete flat.hud;
|
|
376
|
+
const patch = { ...normalizeOverrides(flat, origin) };
|
|
377
|
+
if (hud !== undefined)
|
|
378
|
+
patch.hud = hud;
|
|
347
379
|
for (const key of SETTINGS_KEYS) {
|
|
348
380
|
if (patch[key] === undefined) {
|
|
349
381
|
throw new Error(`missing settings key ${key} in ${origin}`);
|
|
@@ -353,6 +385,42 @@ export function parseSettingsPatch(raw, origin) {
|
|
|
353
385
|
validateRenderConfig({ ...DEFAULT_CONFIG, ...settings, hud: { ...settings.hud } });
|
|
354
386
|
return settings;
|
|
355
387
|
}
|
|
388
|
+
// The pick-request flavor of look settings: its error wording is the legacy
|
|
389
|
+
// IPC wording, deliberately distinct from validateRenderConfig's CLI wording.
|
|
390
|
+
export function parseLookSettings(raw) {
|
|
391
|
+
const look = typeof raw === 'object' && raw !== null ? raw : {};
|
|
392
|
+
const { style, view, hud } = look;
|
|
393
|
+
const mapStyle = parseValue(z.enum(STYLE_VALUES, {
|
|
394
|
+
error: (issue) => `unknown map style: ${String(issue.input)}`,
|
|
395
|
+
}), style);
|
|
396
|
+
const viewMode = parseValue(z.enum(VIEW_VALUES, {
|
|
397
|
+
error: (issue) => `unknown view: ${String(issue.input)}`,
|
|
398
|
+
}), view);
|
|
399
|
+
const zoom = parseValue(numberValue('zoom'), look.zoom);
|
|
400
|
+
const zoomOut = parseValue(numberValue('zoom-out'), look.zoomOut);
|
|
401
|
+
if (!(zoom >= 0))
|
|
402
|
+
throw new Error('zoom must be >= 0 (0 = auto-fit)');
|
|
403
|
+
if (!(zoomOut >= 0))
|
|
404
|
+
throw new Error('zoom-out must be >= 0');
|
|
405
|
+
const introSec = parseValue(numberValue('intro'), look.introSec);
|
|
406
|
+
const outroSec = parseValue(numberValue('outro'), look.outroSec);
|
|
407
|
+
if (!(introSec >= 0))
|
|
408
|
+
throw new Error('intro must be 0 or more');
|
|
409
|
+
if (!(outroSec >= 0))
|
|
410
|
+
throw new Error('outro must be 0 or more');
|
|
411
|
+
const trailColor = asTrailColor(look.trailColor ?? null, 'trail color');
|
|
412
|
+
const chips = typeof hud === 'object' && hud !== null ? hud : {};
|
|
413
|
+
return {
|
|
414
|
+
style: mapStyle,
|
|
415
|
+
view: viewMode,
|
|
416
|
+
zoom,
|
|
417
|
+
zoomOut,
|
|
418
|
+
hud: { heading: !!chips.heading, alt: !!chips.alt, speed: !!chips.speed },
|
|
419
|
+
introSec,
|
|
420
|
+
outroSec,
|
|
421
|
+
trailColor,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
356
424
|
export const MIN_DIMENSION = 64;
|
|
357
425
|
// Negated comparisons are NaN-safe (NaN would slip through <).
|
|
358
426
|
export function validateDimensions(width, height) {
|
|
@@ -390,35 +458,24 @@ export function assertValidFrameRange(range, name = 'frame range') {
|
|
|
390
458
|
}
|
|
391
459
|
}
|
|
392
460
|
export function parseFrameRange(raw, name = 'frame range') {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
const start = asNumber(r.start, `${name}: start`);
|
|
403
|
-
const end = asNumber(r.end, `${name}: end`);
|
|
404
|
-
assertValidFrameRange({ start, end }, name);
|
|
405
|
-
return { start, end };
|
|
461
|
+
const range = parseValue(strictShape({
|
|
462
|
+
start: numberValue(`${name}: start`),
|
|
463
|
+
end: numberValue(`${name}: end`),
|
|
464
|
+
}, {
|
|
465
|
+
invalid: `invalid ${name}`,
|
|
466
|
+
unknownKey: (key) => `unknown ${name} key ${key}`,
|
|
467
|
+
}), raw);
|
|
468
|
+
assertValidFrameRange(range, name);
|
|
469
|
+
return range;
|
|
406
470
|
}
|
|
407
|
-
function
|
|
408
|
-
if (
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
if (key !== 'heading' && key !== 'alt' && key !== 'speed') {
|
|
414
|
-
throw new Error(`unknown key ${key} in ${name}`);
|
|
415
|
-
}
|
|
471
|
+
export function resolveRange(range, frames) {
|
|
472
|
+
if (!range)
|
|
473
|
+
return null;
|
|
474
|
+
assertValidFrameRange(range);
|
|
475
|
+
if (range.end >= frames) {
|
|
476
|
+
throw new Error(`frame range ${range.start}-${range.end} is beyond the recording (${frames} frames)`);
|
|
416
477
|
}
|
|
417
|
-
return
|
|
418
|
-
heading: asBool(h.heading, `${name}: heading`),
|
|
419
|
-
alt: asBool(h.alt, `${name}: alt`),
|
|
420
|
-
speed: asBool(h.speed, `${name}: speed`),
|
|
421
|
-
};
|
|
478
|
+
return range;
|
|
422
479
|
}
|
|
423
480
|
const MAIN_OWNED_KEYS = [
|
|
424
481
|
'outDir', 'outSuffix', 'tileCache', 'browser', 'ffmpeg', 'ffprobe', 'workers', 'capture',
|
|
@@ -431,27 +488,31 @@ function parseRequestConfig(raw, base) {
|
|
|
431
488
|
const flat = { ...raw };
|
|
432
489
|
for (const key of MAIN_OWNED_KEYS)
|
|
433
490
|
delete flat[key];
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
491
|
+
const { hud, ...rest } = flat;
|
|
492
|
+
const hudSpec = hud === undefined || hud === null
|
|
493
|
+
? undefined
|
|
494
|
+
: parseValue(hudSpecSchema('export request: config: hud'), hud);
|
|
495
|
+
const config = { ...base, ...normalizeOverrides(rest, 'export request: config') };
|
|
496
|
+
const merged = hudSpec === undefined ? config : { ...config, hud: hudSpec };
|
|
497
|
+
validateRenderConfig(merged);
|
|
498
|
+
return { ...merged, ...normalizeDimensions(merged.width, merged.height) };
|
|
440
499
|
}
|
|
500
|
+
const EXPORT_REQUEST_SCHEMA = z.preprocess(keyedObjectInput, strictShape({
|
|
501
|
+
outPath: z.unknown().optional(),
|
|
502
|
+
config: z.unknown().optional(),
|
|
503
|
+
range: z.unknown().optional(),
|
|
504
|
+
}, {
|
|
505
|
+
invalid: 'invalid export request',
|
|
506
|
+
unknownKey: (key) => `unknown export request key ${key}`,
|
|
507
|
+
}));
|
|
441
508
|
export function parseExportRequest(raw, base) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
const r = raw;
|
|
446
|
-
for (const key of Object.keys(r)) {
|
|
447
|
-
if (key !== 'outPath' && key !== 'config' && key !== 'range') {
|
|
448
|
-
throw new Error(`unknown export request key ${key}`);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
const outPath = asString(r.outPath, 'export request: outPath');
|
|
509
|
+
const request = parseValue(EXPORT_REQUEST_SCHEMA, raw);
|
|
510
|
+
const outPath = parseValue(stringValue('export request: outPath'), request.outPath);
|
|
452
511
|
if (!outPath.toLowerCase().endsWith('.mp4')) {
|
|
453
512
|
throw new Error(`export request: outPath must be an .mp4 file: ${outPath}`);
|
|
454
513
|
}
|
|
455
|
-
const range =
|
|
456
|
-
|
|
514
|
+
const range = request.range === undefined || request.range === null
|
|
515
|
+
? null
|
|
516
|
+
: parseFrameRange(request.range);
|
|
517
|
+
return { outPath, config: parseRequestConfig(request.config, base), range };
|
|
457
518
|
}
|
package/dist/ff.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
|
+
import { framesForSeconds, parseFpsRate, parseRate } from './frametime.js';
|
|
3
4
|
const execFileAsync = promisify(execFile);
|
|
4
5
|
const INSTALL_HINT = 'point --ffmpeg/--ffprobe at your executables, or install ffmpeg (includes ' +
|
|
5
6
|
'ffprobe) and make sure both are on PATH, e.g. "winget install Gyan.FFmpeg" ' +
|
|
@@ -20,24 +21,6 @@ export async function ffprobeJson(tools, videoPath, args) {
|
|
|
20
21
|
const { stdout } = await execFileAsync(tools.ffprobe, ['-v', 'error', ...args, videoPath], { maxBuffer: FFPROBE_MAX_BUFFER });
|
|
21
22
|
return JSON.parse(stdout || '{}');
|
|
22
23
|
}
|
|
23
|
-
function parseRate(str) {
|
|
24
|
-
const [num, den] = str.split('/').map(Number);
|
|
25
|
-
return Number.isFinite(num) ? { num, den } : null;
|
|
26
|
-
}
|
|
27
|
-
function parseFpsRate(str) {
|
|
28
|
-
const rate = str ? parseRate(str) : null;
|
|
29
|
-
if (!rate || !Number.isFinite(rate.den) || rate.den === 0 || rate.num === 0) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
const { num } = rate;
|
|
33
|
-
const den = rate.den;
|
|
34
|
-
return {
|
|
35
|
-
num,
|
|
36
|
-
den,
|
|
37
|
-
value: num / den,
|
|
38
|
-
str: den === 1 ? String(num) : `${num}/${den}`,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
24
|
function parseCount(text) {
|
|
42
25
|
return Number.parseInt(text ?? '', 10);
|
|
43
26
|
}
|
|
@@ -60,7 +43,7 @@ export async function probeVideo(tools, videoPath, log = () => { }) {
|
|
|
60
43
|
const durationSec = Number.parseFloat(format.duration ?? '');
|
|
61
44
|
let frames = parseCount(stream.nb_frames);
|
|
62
45
|
if (!Number.isFinite(frames) || frames <= 0) {
|
|
63
|
-
frames =
|
|
46
|
+
frames = framesForSeconds(fps.value, durationSec);
|
|
64
47
|
log('warning: nb_frames missing, using duration x fps');
|
|
65
48
|
}
|
|
66
49
|
if (!Number.isFinite(frames) || frames <= 0) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function parseRate(str) {
|
|
2
|
+
const [num, den] = str.split('/').map(Number);
|
|
3
|
+
return Number.isFinite(num) ? { num, den } : null;
|
|
4
|
+
}
|
|
5
|
+
export function parseFpsRate(str) {
|
|
6
|
+
const rate = str ? parseRate(str) : null;
|
|
7
|
+
if (!rate || !Number.isFinite(rate.den) || rate.den === 0 || rate.num === 0) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const { num } = rate;
|
|
11
|
+
const den = rate.den;
|
|
12
|
+
return {
|
|
13
|
+
num,
|
|
14
|
+
den,
|
|
15
|
+
value: num / den,
|
|
16
|
+
str: den === 1 ? String(num) : `${num}/${den}`,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function formatFps(rate) {
|
|
20
|
+
const ratio = /^(\d+)\/(\d+)$/.exec(rate);
|
|
21
|
+
const num = ratio ? Number(ratio[1]) : Number(rate);
|
|
22
|
+
const den = ratio ? Number(ratio[2]) : 1;
|
|
23
|
+
if (!(num > 0) || !(den > 0))
|
|
24
|
+
return rate;
|
|
25
|
+
return `${Math.round((num / den) * 100) / 100} fps`;
|
|
26
|
+
}
|
|
27
|
+
export function timeAt(frame, fps) {
|
|
28
|
+
return fps > 0 ? frame / fps : 0;
|
|
29
|
+
}
|
|
30
|
+
export function framesForSeconds(fps, seconds) {
|
|
31
|
+
return Math.round(fps * seconds);
|
|
32
|
+
}
|