drone-path 0.8.1 → 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 +43 -0
- package/README.md +18 -25
- package/THIRD-PARTY-NOTICES.md +14 -7
- package/app/ipc.mjs +178 -0
- package/app/main.mjs +10 -150
- package/app/preload.cjs +3 -0
- package/dist/appassets.js +2 -11
- package/dist/apppaths.js +2 -10
- package/dist/appsession.js +59 -59
- package/dist/appstate.js +22 -38
- package/dist/assets.js +0 -7
- package/dist/buildinfo.js +71 -0
- package/dist/cammeta.js +127 -89
- package/dist/changeset-gate.js +0 -7
- package/dist/cli.js +3 -36
- package/dist/config.js +216 -167
- package/dist/configfile.js +0 -8
- package/dist/decimate.js +2 -12
- package/dist/exportjob.js +3 -19
- package/dist/ff.js +2 -27
- package/dist/fftools.js +0 -10
- package/dist/frametime.js +32 -0
- package/dist/geo.js +3 -13
- package/dist/inputs.js +0 -4
- package/dist/manual/anchors.js +1 -7
- package/dist/manual/build.js +0 -6
- package/dist/manual/cliref.js +0 -6
- package/dist/manual/links.js +0 -17
- package/dist/manual/markdown.js +2 -10
- package/dist/manual/model.js +0 -3
- package/dist/manual/module.js +0 -3
- package/dist/manual/nav.js +0 -2
- package/dist/manual/reference.js +1 -4
- package/dist/page.js +3 -26
- package/dist/paths.js +0 -12
- package/dist/plan.js +1 -18
- package/dist/png.js +1 -21
- package/dist/proto.js +4 -4
- package/dist/range.js +0 -8
- package/dist/render.js +38 -165
- package/dist/renderer/dom.js +0 -6
- package/dist/renderer/framemath.js +0 -4
- package/dist/renderer/scene.js +10 -34
- package/dist/renderer/theme.js +58 -10
- package/dist/renderer/tilesources.js +0 -10
- package/dist/renderer/trail.js +1 -12
- package/dist/restyle.js +1 -9
- package/dist/run.js +79 -143
- package/dist/serve.js +0 -13
- package/dist/srt.js +30 -8
- package/dist/summary.js +0 -3
- package/dist/telemetry-json-schema.js +23 -0
- package/dist/telemetry-json.js +113 -0
- package/dist/telemetry-math.js +11 -46
- package/dist/telemetry.js +58 -11
- package/dist/tilecache.js +0 -5
- package/dist/tiles.js +31 -117
- package/package.json +15 -13
- package/dist/renderer/leaflet.js +0 -5
- package/dist/tracing.js +0 -208
package/dist/renderer/trail.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
// Trail growth state machine shared by the headless renderer and the app: at
|
|
2
|
-
// frame i the trail is the flown path so far - the decimated prefix before i
|
|
3
|
-
// plus the live tip at the frame's own position. The tip tracks the drone so
|
|
4
|
-
// the trail grows every frame (a prefix of decimated points alone stays empty
|
|
5
|
-
// for whole flights whenever the geometry collapses, #95), while the kept
|
|
6
|
-
// prefix stays bounded by the decimation budget. A changed frame pushes one
|
|
7
|
-
// setLatLngs per layer; repeated frames and empty tracks stay quiet.
|
|
8
|
-
// Largest k with trailFrame[k] <= i (trailFrame is strictly increasing):
|
|
9
|
-
// the textbook upper bound stepped back one; -1 when every point is later.
|
|
10
1
|
export function lastIndexAtOrBefore(trailFrame, i) {
|
|
11
2
|
let lo = 0;
|
|
12
3
|
let hi = trailFrame.length - 1;
|
|
@@ -31,8 +22,7 @@ export function createTrailController(trail, frames, layers) {
|
|
|
31
22
|
if (i === lastFrame)
|
|
32
23
|
return;
|
|
33
24
|
const tip = i >= 0 && i < frames.lat.length ? [frames.lat[i], frames.lon[i]] : null;
|
|
34
|
-
//
|
|
35
|
-
// exactly frame i would only duplicate it.
|
|
25
|
+
// A kept point at exactly frame i would duplicate the tip's position.
|
|
36
26
|
let end = lastIndexAtOrBefore(trail.frame, i);
|
|
37
27
|
if (tip !== null && trail.frame[end] === i)
|
|
38
28
|
end -= 1;
|
|
@@ -42,7 +32,6 @@ export function createTrailController(trail, frames, layers) {
|
|
|
42
32
|
if (tip !== null)
|
|
43
33
|
points.push(tip);
|
|
44
34
|
lastFrame = i;
|
|
45
|
-
// Fresh layers already hold an empty path; only clear what was drawn.
|
|
46
35
|
if (points.length === 0 && !drawn)
|
|
47
36
|
return;
|
|
48
37
|
drawn = points.length > 0;
|
package/dist/restyle.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
// Settings -> scene mapping for the app's live restyle. It runs the very
|
|
2
|
-
// planning the pipeline runs (page.planPageOpts over the telemetry's fix
|
|
3
|
-
// bbox), so a preview and an export from the same settings agree frame for
|
|
4
|
-
// frame. Pure (no DOM, no I/O): the browser UI and unit tests drive it
|
|
5
|
-
// directly.
|
|
6
1
|
import { buildSceneData, planPageOpts } from './page.js';
|
|
7
|
-
export function restyleSceneData(prev, config, meta,
|
|
8
|
-
// The output size to plan at: the export preview plans at the size the
|
|
9
|
-
// pipeline will render, while the player keeps the prepared scene's own.
|
|
10
|
-
size = { width: prev.width, height: prev.height }) {
|
|
2
|
+
export function restyleSceneData(prev, config, meta, size = { width: prev.width, height: prev.height }) {
|
|
11
3
|
const planned = planPageOpts({
|
|
12
4
|
bbox: meta.bbox,
|
|
13
5
|
width: size.width,
|
package/dist/run.js
CHANGED
|
@@ -6,16 +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 { writeTelemetryDocument } from './telemetry-json.js';
|
|
9
10
|
import { prefetchTiles } from './tiles.js';
|
|
10
11
|
import { planIntroOutroFrames, planView } from './plan.js';
|
|
11
12
|
import { buildPageHtml, planPageOpts } from './page.js';
|
|
12
13
|
import { renderVideo } from './render.js';
|
|
13
|
-
import {
|
|
14
|
+
import { effectiveZoomOut, hasAltitude, resolveHudSpec, resolveRange, } from './config.js';
|
|
14
15
|
import { fixesLabel, noLockCuesLabel, telemetrySummary, trackDistanceLabel, } from './summary.js';
|
|
15
|
-
import { NOOP_TRACER, stage } from './tracing.js';
|
|
16
|
-
// The preparation stages in execution order. The loading-bar step numbers
|
|
17
|
-
// derive from this sequence, so adding or reordering a stage cannot silently
|
|
18
|
-
// skew the bar (see PrepareProgress).
|
|
19
16
|
const PREPARE_STAGE_ORDER = ['probe', 'telemetry', 'plan'];
|
|
20
17
|
export function outputPathFor(videoPath, config) {
|
|
21
18
|
const base = videoBaseName(videoPath);
|
|
@@ -40,7 +37,6 @@ export function planOutputs(videos, config) {
|
|
|
40
37
|
return { out, plain };
|
|
41
38
|
});
|
|
42
39
|
}
|
|
43
|
-
// HUD sanity: drop chips whose data does not exist for this source.
|
|
44
40
|
function resolveHud(config, tel, log) {
|
|
45
41
|
const hud = resolveHudSpec(config.hud, hasAltitude(tel.frames.map((f) => f.alt)));
|
|
46
42
|
if (config.hud.alt && !hud.alt) {
|
|
@@ -78,8 +74,6 @@ function describeView(config, overview, tilesLabel) {
|
|
|
78
74
|
function mtimeOf(outPath) {
|
|
79
75
|
return fs.existsSync(outPath) ? fs.statSync(outPath).mtimeMs : null;
|
|
80
76
|
}
|
|
81
|
-
// Never leave a broken or partial render behind: on any failure the output
|
|
82
|
-
// this run wrote is deleted (a pre-existing file we did not touch stays).
|
|
83
77
|
function removePartialOutput(outPath, mtimeBefore, log) {
|
|
84
78
|
const mtimeNow = mtimeOf(outPath);
|
|
85
79
|
if (mtimeNow !== null && (mtimeBefore === null || mtimeNow !== mtimeBefore)) {
|
|
@@ -104,11 +98,6 @@ const realDeps = {
|
|
|
104
98
|
verifyOutput,
|
|
105
99
|
outputMatchesSource,
|
|
106
100
|
};
|
|
107
|
-
// A caller overrides only the dep its composition owns (the app shares its
|
|
108
|
-
// tile queue with every lane); nullish overrides - possible from untyped
|
|
109
|
-
// shell code - count as omitted, so no real dep is ever dropped. The bulk
|
|
110
|
-
// warm carries no cacheDir (providers own their cache), so the default
|
|
111
|
-
// binds the run's own cache here, where the run's config is in hand.
|
|
112
101
|
function resolveDeps(overrides, tileCache) {
|
|
113
102
|
return {
|
|
114
103
|
probeVideo: overrides?.probeVideo ?? realDeps.probeVideo,
|
|
@@ -120,17 +109,6 @@ function resolveDeps(overrides, tileCache) {
|
|
|
120
109
|
outputMatchesSource: overrides?.outputMatchesSource ?? realDeps.outputMatchesSource,
|
|
121
110
|
};
|
|
122
111
|
}
|
|
123
|
-
// A segment export renders source frames start..end inclusive; the guard
|
|
124
|
-
// keeps the render and the verification honest about what the source has.
|
|
125
|
-
function resolveRange(range, frames) {
|
|
126
|
-
if (!range)
|
|
127
|
-
return null;
|
|
128
|
-
assertValidFrameRange(range);
|
|
129
|
-
if (range.end >= frames) {
|
|
130
|
-
throw new Error(`frame range ${range.start}-${range.end} is beyond the recording (${frames} frames)`);
|
|
131
|
-
}
|
|
132
|
-
return range;
|
|
133
|
-
}
|
|
134
112
|
function createPrepareReporter(onProgress = () => { }) {
|
|
135
113
|
return (stage) => onProgress({
|
|
136
114
|
stage,
|
|
@@ -139,9 +117,9 @@ function createPrepareReporter(onProgress = () => { }) {
|
|
|
139
117
|
});
|
|
140
118
|
}
|
|
141
119
|
async function probeStage(env) {
|
|
142
|
-
const { videoPath, config, log,
|
|
120
|
+
const { videoPath, config, log, deps, tools, report } = env;
|
|
143
121
|
report('probe');
|
|
144
|
-
const probe = await
|
|
122
|
+
const probe = await deps.probeVideo(tools, videoPath, log);
|
|
145
123
|
log(`source: ${path.basename(videoPath)} ${probe.width}x${probe.height} @ ${probe.fps.str} fps, ${probe.frames} frames`);
|
|
146
124
|
const introOutro = planIntroOutroFrames(config, {
|
|
147
125
|
fps: probe.fps.value,
|
|
@@ -153,87 +131,58 @@ async function probeStage(env) {
|
|
|
153
131
|
return { probe, introOutro };
|
|
154
132
|
}
|
|
155
133
|
async function telemetryStage(env, probe) {
|
|
156
|
-
const { videoPath, config, log,
|
|
134
|
+
const { videoPath, config, log, deps, tools, report } = env;
|
|
157
135
|
report('telemetry');
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
tools,
|
|
164
|
-
});
|
|
165
|
-
span.setAttributes({
|
|
166
|
-
'telemetry.source': loaded.source,
|
|
167
|
-
'telemetry.method': loaded.method,
|
|
168
|
-
'telemetry.fix.count': loaded.fixCount,
|
|
169
|
-
'telemetry.noLock.count': loaded.noLock,
|
|
170
|
-
});
|
|
171
|
-
return loaded;
|
|
136
|
+
const loaded = await deps.loadTelemetry(videoPath, {
|
|
137
|
+
frames: probe.frames,
|
|
138
|
+
fpsValue: probe.fps.value,
|
|
139
|
+
durationSec: probe.durationSec,
|
|
140
|
+
tools,
|
|
172
141
|
});
|
|
142
|
+
const tel = loaded.telemetry;
|
|
173
143
|
const summary = telemetrySummary(tel);
|
|
174
144
|
log(`telemetry: ${summary.source} (${summary.method}), ${fixesLabel(summary.fixes)}, ` +
|
|
175
145
|
`heading=${summary.headingMode}, track ${trackDistanceLabel(summary.trackDistanceM)}` +
|
|
176
146
|
(summary.noLock ? `, ${noLockCuesLabel(summary.noLock)}` : ''));
|
|
177
147
|
const hud = resolveHud(config, tel, log);
|
|
178
|
-
return {
|
|
148
|
+
return {
|
|
149
|
+
tel,
|
|
150
|
+
frameValues: loaded.frameValues,
|
|
151
|
+
protoFile: loaded.protoFile,
|
|
152
|
+
gimbalDevice: loaded.gimbalDevice,
|
|
153
|
+
hud,
|
|
154
|
+
};
|
|
179
155
|
}
|
|
180
156
|
async function viewPlanStage(env, tel) {
|
|
181
|
-
const { config, log,
|
|
157
|
+
const { config, log, report } = env;
|
|
182
158
|
report('plan');
|
|
183
|
-
const overview =
|
|
184
|
-
const computed = planView(tel.bbox, config.width, config.height, config);
|
|
185
|
-
span.setAttributes({
|
|
186
|
-
'plan.zoom': computed.zoom,
|
|
187
|
-
'plan.zoomOut': effectiveZoomOut(config),
|
|
188
|
-
'plan.tile.count': computed.tiles.length,
|
|
189
|
-
});
|
|
190
|
-
return computed;
|
|
191
|
-
});
|
|
159
|
+
const overview = planView(tel.bbox, config.width, config.height, config);
|
|
192
160
|
log(describeView(config, overview, config.style));
|
|
193
161
|
return overview;
|
|
194
162
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const stats = await deps.prefetchTiles({
|
|
201
|
-
style: config.style,
|
|
202
|
-
tiles: overview.tiles,
|
|
203
|
-
log,
|
|
204
|
-
});
|
|
205
|
-
span.setAttributes({
|
|
206
|
-
'tiles.total': stats.total,
|
|
207
|
-
'tiles.downloaded': stats.downloaded,
|
|
208
|
-
'tiles.cached': stats.total - stats.downloaded - stats.failed,
|
|
209
|
-
'tiles.failed': stats.failed,
|
|
210
|
-
});
|
|
211
|
-
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,
|
|
212
168
|
});
|
|
213
169
|
if (tileStats.downloaded) {
|
|
214
170
|
log(`tiles: ${tileStats.downloaded} downloaded, ${tileStats.failed} placeholders`);
|
|
215
171
|
}
|
|
216
172
|
return tileStats;
|
|
217
173
|
}
|
|
218
|
-
// The preparation stages shared by the headless pipeline and the app: probe,
|
|
219
|
-
// telemetry, view plan. One trace context: the stages nest under the caller's
|
|
220
|
-
// parent span (or stand alone when none is given).
|
|
221
174
|
export async function prepareSession(videoPath, config, log, options = {}) {
|
|
222
175
|
const env = {
|
|
223
176
|
videoPath,
|
|
224
177
|
config,
|
|
225
178
|
log,
|
|
226
|
-
tracer: options.trace?.tracer ?? NOOP_TRACER,
|
|
227
|
-
parent: options.trace?.parent,
|
|
228
179
|
deps: resolveDeps(options.deps, config.tileCache),
|
|
229
180
|
tools: options.tools ?? resolveFfTools(config),
|
|
230
181
|
report: createPrepareReporter(options.onProgress),
|
|
231
182
|
};
|
|
232
|
-
// Config producers normalize the canvas (config.normalizeDimensions); the
|
|
233
|
-
// pipeline renders exactly what the vocabulary resolved.
|
|
234
183
|
const { width, height } = config;
|
|
235
184
|
const { probe, introOutro } = await probeStage(env);
|
|
236
|
-
const { tel, hud } = await telemetryStage(env, probe);
|
|
185
|
+
const { tel, frameValues, protoFile, gimbalDevice, hud } = await telemetryStage(env, probe);
|
|
237
186
|
const overview = await viewPlanStage(env, tel);
|
|
238
187
|
const frames = frameArrays(tel);
|
|
239
188
|
return {
|
|
@@ -241,17 +190,15 @@ export async function prepareSession(videoPath, config, log, options = {}) {
|
|
|
241
190
|
height,
|
|
242
191
|
probe,
|
|
243
192
|
tel,
|
|
193
|
+
frameValues,
|
|
194
|
+
protoFile,
|
|
195
|
+
gimbalDevice,
|
|
244
196
|
hud,
|
|
245
197
|
introOutro,
|
|
246
198
|
overview,
|
|
247
199
|
frames,
|
|
248
200
|
};
|
|
249
201
|
}
|
|
250
|
-
// Maps a prepared recording onto the shared renderer page's inputs through
|
|
251
|
-
// the same planning the app's live restyle uses; callers add the video option
|
|
252
|
-
// when they drive the interactive variant. The planning triple is computed
|
|
253
|
-
// once in prepareSession and passed down, so the summary and the rendered
|
|
254
|
-
// page cannot drift apart.
|
|
255
202
|
export function recordingPageOpts(prep, config) {
|
|
256
203
|
return planPageOpts({
|
|
257
204
|
bbox: prep.tel.bbox,
|
|
@@ -281,9 +228,7 @@ function buildOkSummary(ctx, elapsedSec) {
|
|
|
281
228
|
introFrames: introOutro.introN,
|
|
282
229
|
outroFrames: introOutro.outroN,
|
|
283
230
|
hud,
|
|
284
|
-
//
|
|
285
|
-
// TelemetrySummary must land here visibly, not silently drop a key
|
|
286
|
-
// from the --json line.
|
|
231
|
+
// Field by field, not a spread: a TelemetrySummary rename must land here visibly, not silently drop a --json key.
|
|
287
232
|
source: telemetry.source,
|
|
288
233
|
method: telemetry.method,
|
|
289
234
|
headingMode: telemetry.headingMode,
|
|
@@ -303,27 +248,18 @@ function buildOkSummary(ctx, elapsedSec) {
|
|
|
303
248
|
};
|
|
304
249
|
}
|
|
305
250
|
async function verifyRenderedOutput(env) {
|
|
306
|
-
const { ctx, deps, tools
|
|
307
|
-
await
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
'verify.fps.expected': ctx.probe.fps.str,
|
|
313
|
-
'verify.fps.actual': verify.fps ?? 'unknown',
|
|
314
|
-
'verify.ok': verify.ok,
|
|
315
|
-
});
|
|
316
|
-
if (!verify.ok) {
|
|
317
|
-
throw new Error(`output verification failed: got ${verify.frames} frames @ ${verify.fps ?? 'unknown'}, ` +
|
|
318
|
-
`expected ${ctx.outFrames} @ ${ctx.probe.fps.str}`);
|
|
319
|
-
}
|
|
320
|
-
});
|
|
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
|
+
}
|
|
321
257
|
ctx.log(ctx.frameRange
|
|
322
258
|
? 'verified: frame count and frame rate are 1:1 within the exported range'
|
|
323
259
|
: 'verified: frame count and frame rate match the source');
|
|
324
260
|
}
|
|
325
261
|
async function renderToOutput(env) {
|
|
326
|
-
const { ctx, deps, tools, options
|
|
262
|
+
const { ctx, deps, tools, options } = env;
|
|
327
263
|
const html = buildPageHtml(recordingPageOpts(ctx, ctx.config));
|
|
328
264
|
fs.mkdirSync(path.dirname(ctx.outPath), { recursive: true });
|
|
329
265
|
await renderWithOutputCleanup(ctx.outPath, ctx.log, async () => {
|
|
@@ -346,65 +282,65 @@ async function renderToOutput(env) {
|
|
|
346
282
|
browserPath: ctx.config.browser,
|
|
347
283
|
signal: options.signal,
|
|
348
284
|
log: ctx.log,
|
|
349
|
-
trace: { tracer, parent: root },
|
|
350
285
|
onCapture: options.onCapture,
|
|
351
286
|
});
|
|
352
287
|
await verifyRenderedOutput(env);
|
|
353
288
|
});
|
|
354
289
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
290
|
+
export function telemetryExportInput(prep) {
|
|
291
|
+
return {
|
|
292
|
+
source: prep.tel.source,
|
|
293
|
+
headingMode: prep.tel.headingMode,
|
|
294
|
+
frameCount: prep.probe.frames,
|
|
295
|
+
protoFile: prep.protoFile,
|
|
296
|
+
gimbalDevice: prep.gimbalDevice,
|
|
297
|
+
frames: prep.frameValues,
|
|
298
|
+
headingDeg: prep.tel.frames.map((frame) => frame.headingDeg),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
function writeTelemetryExport(file, prep, log) {
|
|
302
|
+
// The document intentionally covers the whole recording: a frame range
|
|
303
|
+
// limits the render, never this export.
|
|
304
|
+
writeTelemetryDocument(file, telemetryExportInput(prep));
|
|
305
|
+
log(`telemetry JSON: wrote ${file}`);
|
|
306
|
+
}
|
|
359
307
|
export async function processRecording(videoPath, config, log, outPath = outputPathFor(videoPath, config), options = {}) {
|
|
360
308
|
const t0 = Date.now();
|
|
361
|
-
const tracer = options.trace?.tracer ?? NOOP_TRACER;
|
|
362
309
|
const deps = resolveDeps(options.deps, config.tileCache);
|
|
363
310
|
const tools = options.tools ?? resolveFfTools(config);
|
|
364
311
|
if (options.signal?.aborted)
|
|
365
312
|
throw new Error('render canceled');
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
...options,
|
|
371
|
-
deps,
|
|
372
|
-
tools,
|
|
373
|
-
trace: { tracer, parent: root },
|
|
374
|
-
});
|
|
375
|
-
root.setAttributes({
|
|
376
|
-
'canvas.width': prep.width,
|
|
377
|
-
'canvas.height': prep.height,
|
|
378
|
-
'map.style': config.style,
|
|
379
|
-
'map.view': config.view,
|
|
380
|
-
'source.frames': prep.probe.frames,
|
|
381
|
-
'source.fps': prep.probe.fps.value,
|
|
382
|
-
'telemetry.source': prep.tel.source,
|
|
383
|
-
});
|
|
384
|
-
const tileStats = await tileWarmStage(deps, config, prep.overview, log, tracer, root);
|
|
385
|
-
const range = resolveRange(options.range, prep.probe.frames);
|
|
386
|
-
const outFrames = range ? range.end - range.start + 1 : prep.probe.frames;
|
|
387
|
-
const ctx = {
|
|
388
|
-
...prep,
|
|
389
|
-
videoPath,
|
|
390
|
-
outPath,
|
|
391
|
-
config,
|
|
392
|
-
log,
|
|
393
|
-
outFrames,
|
|
394
|
-
frameRange: range,
|
|
395
|
-
tileStats,
|
|
396
|
-
};
|
|
397
|
-
await renderToOutput({ ctx, deps, tools, options, tracer, root });
|
|
398
|
-
return buildOkSummary(ctx, Math.round((Date.now() - t0) / 1000));
|
|
313
|
+
const prep = await prepareSession(videoPath, config, log, {
|
|
314
|
+
...options,
|
|
315
|
+
deps,
|
|
316
|
+
tools,
|
|
399
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));
|
|
400
336
|
}
|
|
401
|
-
// Failures never abort the batch.
|
|
402
337
|
export async function runBatch(videos, config, log, emit, options = {}) {
|
|
403
338
|
const result = { ok: 0, skipped: 0, failed: 0 };
|
|
404
339
|
const deps = resolveDeps(options.deps, config.tileCache);
|
|
405
340
|
const tools = options.tools ?? resolveFfTools(config);
|
|
406
|
-
|
|
407
|
-
|
|
341
|
+
if (config.telemetryJson && videos.length > 1) {
|
|
342
|
+
throw new Error('--telemetry-json writes one document per run: give a single recording');
|
|
343
|
+
}
|
|
408
344
|
const plans = planOutputs(videos, config);
|
|
409
345
|
for (const [idx, video] of videos.entries()) {
|
|
410
346
|
const base = path.basename(video);
|
package/dist/serve.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// Static assets and video streaming shared by the headless render server and
|
|
2
|
-
// the app's session server. URL routing and its guards live in src/assets.ts;
|
|
3
|
-
// this shell performs the I/O and writes the resolved result.
|
|
4
1
|
import fs from 'node:fs';
|
|
5
2
|
import path from 'node:path';
|
|
6
3
|
import { createRequire } from 'node:module';
|
|
@@ -10,12 +7,7 @@ import { mimeFor, resolveAsset } from './assets.js';
|
|
|
10
7
|
import { rangePlan } from './range.js';
|
|
11
8
|
const require_ = createRequire(import.meta.url);
|
|
12
9
|
const LEAFLET_DIR = path.dirname(require_.resolve('leaflet/dist/leaflet.js'));
|
|
13
|
-
/** Compiled shared renderer modules, served to generated pages as ESM. */
|
|
14
10
|
export const RENDERER_DIR = fileURLToPath(new URL('./renderer/', import.meta.url));
|
|
15
|
-
// Writes the shared router's result: the routed file (or its placeholder
|
|
16
|
-
// fallback) with its mime, or a 404 for a claimed URL without a file.
|
|
17
|
-
// Returns true when the URL belongs to one of the routes; callers route
|
|
18
|
-
// everything else themselves.
|
|
19
11
|
export function serveAsset(url, res, routes) {
|
|
20
12
|
const asset = resolveAsset(url, { ...routes, leafletDir: LEAFLET_DIR });
|
|
21
13
|
if (asset.kind === 'unrouted')
|
|
@@ -35,9 +27,6 @@ export function serveAsset(url, res, routes) {
|
|
|
35
27
|
res.end('not found');
|
|
36
28
|
return true;
|
|
37
29
|
}
|
|
38
|
-
// Streams a file with HTTP Range support so the <video> element can seek.
|
|
39
|
-
// The returned promise resolves once the file handle is released, so callers
|
|
40
|
-
// can order file cleanup after the stream.
|
|
41
30
|
export function serveFileWithRange(req, res, filePath) {
|
|
42
31
|
let size;
|
|
43
32
|
try {
|
|
@@ -62,8 +51,6 @@ export function serveFileWithRange(req, res, filePath) {
|
|
|
62
51
|
const stream = plan.status === 206
|
|
63
52
|
? fs.createReadStream(filePath, { start: plan.span.start, end: plan.span.end })
|
|
64
53
|
: fs.createReadStream(filePath);
|
|
65
|
-
// pipeline tears the read stream down when the client aborts (every video
|
|
66
|
-
// seek does), so the file handle is released and the promise settles.
|
|
67
54
|
return new Promise((resolve) => {
|
|
68
55
|
pipeline(stream, res, () => resolve());
|
|
69
56
|
});
|
package/dist/srt.js
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
|
-
// One cue per video frame; the cue index equals the video frame index. Cues
|
|
2
|
-
// whose latitude/longitude line is not a real GPS fix (src/geo.ts's
|
|
3
|
-
// gpsFix - the (0, 0) placeholder or worse) are kept with fix = null so
|
|
4
|
-
// alignment is never lost.
|
|
5
1
|
import { readFile } from 'node:fs/promises';
|
|
6
2
|
import { gpsFix } from './geo.js';
|
|
7
3
|
const RX_TIMING = /^(\d{2}):(\d{2}):(\d{2})[,.](\d{3})\s*-->/;
|
|
8
4
|
const RX_LATLON = /\[latitude:\s*(-?\d+\.?\d*)\]\s*\[longitude:\s*(-?\d+\.?\d*)\]/;
|
|
9
5
|
const RX_ALT = /\[rel_alt:\s*(-?\d+\.?\d*)\s+abs_alt:\s*(-?\d+\.?\d*)\]/;
|
|
6
|
+
const RX_ISO = /\[iso:\s*(-?\d+\.?\d*)\]/;
|
|
7
|
+
const RX_SHUTTER = /\[shutter:\s*([^\]]+)\]/;
|
|
8
|
+
const RX_CT = /\[ct:\s*(-?\d+\.?\d*)\]/;
|
|
9
|
+
const RX_FNUM = /\[fnum:\s*(-?\d+\.?\d*)\]/;
|
|
10
|
+
const RX_FRACTION = /^(\d+\.?\d*)\s*\/\s*(\d+\.?\d*)$/;
|
|
10
11
|
function parseNumber(text) {
|
|
11
12
|
const value = Number.parseFloat(text);
|
|
12
13
|
return Number.isFinite(value) ? value : null;
|
|
13
14
|
}
|
|
15
|
+
function parseShutter(text) {
|
|
16
|
+
const fraction = RX_FRACTION.exec(text.trim());
|
|
17
|
+
if (fraction) {
|
|
18
|
+
const denominator = parseNumber(fraction[2]);
|
|
19
|
+
const numerator = parseNumber(fraction[1]);
|
|
20
|
+
return denominator && numerator !== null ? numerator / denominator : null;
|
|
21
|
+
}
|
|
22
|
+
return parseNumber(text);
|
|
23
|
+
}
|
|
14
24
|
function stripFontTags(line) {
|
|
15
25
|
return line.replace(/<[^>]*>/g, '').trim();
|
|
16
26
|
}
|
|
@@ -26,15 +36,16 @@ function newCue(tSec) {
|
|
|
26
36
|
fix: null,
|
|
27
37
|
relAlt: null,
|
|
28
38
|
absAlt: null,
|
|
39
|
+
iso: null,
|
|
40
|
+
shutterTime: null,
|
|
41
|
+
whiteBalanceCctK: null,
|
|
42
|
+
fNumber: null,
|
|
29
43
|
};
|
|
30
44
|
}
|
|
31
45
|
export function parseSrtText(text) {
|
|
32
46
|
const cues = [];
|
|
33
47
|
let noLock = 0;
|
|
34
48
|
let baseMs = null;
|
|
35
|
-
// A second (repeated) lat/lon line in one cue must not count as another
|
|
36
|
-
// no-lock event - only the current cue can receive lines, so one flag is
|
|
37
|
-
// enough to remember whether it already saw one.
|
|
38
49
|
let cueSawLatLon = false;
|
|
39
50
|
for (const rawLine of text.split(/\r?\n/)) {
|
|
40
51
|
const line = stripFontTags(rawLine);
|
|
@@ -44,7 +55,6 @@ export function parseSrtText(text) {
|
|
|
44
55
|
if (timing) {
|
|
45
56
|
const ms = timingLineToMs(timing);
|
|
46
57
|
baseMs ??= ms;
|
|
47
|
-
// A timing line always starts a new cue.
|
|
48
58
|
cues.push(newCue((ms - baseMs) / 1000));
|
|
49
59
|
cueSawLatLon = false;
|
|
50
60
|
continue;
|
|
@@ -68,6 +78,18 @@ export function parseSrtText(text) {
|
|
|
68
78
|
cue.relAlt = parseNumber(alt[1]);
|
|
69
79
|
cue.absAlt = parseNumber(alt[2]);
|
|
70
80
|
}
|
|
81
|
+
const iso = cue.iso === null ? RX_ISO.exec(line) : null;
|
|
82
|
+
if (iso)
|
|
83
|
+
cue.iso = parseNumber(iso[1]);
|
|
84
|
+
const shutter = cue.shutterTime === null ? RX_SHUTTER.exec(line) : null;
|
|
85
|
+
if (shutter)
|
|
86
|
+
cue.shutterTime = parseShutter(shutter[1]);
|
|
87
|
+
const ct = cue.whiteBalanceCctK === null ? RX_CT.exec(line) : null;
|
|
88
|
+
if (ct)
|
|
89
|
+
cue.whiteBalanceCctK = parseNumber(ct[1]);
|
|
90
|
+
const fnum = cue.fNumber === null ? RX_FNUM.exec(line) : null;
|
|
91
|
+
if (fnum)
|
|
92
|
+
cue.fNumber = parseNumber(fnum[1]);
|
|
71
93
|
}
|
|
72
94
|
return { cues, noLock, count: cues.length };
|
|
73
95
|
}
|
package/dist/summary.js
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { generateTelemetryJsonSchema } from './telemetry-json.js';
|
|
5
|
+
export function writeTelemetryJsonSchema(file) {
|
|
6
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
7
|
+
fs.writeFileSync(file, generateTelemetryJsonSchema());
|
|
8
|
+
}
|
|
9
|
+
function main() {
|
|
10
|
+
try {
|
|
11
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
12
|
+
const file = path.join(root, 'docs', 'telemetry-json.schema.json');
|
|
13
|
+
writeTelemetryJsonSchema(file);
|
|
14
|
+
process.stderr.write(`[drone-path] docs: wrote ${path.relative(root, file)}\n`);
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
process.stderr.write(`[drone-path] ERROR: ${e.message}\n`);
|
|
18
|
+
process.exitCode = 1;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
22
|
+
main();
|
|
23
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export const TELEMETRY_JSON_SCHEMA_VERSION = 1;
|
|
5
|
+
const GimbalDeviceSchema = z.strictObject({
|
|
6
|
+
id: z.int(),
|
|
7
|
+
type: z.int(),
|
|
8
|
+
subType: z.int(),
|
|
9
|
+
name: z.string(),
|
|
10
|
+
frequency: z.number(),
|
|
11
|
+
});
|
|
12
|
+
const TelemetryRecordSchema = z.strictObject({
|
|
13
|
+
frame: z.int(),
|
|
14
|
+
gimbalDeviceTimestampMs: z.int().optional(),
|
|
15
|
+
lat: z.number().optional(),
|
|
16
|
+
lng: z.number().optional(),
|
|
17
|
+
altAbs: z.number().optional(),
|
|
18
|
+
altRel: z.number().optional(),
|
|
19
|
+
gpsAltMm: z.int().optional(),
|
|
20
|
+
pitchDeg: z.number().optional(),
|
|
21
|
+
rollDeg: z.number().optional(),
|
|
22
|
+
yawDeg: z.number().optional(),
|
|
23
|
+
gimbalPitchDeg: z.number().optional(),
|
|
24
|
+
gimbalRollDeg: z.number().optional(),
|
|
25
|
+
gimbalYawDeg: z.number().optional(),
|
|
26
|
+
headingDeg: z.number(),
|
|
27
|
+
headingSource: z.enum(['yaw', 'cog']),
|
|
28
|
+
iso: z.int().optional(),
|
|
29
|
+
shutterTime: z.number().optional(),
|
|
30
|
+
whiteBalanceCctK: z.int().optional(),
|
|
31
|
+
fNumber: z.number().optional(),
|
|
32
|
+
});
|
|
33
|
+
export const TelemetryDocumentSchema = z.strictObject({
|
|
34
|
+
schemaVersion: z.literal(TELEMETRY_JSON_SCHEMA_VERSION),
|
|
35
|
+
protoFile: z.string().optional(),
|
|
36
|
+
source: z.enum(['srt', 'cammeta']),
|
|
37
|
+
headingMode: z.enum(['yaw', 'cog']),
|
|
38
|
+
frameCount: z.int(),
|
|
39
|
+
gimbalDevice: GimbalDeviceSchema.optional(),
|
|
40
|
+
frames: z.array(TelemetryRecordSchema),
|
|
41
|
+
});
|
|
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');
|
|
67
|
+
function copyValue(record, key, value) {
|
|
68
|
+
if (value === null || value === undefined)
|
|
69
|
+
return;
|
|
70
|
+
record[key] = TELEMETRY_VALUES[key].integer ? Math.round(value) : value;
|
|
71
|
+
}
|
|
72
|
+
function buildRecord(input, index) {
|
|
73
|
+
const row = input.frames[index] ?? {};
|
|
74
|
+
const record = {
|
|
75
|
+
frame: (input.frameStart ?? 0) + index,
|
|
76
|
+
};
|
|
77
|
+
for (const key of BEFORE_HEADING_KEYS)
|
|
78
|
+
copyValue(record, key, row[key]);
|
|
79
|
+
record.headingDeg = input.headingDeg[index];
|
|
80
|
+
record.headingSource = input.headingMode;
|
|
81
|
+
for (const key of EXPOSURE_KEYS)
|
|
82
|
+
copyValue(record, key, row[key]);
|
|
83
|
+
return record;
|
|
84
|
+
}
|
|
85
|
+
export function buildTelemetryDocument(input) {
|
|
86
|
+
if (input.headingDeg.length !== input.frameCount) {
|
|
87
|
+
throw new Error('telemetry JSON: heading count does not match the frame count');
|
|
88
|
+
}
|
|
89
|
+
const frames = [];
|
|
90
|
+
for (let index = 0; index < input.frameCount; index++) {
|
|
91
|
+
frames.push(buildRecord(input, index));
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
schemaVersion: TELEMETRY_JSON_SCHEMA_VERSION,
|
|
95
|
+
...(input.protoFile ? { protoFile: input.protoFile } : {}),
|
|
96
|
+
source: input.source,
|
|
97
|
+
headingMode: input.headingMode,
|
|
98
|
+
frameCount: input.frameCount,
|
|
99
|
+
...(input.gimbalDevice ? { gimbalDevice: input.gimbalDevice } : {}),
|
|
100
|
+
frames,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export function serializeTelemetryDocument(doc) {
|
|
104
|
+
return `${JSON.stringify(doc, null, 2)}\n`;
|
|
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
|
+
}
|
|
111
|
+
export function generateTelemetryJsonSchema() {
|
|
112
|
+
return `${JSON.stringify(z.toJSONSchema(TelemetryDocumentSchema), null, 2)}\n`;
|
|
113
|
+
}
|