drone-path 0.12.1 → 1.0.0-rc1

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.
Files changed (78) hide show
  1. package/README.md +20 -74
  2. package/THIRD-PARTY-NOTICES.md +3 -82
  3. package/bin/drone-path.mjs +0 -0
  4. package/dist/cli.d.ts +14 -0
  5. package/dist/cli.js +7 -7
  6. package/dist/version.d.ts +1 -0
  7. package/package.json +21 -68
  8. package/CHANGELOG.md +0 -336
  9. package/app/ipc.d.mts +0 -43
  10. package/app/ipc.mjs +0 -216
  11. package/app/main.mjs +0 -356
  12. package/app/preload.cjs +0 -34
  13. package/app/update-policy.d.mts +0 -6
  14. package/app/update-policy.mjs +0 -6
  15. package/app/update.d.mts +0 -10
  16. package/app/update.mjs +0 -54
  17. package/dist/appassets.js +0 -35
  18. package/dist/apppaths.js +0 -20
  19. package/dist/appsession.js +0 -121
  20. package/dist/appstate.js +0 -94
  21. package/dist/assets.js +0 -60
  22. package/dist/buildinfo.js +0 -64
  23. package/dist/cammeta-decode.js +0 -237
  24. package/dist/cammeta.js +0 -92
  25. package/dist/changeset-gate.js +0 -39
  26. package/dist/config.js +0 -631
  27. package/dist/configfile.js +0 -86
  28. package/dist/decimate.js +0 -84
  29. package/dist/errors.js +0 -34
  30. package/dist/exec-tool.js +0 -13
  31. package/dist/exportjob.js +0 -90
  32. package/dist/ffmpeg-tools.js +0 -56
  33. package/dist/ffmpeg.js +0 -98
  34. package/dist/frametime.js +0 -32
  35. package/dist/geo.js +0 -60
  36. package/dist/logging.js +0 -1
  37. package/dist/manual/anchors.js +0 -17
  38. package/dist/manual/build.js +0 -67
  39. package/dist/manual/cliref.js +0 -34
  40. package/dist/manual/links.js +0 -59
  41. package/dist/manual/markdown.js +0 -98
  42. package/dist/manual/model.js +0 -1
  43. package/dist/manual/module.js +0 -5
  44. package/dist/manual/nav.js +0 -11
  45. package/dist/manual/reference.js +0 -18
  46. package/dist/paths.js +0 -16
  47. package/dist/pipeline.js +0 -402
  48. package/dist/plan.js +0 -106
  49. package/dist/png.js +0 -32
  50. package/dist/protobuf-wire.js +0 -102
  51. package/dist/range.js +0 -50
  52. package/dist/recordings.js +0 -55
  53. package/dist/render-page.js +0 -85
  54. package/dist/render.js +0 -268
  55. package/dist/renderer/boot.js +0 -7
  56. package/dist/renderer/dom.js +0 -177
  57. package/dist/renderer/framemath.js +0 -30
  58. package/dist/renderer/scene.js +0 -385
  59. package/dist/renderer/theme.js +0 -82
  60. package/dist/renderer/tilesources.js +0 -38
  61. package/dist/renderer/trail.js +0 -42
  62. package/dist/restyle.js +0 -16
  63. package/dist/serve.js +0 -27
  64. package/dist/srt.js +0 -98
  65. package/dist/telemetry-json-schema.js +0 -18
  66. package/dist/telemetry-json.js +0 -126
  67. package/dist/telemetry-math.js +0 -267
  68. package/dist/telemetry-summary.js +0 -19
  69. package/dist/telemetry.js +0 -95
  70. package/dist/tilecache.js +0 -21
  71. package/dist/tiles.js +0 -155
  72. package/dist/track-format.js +0 -13
  73. package/dist/track-geojson.js +0 -44
  74. package/dist/track-gpx.js +0 -34
  75. package/dist/track-kml.js +0 -47
  76. package/dist/track-kmz.js +0 -68
  77. package/dist/track-write.js +0 -41
  78. package/dist/track.js +0 -79
@@ -1,34 +0,0 @@
1
- import { CONFIG_FILE_OPTION, CONFIG_OPTIONS, TELEMETRY_JSON_ALIAS, cliDefaultOf, } from '../config.js';
2
- import { escapeAngleBrackets } from './markdown.js';
3
- function defaultCell(key) {
4
- const value = cliDefaultOf(key);
5
- if (typeof value === 'boolean')
6
- return value ? 'on' : 'off';
7
- return value === '' ? '—' : `\`${value}\``;
8
- }
9
- function describe(row) {
10
- const help = escapeAngleBrackets(row.cli.help);
11
- return row.cli.choices ? `${help} (choices: ${row.cli.choices.join(', ')})` : help;
12
- }
13
- export function generateCliReference() {
14
- const rows = CONFIG_OPTIONS.map((row) => `| \`${row.key}\` | \`${row.cli.flags}\` | ${defaultCell(row.key)} | ${describe(row)} |`);
15
- rows.push(`| — | \`${CONFIG_FILE_OPTION.flags}\` | — | ${CONFIG_FILE_OPTION.help} |`);
16
- rows.push(`| \`${TELEMETRY_JSON_ALIAS.inputKey}\` | \`${TELEMETRY_JSON_ALIAS.flags}\` | — | ` +
17
- `deprecated alias of --track-out <file>.json: same output, warns on use, ` +
18
- `removed in a future version |`);
19
- return [
20
- '<!-- Generated from the option vocabulary in src/config.ts by "npm run docs:reference". Do not edit by hand. -->',
21
- '',
22
- '# CLI and config reference',
23
- '',
24
- 'Every `drone-path` option with its config-file key and built-in default.',
25
- 'In a [config file](config-file.md) every key is optional: anything omitted',
26
- 'falls back to the default below. Run `npx drone-path --help` for the same',
27
- 'table in the terminal.',
28
- '',
29
- '| Config key | CLI flag | Default | Description |',
30
- '|---|---|---|---|',
31
- ...rows,
32
- '',
33
- ].join('\n');
34
- }
@@ -1,59 +0,0 @@
1
- const SCHEME_RX = /^[a-z][a-z0-9+.-]*:/i;
2
- export function pageSlugOf(file) {
3
- const base = file.split('/').pop() ?? file;
4
- return base === 'README.md' ? 'index' : base.replace(/\.md$/, '');
5
- }
6
- export function isExternalTarget(raw) {
7
- return SCHEME_RX.test(raw);
8
- }
9
- export function parsePageLink(raw, currentSlug) {
10
- const [path, hash, ...rest] = raw.split('#');
11
- if (rest.length > 0)
12
- return null;
13
- const anchor = hash === undefined || hash === '' ? null : hash;
14
- if (path === '')
15
- return anchor === null ? null : { slug: currentSlug, anchor };
16
- const clean = path.startsWith('./') ? path.slice(2) : path;
17
- if (!clean.endsWith('.md') || clean.includes('/'))
18
- return null;
19
- return { slug: pageSlugOf(clean), anchor };
20
- }
21
- export function parseImageRef(raw) {
22
- const match = /^\.\.\/images\/([^/?#]+)$/.exec(raw);
23
- return match ? (match[1] ?? null) : null;
24
- }
25
- export function validateCorpus(pages, imageFiles) {
26
- const bySlug = new Map(pages.map((p) => [p.slug, p]));
27
- const issues = [];
28
- for (const { slug, refs } of pages) {
29
- const file = `docs/user/${sourceNameOf(slug)}`;
30
- for (const raw of refs.unknown) {
31
- issues.push({
32
- file,
33
- message: `link "${raw}" is neither a .md page link nor a web link; link pages as "other.md" or "other.md#anchor", and mention plain file paths in backticks`,
34
- });
35
- }
36
- for (const link of refs.links) {
37
- const target = bySlug.get(link.slug);
38
- if (!target) {
39
- issues.push({ file, message: `link "${link.raw}" points at missing page "${link.slug}.md"` });
40
- continue;
41
- }
42
- if (link.anchor !== null && !target.page.headings.some((h) => h.id === link.anchor)) {
43
- issues.push({
44
- file,
45
- message: `link "${link.raw}" points at missing anchor "#${link.anchor}" in "${sourceNameOf(link.slug)}"`,
46
- });
47
- }
48
- }
49
- for (const image of refs.images) {
50
- if (!imageFiles.has(image.file)) {
51
- issues.push({ file, message: `image "${image.raw}" points at missing file "docs/images/${image.file}"` });
52
- }
53
- }
54
- }
55
- return issues;
56
- }
57
- export function sourceNameOf(slug) {
58
- return slug === 'index' ? 'README.md' : `${slug}.md`;
59
- }
@@ -1,98 +0,0 @@
1
- import { Marked } from 'marked';
2
- import { createSlugger } from './anchors.js';
3
- import { isExternalTarget, parseImageRef, parsePageLink } from './links.js';
4
- /** Angle brackets only — for help text that carries no entities (the CLI
5
- reference renders these as literal angle brackets). */
6
- export function escapeAngleBrackets(value) {
7
- return value.replace(/</g, '&lt;').replace(/>/g, '&gt;');
8
- }
9
- function escapeHtml(value) {
10
- return escapeAngleBrackets(value.replace(/&/g, '&amp;'));
11
- }
12
- function escapeAttr(value) {
13
- return escapeHtml(value).replace(/"/g, '&quot;');
14
- }
15
- function inlineText(tokens) {
16
- if (!tokens)
17
- return '';
18
- let out = '';
19
- for (const token of tokens) {
20
- switch (token.type) {
21
- case 'text':
22
- case 'escape':
23
- case 'codespan':
24
- out += token.text;
25
- break;
26
- case 'image':
27
- out += token.text;
28
- break;
29
- case 'br':
30
- out += ' ';
31
- break;
32
- case 'html':
33
- case 'tag':
34
- break;
35
- default:
36
- if ('tokens' in token && token.tokens)
37
- out += inlineText(token.tokens);
38
- }
39
- }
40
- return out;
41
- }
42
- function titleAttr(title) {
43
- return title ? ` title="${escapeAttr(title)}"` : '';
44
- }
45
- export function compileMarkdown(source, slug) {
46
- const slugger = createSlugger();
47
- const headings = [];
48
- const links = [];
49
- const images = [];
50
- const unknown = [];
51
- const md = new Marked({ gfm: true, breaks: false });
52
- md.use({
53
- renderer: {
54
- heading({ tokens, depth }) {
55
- const text = inlineText(tokens);
56
- const id = slugger(text);
57
- headings.push({ id, text, level: depth });
58
- return `<h${depth} id="${escapeAttr(id)}">${this.parser.parseInline(tokens)}</h${depth}>\n`;
59
- },
60
- link({ href, title, tokens }) {
61
- const inner = this.parser.parseInline(tokens);
62
- const label = inlineText(tokens);
63
- if (isExternalTarget(href)) {
64
- return `<a href="${escapeAttr(href)}"${titleAttr(title)} target="_blank" rel="noopener noreferrer">${inner}</a>`;
65
- }
66
- const target = parsePageLink(href, slug);
67
- if (!target) {
68
- unknown.push(href);
69
- return `<a href="${escapeAttr(href)}"${titleAttr(title)}>${inner}</a>`;
70
- }
71
- links.push({ raw: href, label, slug: target.slug, anchor: target.anchor });
72
- const anchor = target.anchor === null ? '' : ` data-manual-anchor="${escapeAttr(target.anchor)}"`;
73
- return `<a href="#manual/${escapeAttr(target.slug)}"${anchor} data-manual-slug="${escapeAttr(target.slug)}"${titleAttr(title)}>${inner}</a>`;
74
- },
75
- image({ href, title, text }) {
76
- const file = parseImageRef(href);
77
- if (!file) {
78
- unknown.push(href);
79
- return `<img src="${escapeAttr(href)}" alt="${escapeAttr(text)}"${titleAttr(title)}>`;
80
- }
81
- images.push({ raw: href, file });
82
- return `<img src="/manual/images/${escapeAttr(file)}" alt="${escapeAttr(text)}"${titleAttr(title)}>`;
83
- },
84
- html({ text }) {
85
- // Comments disappear like on GitHub; any other raw HTML is escaped.
86
- return /^<!--[\s\S]*-->$/.test(text) ? '' : escapeHtml(text);
87
- },
88
- },
89
- });
90
- // Two-step form instead of parse(): only parser(lexer(...)) types the output as a plain string.
91
- const html = md.parser(md.lexer(source));
92
- const title = headings.find((h) => h.level === 1)?.text ?? '';
93
- return {
94
- slug,
95
- page: { slug, title, headings, html },
96
- refs: { links, images, unknown },
97
- };
98
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- export function bundleModuleSource(bundle) {
2
- const header = '// Generated by src/manual/build.ts from docs/user/*.md. Do not edit.\n' +
3
- "import type { ManualBundle } from '../../../../src/manual/model.js';\n\n";
4
- return `${header}export const MANUAL: ManualBundle = ${JSON.stringify(bundle, null, 2)};\n`;
5
- }
@@ -1,11 +0,0 @@
1
- export function navFromIndex(index) {
2
- const nav = [{ slug: index.slug, label: index.page.title }];
3
- const seen = new Set([index.slug]);
4
- for (const link of index.refs.links) {
5
- if (seen.has(link.slug))
6
- continue;
7
- seen.add(link.slug);
8
- nav.push({ slug: link.slug, label: link.label });
9
- }
10
- return nav;
11
- }
@@ -1,18 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
- import { runToolMain } from '../errors.js';
5
- import { generateCliReference } from './cliref.js';
6
- function writeReference(file) {
7
- fs.mkdirSync(path.dirname(file), { recursive: true });
8
- fs.writeFileSync(file, generateCliReference());
9
- }
10
- function main() {
11
- const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');
12
- const file = path.join(root, 'docs', 'user', 'cli-reference.md');
13
- writeReference(file);
14
- process.stderr.write(`[drone-path] manual: wrote ${path.relative(root, file)}\n`);
15
- }
16
- if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
17
- void runToolMain(main);
18
- }
package/dist/paths.js DELETED
@@ -1,16 +0,0 @@
1
- import path from 'node:path';
2
- export function pathKey(p, platform = process.platform) {
3
- const resolved = platform === 'win32' ? path.win32.resolve(p) : path.posix.resolve(p);
4
- return platform === 'win32' ? resolved.toLowerCase() : resolved;
5
- }
6
- export function samePath(a, b, platform = process.platform) {
7
- return pathKey(a, platform) === pathKey(b, platform);
8
- }
9
- export function uniquePath(dir, stem, ext, isTaken) {
10
- for (let n = 1;; n++) {
11
- const name = n === 1 ? `${stem}${ext}` : `${stem}-${n}${ext}`;
12
- const candidate = path.join(dir, name);
13
- if (!isTaken(candidate))
14
- return candidate;
15
- }
16
- }
package/dist/pipeline.js DELETED
@@ -1,402 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { ERR_OUTPUT_VERIFICATION, ERR_RENDER_CANCELED, errorMessage } from './errors.js';
4
- import { outputMatchesSource, probeVideo, verifyOutput } from './ffmpeg.js';
5
- import { resolveFfmpegTools } from './ffmpeg-tools.js';
6
- import { videoBaseName } from './recordings.js';
7
- import { pathKey, uniquePath } from './paths.js';
8
- import { loadTelemetry } from './telemetry.js';
9
- import { writeTrackFile } from './track-write.js';
10
- import { prefetchTiles } from './tiles.js';
11
- import { planIntroOutroFrames, planView } from './plan.js';
12
- import { buildPageHtml, planPageOpts } from './render-page.js';
13
- import { renderVideo } from './render.js';
14
- import { effectiveZoomOut, hasAltitude, resolveHudLayout, resolveFrameRange, } from './config.js';
15
- import { fixCountLabel, noLockCountLabel, telemetrySummary, trackDistanceLabel, } from './telemetry-summary.js';
16
- const PREPARE_STAGE_ORDER = ['probe', 'telemetry', 'plan'];
17
- export function outputPathFor(videoPath, config) {
18
- const base = videoBaseName(videoPath);
19
- const name = `${base}${config.outSuffix}.mp4`;
20
- return config.outDir
21
- ? path.join(config.outDir, name)
22
- : path.join(path.dirname(videoPath), name);
23
- }
24
- export function planOutputs(videos, config) {
25
- const used = new Set();
26
- return videos.map((video) => {
27
- const plain = outputPathFor(video, config);
28
- const key = pathKey(plain);
29
- if (!used.has(key)) {
30
- used.add(key);
31
- return { out: plain, plain };
32
- }
33
- const ext = path.extname(plain);
34
- const stem = path.basename(plain, ext);
35
- const out = uniquePath(path.dirname(plain), stem, ext, (candidate) => used.has(pathKey(candidate)));
36
- used.add(pathKey(out));
37
- return { out, plain };
38
- });
39
- }
40
- function resolveHud(config, tel, log) {
41
- const hud = resolveHudLayout(config.hud, hasAltitude(tel.frames.map((f) => f.alt)));
42
- if (config.hud.alt && !hud.alt) {
43
- log('hud: altitude unavailable in this telemetry source (chip disabled)');
44
- }
45
- return hud;
46
- }
47
- export function frameChannelsOf(tel) {
48
- const lat = [];
49
- const lon = [];
50
- tel.frames.forEach((frame, i) => {
51
- if (frame.fix === null) {
52
- throw new Error(`telemetry frame ${i} has no GPS position`);
53
- }
54
- lat.push(frame.fix.lat);
55
- lon.push(frame.fix.lon);
56
- });
57
- return {
58
- lat,
59
- lon,
60
- alt: tel.frames.map((f) => f.alt),
61
- speed: tel.frames.map((f) => f.speed),
62
- headingDeg: tel.frames.map((f) => f.headingDeg),
63
- };
64
- }
65
- function describeView(config, overview, tilesLabel) {
66
- const zoomNote = config.zoom
67
- ? ' (fixed)'
68
- : config.zoomOut
69
- ? ` (-${config.zoomOut})`
70
- : '';
71
- return (`view: ${config.view} at zoom ${overview.zoom}${zoomNote}, ` +
72
- `${overview.tiles.length} tiles (${tilesLabel})`);
73
- }
74
- function mtimeOf(outPath) {
75
- return fs.existsSync(outPath) ? fs.statSync(outPath).mtimeMs : null;
76
- }
77
- function removePartialOutput(outPath, mtimeBefore, log) {
78
- const mtimeNow = mtimeOf(outPath);
79
- if (mtimeNow !== null && (mtimeBefore === null || mtimeNow !== mtimeBefore)) {
80
- fs.rmSync(outPath, { force: true });
81
- log(`removed partial output: ${outPath}`);
82
- }
83
- }
84
- async function renderWithOutputCleanup(outPath, log, render) {
85
- const mtimeBefore = mtimeOf(outPath);
86
- try {
87
- await render();
88
- }
89
- catch (e) {
90
- removePartialOutput(outPath, mtimeBefore, log);
91
- throw e;
92
- }
93
- }
94
- const realDeps = {
95
- probeVideo,
96
- loadTelemetry,
97
- renderVideo,
98
- verifyOutput,
99
- outputMatchesSource,
100
- };
101
- function resolveDeps(overrides, tileCache) {
102
- return {
103
- probeVideo: overrides?.probeVideo ?? realDeps.probeVideo,
104
- loadTelemetry: overrides?.loadTelemetry ?? realDeps.loadTelemetry,
105
- prefetchTiles: overrides?.prefetchTiles ??
106
- ((options) => prefetchTiles({ ...options, cacheDir: tileCache })),
107
- renderVideo: overrides?.renderVideo ?? realDeps.renderVideo,
108
- verifyOutput: overrides?.verifyOutput ?? realDeps.verifyOutput,
109
- outputMatchesSource: overrides?.outputMatchesSource ?? realDeps.outputMatchesSource,
110
- };
111
- }
112
- function createPrepareReporter(onProgress = () => { }) {
113
- return (stage) => onProgress({
114
- stage,
115
- done: PREPARE_STAGE_ORDER.indexOf(stage),
116
- total: PREPARE_STAGE_ORDER.length,
117
- });
118
- }
119
- async function probeStage(env) {
120
- const { videoPath, config, log, deps, tools, report } = env;
121
- report('probe');
122
- const probe = await deps.probeVideo(tools, videoPath, log);
123
- log(`source: ${path.basename(videoPath)} ${probe.width}x${probe.height} @ ${probe.fps.str} fps, ${probe.frames} frames`);
124
- const introOutro = planIntroOutroFrames(config, {
125
- fps: probe.fps.value,
126
- frames: probe.frames,
127
- });
128
- if (introOutro.clamped) {
129
- log(`intro/outro shortened to ${introOutro.introN}/${introOutro.outroN} frames for this clip`);
130
- }
131
- return { probe, introOutro };
132
- }
133
- async function telemetryStage(env, probe) {
134
- const { videoPath, config, log, deps, tools, report } = env;
135
- report('telemetry');
136
- const loaded = await deps.loadTelemetry(videoPath, {
137
- frames: probe.frames,
138
- fpsValue: probe.fps.value,
139
- durationSec: probe.durationSec,
140
- tools,
141
- });
142
- const tel = loaded.telemetry;
143
- const summary = telemetrySummary(tel);
144
- log(`telemetry: ${summary.source} (${summary.method}), ${fixCountLabel(summary.fixCount)}, ` +
145
- `heading=${summary.headingMode}, track ${trackDistanceLabel(summary.trackDistanceM)}` +
146
- (summary.noLock ? `, ${noLockCountLabel(summary.noLock)}` : ''));
147
- const hud = resolveHud(config, tel, log);
148
- return {
149
- tel,
150
- frameValues: loaded.frameValues,
151
- trackValues: loaded.trackValues,
152
- protoFile: loaded.protoFile,
153
- gimbalDevice: loaded.gimbalDevice,
154
- hud,
155
- };
156
- }
157
- async function viewPlanStage(env, tel) {
158
- const { config, log, report } = env;
159
- report('plan');
160
- const overview = planView(tel.bbox, config.width, config.height, config);
161
- log(describeView(config, overview, config.style));
162
- return overview;
163
- }
164
- async function tileWarmStage(deps, config, overview, log) {
165
- const tileStats = await deps.prefetchTiles({
166
- style: config.style,
167
- tiles: overview.tiles,
168
- log,
169
- });
170
- if (tileStats.downloaded) {
171
- log(`tiles: ${tileStats.downloaded} downloaded, ${tileStats.failed} placeholders`);
172
- }
173
- return tileStats;
174
- }
175
- export async function prepareSession(videoPath, config, log, options = {}) {
176
- const env = {
177
- videoPath,
178
- config,
179
- log,
180
- deps: resolveDeps(options.deps, config.tileCache),
181
- tools: options.tools ?? resolveFfmpegTools(config),
182
- report: createPrepareReporter(options.onProgress),
183
- };
184
- const { width, height } = config;
185
- const { probe, introOutro } = await probeStage(env);
186
- const { tel, frameValues, trackValues, protoFile, gimbalDevice, hud } = await telemetryStage(env, probe);
187
- const overview = await viewPlanStage(env, tel);
188
- const frames = frameChannelsOf(tel);
189
- return {
190
- width,
191
- height,
192
- probe,
193
- tel,
194
- frameValues,
195
- trackValues,
196
- protoFile,
197
- gimbalDevice,
198
- hud,
199
- introOutro,
200
- overview,
201
- frames,
202
- };
203
- }
204
- export function recordingPageOpts(prep, config) {
205
- return planPageOpts({
206
- bbox: prep.tel.bbox,
207
- width: prep.width,
208
- height: prep.height,
209
- config,
210
- source: { fps: prep.probe.fps.value, frames: prep.probe.frames },
211
- frames: prep.frames,
212
- planned: {
213
- overview: prep.overview,
214
- introOutro: prep.introOutro,
215
- hud: prep.hud,
216
- },
217
- });
218
- }
219
- function buildOkSummary(ctx, elapsedSec) {
220
- const { config, probe, tel, hud, introOutro, overview, tileStats } = ctx;
221
- const telemetry = telemetrySummary(tel);
222
- return {
223
- video: ctx.videoPath,
224
- out: ctx.outPath,
225
- status: 'ok',
226
- width: ctx.width,
227
- height: ctx.height,
228
- style: config.style,
229
- view: config.view,
230
- introFrames: introOutro.introN,
231
- outroFrames: introOutro.outroN,
232
- hud,
233
- // Field by field, not a spread: a TelemetrySummary rename must land here visibly, not silently drop a --json key.
234
- source: telemetry.source,
235
- method: telemetry.method,
236
- headingMode: telemetry.headingMode,
237
- fixes: telemetry.fixCount,
238
- noLock: telemetry.noLock,
239
- trackDistanceM: telemetry.trackDistanceM,
240
- frames: ctx.outFrames,
241
- fps: probe.fps.str,
242
- frameRange: ctx.frameRange ?? undefined,
243
- bbox: tel.bbox,
244
- zoom: overview.zoom,
245
- zoomFixed: config.zoom > 0,
246
- zoomOut: effectiveZoomOut(config),
247
- tilesDownloaded: tileStats.downloaded,
248
- verified: true,
249
- elapsedSec,
250
- };
251
- }
252
- async function verifyRenderedOutput(env) {
253
- const { ctx, deps, tools } = env;
254
- const verify = await deps.verifyOutput(tools, ctx.outPath, ctx.outFrames, ctx.probe.fps.value);
255
- if (!verify.ok) {
256
- throw new Error(`${ERR_OUTPUT_VERIFICATION}got ${verify.frames} frames @ ${verify.fps ?? 'unknown'}, ` +
257
- `expected ${ctx.outFrames} @ ${ctx.probe.fps.str}`);
258
- }
259
- ctx.log(ctx.frameRange
260
- ? 'verified: frame count and frame rate are 1:1 within the exported range'
261
- : 'verified: frame count and frame rate match the source');
262
- }
263
- async function renderToOutput(env) {
264
- const { ctx, deps, tools, options } = env;
265
- const html = buildPageHtml(recordingPageOpts(ctx, ctx.config));
266
- fs.mkdirSync(path.dirname(ctx.outPath), { recursive: true });
267
- await renderWithOutputCleanup(ctx.outPath, ctx.log, async () => {
268
- await deps.renderVideo({
269
- html,
270
- capture: ctx.config.capture,
271
- codec: ctx.config.codec,
272
- quality: ctx.config.quality,
273
- preset: ctx.config.preset,
274
- style: ctx.config.style,
275
- tileCache: ctx.config.tileCache,
276
- tools,
277
- width: ctx.width,
278
- height: ctx.height,
279
- frames: ctx.outFrames,
280
- frameStart: ctx.frameRange?.start ?? 0,
281
- fpsStr: ctx.probe.fps.str,
282
- workers: ctx.config.workers,
283
- outPath: ctx.outPath,
284
- browserPath: ctx.config.browser,
285
- signal: options.signal,
286
- log: ctx.log,
287
- onCapture: options.onCapture,
288
- });
289
- await verifyRenderedOutput(env);
290
- });
291
- }
292
- export function telemetryExportInput(prep) {
293
- return {
294
- source: prep.tel.source,
295
- headingMode: prep.tel.headingMode,
296
- frameCount: prep.probe.frames,
297
- protoFile: prep.protoFile,
298
- gimbalDevice: prep.gimbalDevice,
299
- frames: prep.frameValues,
300
- headingDeg: prep.tel.frames.map((frame) => frame.headingDeg),
301
- };
302
- }
303
- // The track formats read the fix-faithful records (which carry positions and
304
- // source times for every telemetry source); the .json document keeps its own
305
- // record stream.
306
- export function trackExportStream(prep) {
307
- return {
308
- records: prep.trackValues,
309
- fpsValue: prep.probe.fps.value,
310
- frameCount: prep.probe.frames,
311
- };
312
- }
313
- function writeTrackExport(file, prep, log) {
314
- // The export intentionally covers the whole recording: a frame range
315
- // limits the render, never this export.
316
- writeTrackFile(file, { document: telemetryExportInput(prep), track: trackExportStream(prep) }, null);
317
- log(`track: wrote ${file}`);
318
- }
319
- export async function processRecording(videoPath, config, log, outPath = outputPathFor(videoPath, config), options = {}) {
320
- const t0 = Date.now();
321
- const deps = resolveDeps(options.deps, config.tileCache);
322
- const tools = options.tools ?? resolveFfmpegTools(config);
323
- if (options.signal?.aborted)
324
- throw new Error(ERR_RENDER_CANCELED);
325
- const prep = await prepareSession(videoPath, config, log, {
326
- ...options,
327
- deps,
328
- tools,
329
- });
330
- if (config.trackOut) {
331
- writeTrackExport(config.trackOut, prep, log);
332
- }
333
- const tileStats = await tileWarmStage(deps, config, prep.overview, log);
334
- const range = resolveFrameRange(options.range, prep.probe.frames);
335
- const outFrames = range ? range.end - range.start + 1 : prep.probe.frames;
336
- const ctx = {
337
- ...prep,
338
- videoPath,
339
- outPath,
340
- config,
341
- log,
342
- outFrames,
343
- frameRange: range,
344
- tileStats,
345
- };
346
- await renderToOutput({ ctx, deps, tools, options });
347
- return buildOkSummary(ctx, Math.round((Date.now() - t0) / 1000));
348
- }
349
- export async function runBatch(videos, config, log, emit, options = {}) {
350
- const result = { ok: 0, skipped: 0, failed: 0 };
351
- const deps = resolveDeps(options.deps, config.tileCache);
352
- const tools = options.tools ?? resolveFfmpegTools(config);
353
- if (config.trackOut && videos.length > 1) {
354
- throw new Error('--track-out writes one file per run: give a single recording');
355
- }
356
- const plans = planOutputs(videos, config);
357
- function collisionWarning(base, plan) {
358
- if (plan.out !== plan.plain) {
359
- log(`warning: output name collision for ${base} - writing ${path.basename(plan.out)} instead`);
360
- }
361
- }
362
- async function maybeSkip(video, plan) {
363
- if (!(config.skipExisting && (await deps.outputMatchesSource(tools, video, plan.out)))) {
364
- return null;
365
- }
366
- log(`SKIP ${plan.out} (exists and matches the source)`);
367
- return 'skipped';
368
- }
369
- async function runOne(video, plan) {
370
- return processRecording(video, config, log, plan.out, { ...options, deps, tools });
371
- }
372
- for (const [idx, video] of videos.entries()) {
373
- const base = path.basename(video);
374
- log(`=== ${base} ===`);
375
- const plan = plans[idx];
376
- collisionWarning(base, plan);
377
- if ((await maybeSkip(video, plan)) !== null) {
378
- emit({ video, out: plan.out, status: 'skipped', elapsedSec: 0 });
379
- result.skipped++;
380
- continue;
381
- }
382
- try {
383
- const summary = await runOne(video, plan);
384
- emit(summary);
385
- log(`OK ${plan.out} (${summary.frames} frames @ ${summary.fps}, ${summary.elapsedSec} s)`);
386
- result.ok++;
387
- }
388
- catch (e) {
389
- const message = errorMessage(e);
390
- log(`ERROR ${base}: ${message}`);
391
- emit({
392
- video,
393
- out: plan.out,
394
- status: 'error',
395
- elapsedSec: 0,
396
- error: message,
397
- });
398
- result.failed++;
399
- }
400
- }
401
- return result;
402
- }