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/png.js
CHANGED
|
@@ -1,27 +1,10 @@
|
|
|
1
1
|
import zlib from 'node:zlib';
|
|
2
|
-
const CRC_TABLE = (() => {
|
|
3
|
-
const table = new Int32Array(256);
|
|
4
|
-
for (let n = 0; n < 256; n++) {
|
|
5
|
-
let c = n;
|
|
6
|
-
for (let k = 0; k < 8; k++)
|
|
7
|
-
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
8
|
-
table[n] = c;
|
|
9
|
-
}
|
|
10
|
-
return table;
|
|
11
|
-
})();
|
|
12
|
-
function crc32(buf) {
|
|
13
|
-
let crc = 0xffffffff;
|
|
14
|
-
for (let i = 0; i < buf.length; i++) {
|
|
15
|
-
crc = CRC_TABLE[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8);
|
|
16
|
-
}
|
|
17
|
-
return (crc ^ 0xffffffff) >>> 0;
|
|
18
|
-
}
|
|
19
2
|
function pngChunk(type, data) {
|
|
20
3
|
const len = Buffer.alloc(4);
|
|
21
4
|
len.writeUInt32BE(data.length);
|
|
22
5
|
const body = Buffer.concat([Buffer.from(type, 'ascii'), data]);
|
|
23
6
|
const crc = Buffer.alloc(4);
|
|
24
|
-
crc.writeUInt32BE(crc32(body));
|
|
7
|
+
crc.writeUInt32BE(zlib.crc32(body));
|
|
25
8
|
return Buffer.concat([len, body, crc]);
|
|
26
9
|
}
|
|
27
10
|
export function solidPng(hexColor, size = 256) {
|
package/dist/render.js
CHANGED
|
@@ -4,7 +4,6 @@ import { once } from 'node:events';
|
|
|
4
4
|
import { MIME } from './assets.js';
|
|
5
5
|
import { errorMessage } from './errors.js';
|
|
6
6
|
import { RENDERER_DIR, serveAsset } from './serve.js';
|
|
7
|
-
import { NOOP_TRACER, stage } from './tracing.js';
|
|
8
7
|
const PAGE_LOAD_TIMEOUT_MS = 60000;
|
|
9
8
|
const SCREENSHOT_TIMEOUT_MS = 60000;
|
|
10
9
|
function startServer({ html, style, tileCache, }) {
|
|
@@ -146,10 +145,8 @@ async function captureFrame(run, loop, page, idx) {
|
|
|
146
145
|
run.timing.evalMs += Date.now() - evalStart;
|
|
147
146
|
const captureStart = Date.now();
|
|
148
147
|
const buf = await page.screenshot(screenshotOptions(run.capture));
|
|
149
|
-
|
|
150
|
-
run.timing.captureMs += captureMs;
|
|
148
|
+
run.timing.captureMs += Date.now() - captureStart;
|
|
151
149
|
const done = ++loop.capturesDone;
|
|
152
|
-
run.batches.recordFrame(done, captureMs);
|
|
153
150
|
const emitStart = Date.now();
|
|
154
151
|
await run.stream.submit(idx, buf);
|
|
155
152
|
run.timing.emitMs += Date.now() - emitStart;
|
|
@@ -189,16 +186,13 @@ async function runWorkers(run, workerCount) {
|
|
|
189
186
|
throw e;
|
|
190
187
|
})));
|
|
191
188
|
const rejected = settled.find((r) => r.status === 'rejected');
|
|
192
|
-
run.batches.close(rejected?.reason);
|
|
193
|
-
run.captureSpan.setAttribute('render.frames.captured', loop.capturesDone);
|
|
194
189
|
if (rejected)
|
|
195
190
|
throw rejected.reason;
|
|
196
191
|
}
|
|
197
|
-
async function finishEncode(encoder, stream,
|
|
192
|
+
async function finishEncode(encoder, stream, log, outPath) {
|
|
198
193
|
await stream.flushReady();
|
|
199
194
|
stream.end();
|
|
200
195
|
const code = await encoder.closed;
|
|
201
|
-
encodeSpan.setAttribute('render.ffmpeg.exitCode', code ?? -1);
|
|
202
196
|
if (code !== 0) {
|
|
203
197
|
throw new Error(`ffmpeg exited with code ${code}: ${encoder.stderrText().trim()}`);
|
|
204
198
|
}
|
|
@@ -208,86 +202,29 @@ function formatProfile(profile, workerCount) {
|
|
|
208
202
|
return (`profile: eval=${(profile.evalMs / 1000).toFixed(1)}s capture=${(profile.captureMs / 1000).toFixed(1)}s ` +
|
|
209
203
|
`encode-backpressure=${(profile.emitMs / 1000).toFixed(1)}s (summed over ${workerCount} workers)`);
|
|
210
204
|
}
|
|
211
|
-
export class FrameBatchRecorder {
|
|
212
|
-
tracer;
|
|
213
|
-
parent;
|
|
214
|
-
frames;
|
|
215
|
-
cadence;
|
|
216
|
-
openSpan = null;
|
|
217
|
-
durations = [];
|
|
218
|
-
closed = false;
|
|
219
|
-
constructor(tracer, parent, frames, cadence = 100) {
|
|
220
|
-
this.tracer = tracer;
|
|
221
|
-
this.parent = parent;
|
|
222
|
-
this.frames = frames;
|
|
223
|
-
this.cadence = cadence;
|
|
224
|
-
}
|
|
225
|
-
recordFrame(capturedSoFar, captureMs) {
|
|
226
|
-
if (this.closed)
|
|
227
|
-
return;
|
|
228
|
-
this.openSpan ??= this.tracer.startSpan('render.capture.batch', {
|
|
229
|
-
parent: this.parent,
|
|
230
|
-
});
|
|
231
|
-
this.durations.push(captureMs);
|
|
232
|
-
const boundary = capturedSoFar % this.cadence === 0 || capturedSoFar === this.frames;
|
|
233
|
-
if (!boundary)
|
|
234
|
-
return;
|
|
235
|
-
const span = this.openSpan;
|
|
236
|
-
const durations = this.durations;
|
|
237
|
-
this.openSpan = null;
|
|
238
|
-
this.durations = [];
|
|
239
|
-
span.setAttribute('render.frames.captured', capturedSoFar);
|
|
240
|
-
span.setAttribute('render.frame.minMs', Math.min(...durations));
|
|
241
|
-
span.setAttribute('render.frame.avgMs', Math.round((durations.reduce((a, b) => a + b, 0) / durations.length) * 10) / 10);
|
|
242
|
-
span.setAttribute('render.frame.maxMs', Math.max(...durations));
|
|
243
|
-
span.end();
|
|
244
|
-
}
|
|
245
|
-
close(error) {
|
|
246
|
-
if (this.closed)
|
|
247
|
-
return;
|
|
248
|
-
this.closed = true;
|
|
249
|
-
if (this.openSpan === null)
|
|
250
|
-
return;
|
|
251
|
-
if (error !== undefined)
|
|
252
|
-
this.openSpan.fail(error);
|
|
253
|
-
this.openSpan.end();
|
|
254
|
-
this.openSpan = null;
|
|
255
|
-
this.durations = [];
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
205
|
async function captureAndEncode(active, env) {
|
|
259
|
-
const { ctx,
|
|
206
|
+
const { ctx, url, timing, workerCount } = env;
|
|
260
207
|
const { fpsStr, codec, quality, preset, outPath, signal, width, height, frames, frameStart, capture, log, onCapture, tools, } = ctx;
|
|
261
208
|
const encoder = spawnEncoder(tools.ffmpeg, fpsStr, { codec, quality, preset }, outPath);
|
|
262
209
|
const killOnAbort = () => encoder.kill();
|
|
263
210
|
signal?.addEventListener('abort', killOnAbort, { once: true });
|
|
264
211
|
const stream = new OrderedFrameStream(encoder);
|
|
265
212
|
try {
|
|
266
|
-
await
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
log,
|
|
282
|
-
onCapture,
|
|
283
|
-
stream,
|
|
284
|
-
batches: new FrameBatchRecorder(tracer, captureSpan, frames),
|
|
285
|
-
timing,
|
|
286
|
-
captureSpan,
|
|
287
|
-
}, workerCount);
|
|
288
|
-
});
|
|
289
|
-
await finishEncode(encoder, stream, encodeSpan, log, outPath);
|
|
290
|
-
});
|
|
213
|
+
await runWorkers({
|
|
214
|
+
active,
|
|
215
|
+
url,
|
|
216
|
+
width,
|
|
217
|
+
height,
|
|
218
|
+
frames,
|
|
219
|
+
frameStart,
|
|
220
|
+
capture,
|
|
221
|
+
signal,
|
|
222
|
+
log,
|
|
223
|
+
onCapture,
|
|
224
|
+
stream,
|
|
225
|
+
timing,
|
|
226
|
+
}, workerCount);
|
|
227
|
+
await finishEncode(encoder, stream, log, outPath);
|
|
291
228
|
}
|
|
292
229
|
catch (e) {
|
|
293
230
|
encoder.kill();
|
|
@@ -298,23 +235,17 @@ async function captureAndEncode(active, env) {
|
|
|
298
235
|
}
|
|
299
236
|
}
|
|
300
237
|
function reportProfile(env) {
|
|
301
|
-
const { ctx, timing,
|
|
238
|
+
const { ctx, timing, workerCount } = env;
|
|
302
239
|
const profile = {
|
|
303
240
|
evalMs: Math.round(timing.evalMs),
|
|
304
241
|
captureMs: Math.round(timing.captureMs),
|
|
305
242
|
emitMs: Math.round(timing.emitMs),
|
|
306
243
|
};
|
|
307
|
-
renderSpan.setAttributes({
|
|
308
|
-
'render.evalMs': profile.evalMs,
|
|
309
|
-
'render.captureMs': profile.captureMs,
|
|
310
|
-
'render.emitMs': profile.emitMs,
|
|
311
|
-
});
|
|
312
244
|
ctx.log(formatProfile(profile, workerCount));
|
|
313
245
|
return { profile };
|
|
314
246
|
}
|
|
315
247
|
export async function renderVideo(opts) {
|
|
316
|
-
const { html, style, tileCache, width, height, frames, fpsStr, workers, outPath, log = () => { }, browserPath = null, tools, capture = 'jpeg', codec = 'h264', quality = 'high', preset = 'medium', frameStart = 0, signal,
|
|
317
|
-
const tracer = trace?.tracer ?? NOOP_TRACER;
|
|
248
|
+
const { html, style, tileCache, width, height, frames, fpsStr, workers, outPath, log = () => { }, browserPath = null, tools, capture = 'jpeg', codec = 'h264', quality = 'high', preset = 'medium', frameStart = 0, signal, onCapture, } = opts;
|
|
318
249
|
const workerCount = Math.max(1, Math.min(workers, frames));
|
|
319
250
|
const ctx = {
|
|
320
251
|
width,
|
|
@@ -332,27 +263,19 @@ export async function renderVideo(opts) {
|
|
|
332
263
|
onCapture,
|
|
333
264
|
tools,
|
|
334
265
|
};
|
|
335
|
-
|
|
336
|
-
'render
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
await captureAndEncode(browser, env);
|
|
351
|
-
}
|
|
352
|
-
finally {
|
|
353
|
-
await browser?.close().catch(() => { });
|
|
354
|
-
server.close();
|
|
355
|
-
}
|
|
356
|
-
return reportProfile(env);
|
|
357
|
-
});
|
|
266
|
+
if (signal?.aborted)
|
|
267
|
+
throw new Error('render canceled');
|
|
268
|
+
const timing = { evalMs: 0, captureMs: 0, emitMs: 0 };
|
|
269
|
+
const { server, url } = await startServer({ html, style, tileCache });
|
|
270
|
+
const env = { ctx, url, timing, workerCount };
|
|
271
|
+
let browser = null;
|
|
272
|
+
try {
|
|
273
|
+
browser = await launchBrowser(log, browserPath);
|
|
274
|
+
await captureAndEncode(browser, env);
|
|
275
|
+
}
|
|
276
|
+
finally {
|
|
277
|
+
await browser?.close().catch(() => { });
|
|
278
|
+
server.close();
|
|
279
|
+
}
|
|
280
|
+
return reportProfile(env);
|
|
358
281
|
}
|
package/dist/run.js
CHANGED
|
@@ -6,14 +6,13 @@ import { resolveFfTools } from './fftools.js';
|
|
|
6
6
|
import { videoBaseName } from './inputs.js';
|
|
7
7
|
import { pathKey, uniquePath } from './paths.js';
|
|
8
8
|
import { loadTelemetry } from './telemetry.js';
|
|
9
|
-
import {
|
|
9
|
+
import { writeTelemetryDocument } from './telemetry-json.js';
|
|
10
10
|
import { prefetchTiles } from './tiles.js';
|
|
11
11
|
import { planIntroOutroFrames, planView } from './plan.js';
|
|
12
12
|
import { buildPageHtml, planPageOpts } from './page.js';
|
|
13
13
|
import { renderVideo } from './render.js';
|
|
14
|
-
import {
|
|
14
|
+
import { effectiveZoomOut, hasAltitude, resolveHudSpec, resolveRange, } from './config.js';
|
|
15
15
|
import { fixesLabel, noLockCuesLabel, telemetrySummary, trackDistanceLabel, } from './summary.js';
|
|
16
|
-
import { NOOP_TRACER, stage } from './tracing.js';
|
|
17
16
|
const PREPARE_STAGE_ORDER = ['probe', 'telemetry', 'plan'];
|
|
18
17
|
export function outputPathFor(videoPath, config) {
|
|
19
18
|
const base = videoBaseName(videoPath);
|
|
@@ -110,15 +109,6 @@ function resolveDeps(overrides, tileCache) {
|
|
|
110
109
|
outputMatchesSource: overrides?.outputMatchesSource ?? realDeps.outputMatchesSource,
|
|
111
110
|
};
|
|
112
111
|
}
|
|
113
|
-
export function resolveRange(range, frames) {
|
|
114
|
-
if (!range)
|
|
115
|
-
return null;
|
|
116
|
-
assertValidFrameRange(range);
|
|
117
|
-
if (range.end >= frames) {
|
|
118
|
-
throw new Error(`frame range ${range.start}-${range.end} is beyond the recording (${frames} frames)`);
|
|
119
|
-
}
|
|
120
|
-
return range;
|
|
121
|
-
}
|
|
122
112
|
function createPrepareReporter(onProgress = () => { }) {
|
|
123
113
|
return (stage) => onProgress({
|
|
124
114
|
stage,
|
|
@@ -127,9 +117,9 @@ function createPrepareReporter(onProgress = () => { }) {
|
|
|
127
117
|
});
|
|
128
118
|
}
|
|
129
119
|
async function probeStage(env) {
|
|
130
|
-
const { videoPath, config, log,
|
|
120
|
+
const { videoPath, config, log, deps, tools, report } = env;
|
|
131
121
|
report('probe');
|
|
132
|
-
const probe = await
|
|
122
|
+
const probe = await deps.probeVideo(tools, videoPath, log);
|
|
133
123
|
log(`source: ${path.basename(videoPath)} ${probe.width}x${probe.height} @ ${probe.fps.str} fps, ${probe.frames} frames`);
|
|
134
124
|
const introOutro = planIntroOutroFrames(config, {
|
|
135
125
|
fps: probe.fps.value,
|
|
@@ -141,22 +131,13 @@ async function probeStage(env) {
|
|
|
141
131
|
return { probe, introOutro };
|
|
142
132
|
}
|
|
143
133
|
async function telemetryStage(env, probe) {
|
|
144
|
-
const { videoPath, config, log,
|
|
134
|
+
const { videoPath, config, log, deps, tools, report } = env;
|
|
145
135
|
report('telemetry');
|
|
146
|
-
const loaded = await
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
tools,
|
|
152
|
-
});
|
|
153
|
-
span.setAttributes({
|
|
154
|
-
'telemetry.source': result.telemetry.source,
|
|
155
|
-
'telemetry.method': result.telemetry.method,
|
|
156
|
-
'telemetry.fix.count': result.telemetry.fixCount,
|
|
157
|
-
'telemetry.noLock.count': result.telemetry.noLock,
|
|
158
|
-
});
|
|
159
|
-
return result;
|
|
136
|
+
const loaded = await deps.loadTelemetry(videoPath, {
|
|
137
|
+
frames: probe.frames,
|
|
138
|
+
fpsValue: probe.fps.value,
|
|
139
|
+
durationSec: probe.durationSec,
|
|
140
|
+
tools,
|
|
160
141
|
});
|
|
161
142
|
const tel = loaded.telemetry;
|
|
162
143
|
const summary = telemetrySummary(tel);
|
|
@@ -173,34 +154,17 @@ async function telemetryStage(env, probe) {
|
|
|
173
154
|
};
|
|
174
155
|
}
|
|
175
156
|
async function viewPlanStage(env, tel) {
|
|
176
|
-
const { config, log,
|
|
157
|
+
const { config, log, report } = env;
|
|
177
158
|
report('plan');
|
|
178
|
-
const overview =
|
|
179
|
-
const computed = planView(tel.bbox, config.width, config.height, config);
|
|
180
|
-
span.setAttributes({
|
|
181
|
-
'plan.zoom': computed.zoom,
|
|
182
|
-
'plan.zoomOut': effectiveZoomOut(config),
|
|
183
|
-
'plan.tile.count': computed.tiles.length,
|
|
184
|
-
});
|
|
185
|
-
return computed;
|
|
186
|
-
});
|
|
159
|
+
const overview = planView(tel.bbox, config.width, config.height, config);
|
|
187
160
|
log(describeView(config, overview, config.style));
|
|
188
161
|
return overview;
|
|
189
162
|
}
|
|
190
|
-
async function tileWarmStage(deps, config, overview, log
|
|
191
|
-
const tileStats = await
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
log,
|
|
196
|
-
});
|
|
197
|
-
span.setAttributes({
|
|
198
|
-
'tiles.total': stats.total,
|
|
199
|
-
'tiles.downloaded': stats.downloaded,
|
|
200
|
-
'tiles.cached': stats.total - stats.downloaded - stats.failed,
|
|
201
|
-
'tiles.failed': stats.failed,
|
|
202
|
-
});
|
|
203
|
-
return stats;
|
|
163
|
+
async function tileWarmStage(deps, config, overview, log) {
|
|
164
|
+
const tileStats = await deps.prefetchTiles({
|
|
165
|
+
style: config.style,
|
|
166
|
+
tiles: overview.tiles,
|
|
167
|
+
log,
|
|
204
168
|
});
|
|
205
169
|
if (tileStats.downloaded) {
|
|
206
170
|
log(`tiles: ${tileStats.downloaded} downloaded, ${tileStats.failed} placeholders`);
|
|
@@ -212,8 +176,6 @@ export async function prepareSession(videoPath, config, log, options = {}) {
|
|
|
212
176
|
videoPath,
|
|
213
177
|
config,
|
|
214
178
|
log,
|
|
215
|
-
tracer: options.trace?.tracer ?? NOOP_TRACER,
|
|
216
|
-
parent: options.trace?.parent,
|
|
217
179
|
deps: resolveDeps(options.deps, config.tileCache),
|
|
218
180
|
tools: options.tools ?? resolveFfTools(config),
|
|
219
181
|
report: createPrepareReporter(options.onProgress),
|
|
@@ -286,27 +248,18 @@ function buildOkSummary(ctx, elapsedSec) {
|
|
|
286
248
|
};
|
|
287
249
|
}
|
|
288
250
|
async function verifyRenderedOutput(env) {
|
|
289
|
-
const { ctx, deps, tools
|
|
290
|
-
await
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
'verify.fps.expected': ctx.probe.fps.str,
|
|
296
|
-
'verify.fps.actual': verify.fps ?? 'unknown',
|
|
297
|
-
'verify.ok': verify.ok,
|
|
298
|
-
});
|
|
299
|
-
if (!verify.ok) {
|
|
300
|
-
throw new Error(`output verification failed: got ${verify.frames} frames @ ${verify.fps ?? 'unknown'}, ` +
|
|
301
|
-
`expected ${ctx.outFrames} @ ${ctx.probe.fps.str}`);
|
|
302
|
-
}
|
|
303
|
-
});
|
|
251
|
+
const { ctx, deps, tools } = env;
|
|
252
|
+
const verify = await deps.verifyOutput(tools, ctx.outPath, ctx.outFrames, ctx.probe.fps.value);
|
|
253
|
+
if (!verify.ok) {
|
|
254
|
+
throw new Error(`output verification failed: got ${verify.frames} frames @ ${verify.fps ?? 'unknown'}, ` +
|
|
255
|
+
`expected ${ctx.outFrames} @ ${ctx.probe.fps.str}`);
|
|
256
|
+
}
|
|
304
257
|
ctx.log(ctx.frameRange
|
|
305
258
|
? 'verified: frame count and frame rate are 1:1 within the exported range'
|
|
306
259
|
: 'verified: frame count and frame rate match the source');
|
|
307
260
|
}
|
|
308
261
|
async function renderToOutput(env) {
|
|
309
|
-
const { ctx, deps, tools, options
|
|
262
|
+
const { ctx, deps, tools, options } = env;
|
|
310
263
|
const html = buildPageHtml(recordingPageOpts(ctx, ctx.config));
|
|
311
264
|
fs.mkdirSync(path.dirname(ctx.outPath), { recursive: true });
|
|
312
265
|
await renderWithOutputCleanup(ctx.outPath, ctx.log, async () => {
|
|
@@ -329,7 +282,6 @@ async function renderToOutput(env) {
|
|
|
329
282
|
browserPath: ctx.config.browser,
|
|
330
283
|
signal: options.signal,
|
|
331
284
|
log: ctx.log,
|
|
332
|
-
trace: { tracer, parent: root },
|
|
333
285
|
onCapture: options.onCapture,
|
|
334
286
|
});
|
|
335
287
|
await verifyRenderedOutput(env);
|
|
@@ -347,55 +299,40 @@ export function telemetryExportInput(prep) {
|
|
|
347
299
|
};
|
|
348
300
|
}
|
|
349
301
|
function writeTelemetryExport(file, prep, log) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
302
|
+
// The document intentionally covers the whole recording: a frame range
|
|
303
|
+
// limits the render, never this export.
|
|
304
|
+
writeTelemetryDocument(file, telemetryExportInput(prep));
|
|
353
305
|
log(`telemetry JSON: wrote ${file}`);
|
|
354
306
|
}
|
|
355
307
|
export async function processRecording(videoPath, config, log, outPath = outputPathFor(videoPath, config), options = {}) {
|
|
356
308
|
const t0 = Date.now();
|
|
357
|
-
const tracer = options.trace?.tracer ?? NOOP_TRACER;
|
|
358
309
|
const deps = resolveDeps(options.deps, config.tileCache);
|
|
359
310
|
const tools = options.tools ?? resolveFfTools(config);
|
|
360
311
|
if (options.signal?.aborted)
|
|
361
312
|
throw new Error('render canceled');
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
...options,
|
|
367
|
-
deps,
|
|
368
|
-
tools,
|
|
369
|
-
trace: { tracer, parent: root },
|
|
370
|
-
});
|
|
371
|
-
root.setAttributes({
|
|
372
|
-
'canvas.width': prep.width,
|
|
373
|
-
'canvas.height': prep.height,
|
|
374
|
-
'map.style': config.style,
|
|
375
|
-
'map.view': config.view,
|
|
376
|
-
'source.frames': prep.probe.frames,
|
|
377
|
-
'source.fps': prep.probe.fps.value,
|
|
378
|
-
'telemetry.source': prep.tel.source,
|
|
379
|
-
});
|
|
380
|
-
if (config.telemetryJson) {
|
|
381
|
-
writeTelemetryExport(config.telemetryJson, prep, log);
|
|
382
|
-
}
|
|
383
|
-
const tileStats = await tileWarmStage(deps, config, prep.overview, log, tracer, root);
|
|
384
|
-
const range = resolveRange(options.range, prep.probe.frames);
|
|
385
|
-
const outFrames = range ? range.end - range.start + 1 : prep.probe.frames;
|
|
386
|
-
const ctx = {
|
|
387
|
-
...prep,
|
|
388
|
-
videoPath,
|
|
389
|
-
outPath,
|
|
390
|
-
config,
|
|
391
|
-
log,
|
|
392
|
-
outFrames,
|
|
393
|
-
frameRange: range,
|
|
394
|
-
tileStats,
|
|
395
|
-
};
|
|
396
|
-
await renderToOutput({ ctx, deps, tools, options, tracer, root });
|
|
397
|
-
return buildOkSummary(ctx, Math.round((Date.now() - t0) / 1000));
|
|
313
|
+
const prep = await prepareSession(videoPath, config, log, {
|
|
314
|
+
...options,
|
|
315
|
+
deps,
|
|
316
|
+
tools,
|
|
398
317
|
});
|
|
318
|
+
if (config.telemetryJson) {
|
|
319
|
+
writeTelemetryExport(config.telemetryJson, prep, log);
|
|
320
|
+
}
|
|
321
|
+
const tileStats = await tileWarmStage(deps, config, prep.overview, log);
|
|
322
|
+
const range = resolveRange(options.range, prep.probe.frames);
|
|
323
|
+
const outFrames = range ? range.end - range.start + 1 : prep.probe.frames;
|
|
324
|
+
const ctx = {
|
|
325
|
+
...prep,
|
|
326
|
+
videoPath,
|
|
327
|
+
outPath,
|
|
328
|
+
config,
|
|
329
|
+
log,
|
|
330
|
+
outFrames,
|
|
331
|
+
frameRange: range,
|
|
332
|
+
tileStats,
|
|
333
|
+
};
|
|
334
|
+
await renderToOutput({ ctx, deps, tools, options });
|
|
335
|
+
return buildOkSummary(ctx, Math.round((Date.now() - t0) / 1000));
|
|
399
336
|
}
|
|
400
337
|
export async function runBatch(videos, config, log, emit, options = {}) {
|
|
401
338
|
const result = { ok: 0, skipped: 0, failed: 0 };
|
package/dist/telemetry-json.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
1
3
|
import { z } from 'zod';
|
|
2
4
|
export const TELEMETRY_JSON_SCHEMA_VERSION = 1;
|
|
3
5
|
const GimbalDeviceSchema = z.strictObject({
|
|
@@ -37,36 +39,35 @@ export const TelemetryDocumentSchema = z.strictObject({
|
|
|
37
39
|
gimbalDevice: GimbalDeviceSchema.optional(),
|
|
38
40
|
frames: z.array(TelemetryRecordSchema),
|
|
39
41
|
});
|
|
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
|
-
]);
|
|
42
|
+
// The Record annotation makes a schema field without an entry here a compile
|
|
43
|
+
// error instead of a silently dropped record key.
|
|
44
|
+
const TELEMETRY_VALUES = {
|
|
45
|
+
gimbalDeviceTimestampMs: { position: 'before-heading', integer: true },
|
|
46
|
+
lat: { position: 'before-heading' },
|
|
47
|
+
lng: { position: 'before-heading' },
|
|
48
|
+
altAbs: { position: 'before-heading' },
|
|
49
|
+
altRel: { position: 'before-heading' },
|
|
50
|
+
gpsAltMm: { position: 'before-heading', integer: true },
|
|
51
|
+
pitchDeg: { position: 'before-heading' },
|
|
52
|
+
rollDeg: { position: 'before-heading' },
|
|
53
|
+
yawDeg: { position: 'before-heading' },
|
|
54
|
+
gimbalPitchDeg: { position: 'before-heading' },
|
|
55
|
+
gimbalRollDeg: { position: 'before-heading' },
|
|
56
|
+
gimbalYawDeg: { position: 'before-heading' },
|
|
57
|
+
iso: { position: 'exposure', integer: true },
|
|
58
|
+
shutterTime: { position: 'exposure' },
|
|
59
|
+
whiteBalanceCctK: { position: 'exposure', integer: true },
|
|
60
|
+
fNumber: { position: 'exposure' },
|
|
61
|
+
};
|
|
62
|
+
function valueKeys(position) {
|
|
63
|
+
return Object.keys(TELEMETRY_VALUES).filter((key) => TELEMETRY_VALUES[key].position === position);
|
|
64
|
+
}
|
|
65
|
+
const BEFORE_HEADING_KEYS = valueKeys('before-heading');
|
|
66
|
+
const EXPOSURE_KEYS = valueKeys('exposure');
|
|
66
67
|
function copyValue(record, key, value) {
|
|
67
68
|
if (value === null || value === undefined)
|
|
68
69
|
return;
|
|
69
|
-
record[key] =
|
|
70
|
+
record[key] = TELEMETRY_VALUES[key].integer ? Math.round(value) : value;
|
|
70
71
|
}
|
|
71
72
|
function buildRecord(input, index) {
|
|
72
73
|
const row = input.frames[index] ?? {};
|
|
@@ -102,6 +103,11 @@ export function buildTelemetryDocument(input) {
|
|
|
102
103
|
export function serializeTelemetryDocument(doc) {
|
|
103
104
|
return `${JSON.stringify(doc, null, 2)}\n`;
|
|
104
105
|
}
|
|
106
|
+
export function writeTelemetryDocument(file, input) {
|
|
107
|
+
const doc = buildTelemetryDocument(input);
|
|
108
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
109
|
+
fs.writeFileSync(file, serializeTelemetryDocument(doc));
|
|
110
|
+
}
|
|
105
111
|
export function generateTelemetryJsonSchema() {
|
|
106
112
|
return `${JSON.stringify(z.toJSONSchema(TelemetryDocumentSchema), null, 2)}\n`;
|
|
107
113
|
}
|
package/dist/telemetry-math.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { bearingDeg, circularMeanDeg, haversineM } from './geo.js';
|
|
2
|
+
import { timeAt } from './frametime.js';
|
|
2
3
|
const MAX_INTERPOLATION_GAP_S = 3;
|
|
3
4
|
const SPEED_SMOOTHING_SPAN = 5;
|
|
4
5
|
const HEADING_MIN_MOVE_M = 1.5;
|
|
@@ -214,7 +215,7 @@ function firstKnownHeading(rawHeading) {
|
|
|
214
215
|
function buildFrameData(samples, frames, fpsValue, speedBySample, headingBySample) {
|
|
215
216
|
const frameData = [];
|
|
216
217
|
for (let frame = 0; frame < frames; frame++) {
|
|
217
|
-
const t = frame
|
|
218
|
+
const t = timeAt(frame, fpsValue);
|
|
218
219
|
const pos = positionAt(samples, t);
|
|
219
220
|
const si = nearestSampleIndex(samples, t);
|
|
220
221
|
frameData.push({
|
package/dist/telemetry.js
CHANGED
|
@@ -33,6 +33,23 @@ function camSampleToFrameValues(sample) {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
async function loadSamples(tools, videoPath, durationSec) {
|
|
36
|
+
const cam = await parseCamMeta(tools, videoPath, durationSec, { keepAll: true });
|
|
37
|
+
if (cam) {
|
|
38
|
+
const fixSamples = cam.samples.filter((sample) => sample.fix !== null);
|
|
39
|
+
if (fixSamples.length === 0) {
|
|
40
|
+
throw new Error('no telemetry found: the CAM meta (DVTM) stream has no GPS fix pairs; ' +
|
|
41
|
+
'the .SRT sidecar is only consulted when no CAM meta stream is present');
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
samples: fixSamples,
|
|
45
|
+
source: 'cammeta',
|
|
46
|
+
method: cam.method,
|
|
47
|
+
noLock: cam.noLock,
|
|
48
|
+
frameValues: cam.method === 'dvtm-packets' ? cam.samples.map(camSampleToFrameValues) : [],
|
|
49
|
+
protoFile: cam.protoFile,
|
|
50
|
+
gimbalDevice: cam.gimbalDevice,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
36
53
|
const srtPath = findSrtSidecar(videoPath);
|
|
37
54
|
if (srtPath) {
|
|
38
55
|
const parsed = await parseSrt(srtPath);
|
|
@@ -54,20 +71,7 @@ async function loadSamples(tools, videoPath, durationSec) {
|
|
|
54
71
|
gimbalDevice: null,
|
|
55
72
|
};
|
|
56
73
|
}
|
|
57
|
-
|
|
58
|
-
const fixSamples = cam ? cam.samples.filter((sample) => sample.fix !== null) : [];
|
|
59
|
-
if (!cam || fixSamples.length === 0) {
|
|
60
|
-
throw new Error('no telemetry found: no .SRT sidecar and no GPS pairs in the CAM meta stream');
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
samples: fixSamples,
|
|
64
|
-
source: 'cammeta',
|
|
65
|
-
method: cam.method,
|
|
66
|
-
noLock: cam.noLock,
|
|
67
|
-
frameValues: cam.method === 'dvtm-packets' ? cam.samples.map(camSampleToFrameValues) : [],
|
|
68
|
-
protoFile: cam.protoFile,
|
|
69
|
-
gimbalDevice: cam.gimbalDevice,
|
|
70
|
-
};
|
|
74
|
+
throw new Error('no telemetry found: no CAM meta (DVTM) stream and no .SRT sidecar');
|
|
71
75
|
}
|
|
72
76
|
export async function loadTelemetry(videoPath, { frames, fpsValue, durationSec, tools, }) {
|
|
73
77
|
const loaded = await loadSamples(tools, videoPath, durationSec);
|