drone-path 0.13.0 → 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 (80) 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 -349
  9. package/app/ipc.d.mts +0 -44
  10. package/app/ipc.mjs +0 -237
  11. package/app/main.mjs +0 -369
  12. package/app/preload.cjs +0 -36
  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 -101
  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/desktop-i18n/generated/catalogs.js +0 -1230
  30. package/dist/desktop-i18n/messages.js +0 -47
  31. package/dist/errors.js +0 -34
  32. package/dist/exec-tool.js +0 -13
  33. package/dist/exportjob.js +0 -90
  34. package/dist/ffmpeg-tools.js +0 -56
  35. package/dist/ffmpeg.js +0 -98
  36. package/dist/frametime.js +0 -32
  37. package/dist/geo.js +0 -60
  38. package/dist/logging.js +0 -1
  39. package/dist/manual/anchors.js +0 -17
  40. package/dist/manual/build.js +0 -67
  41. package/dist/manual/cliref.js +0 -34
  42. package/dist/manual/links.js +0 -59
  43. package/dist/manual/markdown.js +0 -98
  44. package/dist/manual/model.js +0 -1
  45. package/dist/manual/module.js +0 -5
  46. package/dist/manual/nav.js +0 -11
  47. package/dist/manual/reference.js +0 -18
  48. package/dist/paths.js +0 -16
  49. package/dist/pipeline.js +0 -402
  50. package/dist/plan.js +0 -106
  51. package/dist/png.js +0 -32
  52. package/dist/protobuf-wire.js +0 -102
  53. package/dist/range.js +0 -50
  54. package/dist/recordings.js +0 -55
  55. package/dist/render-page.js +0 -85
  56. package/dist/render.js +0 -268
  57. package/dist/renderer/boot.js +0 -7
  58. package/dist/renderer/dom.js +0 -179
  59. package/dist/renderer/framemath.js +0 -30
  60. package/dist/renderer/scene.js +0 -388
  61. package/dist/renderer/theme.js +0 -82
  62. package/dist/renderer/tilesources.js +0 -38
  63. package/dist/renderer/trail.js +0 -42
  64. package/dist/restyle.js +0 -16
  65. package/dist/serve.js +0 -27
  66. package/dist/srt.js +0 -98
  67. package/dist/telemetry-json-schema.js +0 -18
  68. package/dist/telemetry-json.js +0 -126
  69. package/dist/telemetry-math.js +0 -267
  70. package/dist/telemetry-summary.js +0 -19
  71. package/dist/telemetry.js +0 -95
  72. package/dist/tilecache.js +0 -21
  73. package/dist/tiles.js +0 -155
  74. package/dist/track-format.js +0 -13
  75. package/dist/track-geojson.js +0 -44
  76. package/dist/track-gpx.js +0 -34
  77. package/dist/track-kml.js +0 -47
  78. package/dist/track-kmz.js +0 -68
  79. package/dist/track-write.js +0 -41
  80. package/dist/track.js +0 -79
@@ -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
- }
package/dist/plan.js DELETED
@@ -1,106 +0,0 @@
1
- import { project } from './geo.js';
2
- import { TILE_SOURCES } from './renderer/tilesources.js';
3
- const MIN_ZOOM = 2;
4
- const HOVER_ZOOM_FLOOR = 16;
5
- const MIN_TRACK_SPAN_PX = 80;
6
- const TILE_SIZE_PX = 256;
7
- /** The zoom levels the planner renders: the floor and the map style's tile maximum. */
8
- export function zoomLimits(style) {
9
- return { min: MIN_ZOOM, max: TILE_SOURCES[style].maxZoom || 19 };
10
- }
11
- function fitZoomToTrack(bbox, availW, availH, maxZoom) {
12
- for (let zoom = maxZoom; zoom >= MIN_ZOOM; zoom--) {
13
- const northWest = project(bbox.minLon, bbox.maxLat, zoom);
14
- const southEast = project(bbox.maxLon, bbox.minLat, zoom);
15
- const fits = southEast.x - northWest.x <= availW &&
16
- southEast.y - northWest.y <= availH;
17
- if (fits)
18
- return zoom;
19
- }
20
- return MIN_ZOOM;
21
- }
22
- function pullBackTinyTracks(zoom, bbox) {
23
- while (zoom > HOVER_ZOOM_FLOOR) {
24
- const northWest = project(bbox.minLon, bbox.maxLat, zoom);
25
- const southEast = project(bbox.maxLon, bbox.minLat, zoom);
26
- const spansEnough = southEast.x - northWest.x >= MIN_TRACK_SPAN_PX ||
27
- southEast.y - northWest.y >= MIN_TRACK_SPAN_PX;
28
- if (spansEnough)
29
- break;
30
- zoom--;
31
- }
32
- return zoom;
33
- }
34
- function tilesCovering(centerPx, trackSpanPx, zoom, width, height, follow, maxNativeZoom) {
35
- const tileZoom = maxNativeZoom
36
- ? Math.min(zoom, maxNativeZoom)
37
- : zoom;
38
- const scale = 2 ** (tileZoom - zoom);
39
- const halfW = (width + TILE_SIZE_PX + (follow ? trackSpanPx.x / 2 : 0)) * scale;
40
- const halfH = (height + TILE_SIZE_PX + (follow ? trackSpanPx.y / 2 : 0)) * scale;
41
- const maxTileIndex = 2 ** tileZoom - 1;
42
- const xMin = Math.max(0, Math.floor((centerPx.x * scale - halfW) / TILE_SIZE_PX));
43
- const xMax = Math.min(maxTileIndex, Math.floor((centerPx.x * scale + halfW) / TILE_SIZE_PX));
44
- const yMin = Math.max(0, Math.floor((centerPx.y * scale - halfH) / TILE_SIZE_PX));
45
- const yMax = Math.min(maxTileIndex, Math.floor((centerPx.y * scale + halfH) / TILE_SIZE_PX));
46
- const tiles = [];
47
- for (let x = xMin; x <= xMax; x++) {
48
- for (let y = yMin; y <= yMax; y++)
49
- tiles.push({ z: tileZoom, x, y });
50
- }
51
- return tiles;
52
- }
53
- export function computeOverview({ bbox, width, height, maxZoom = 19, zoomOut = 0, follow = false, maxNativeZoom = null, zoomOverride = 0, }) {
54
- const padX = Math.round(width * 0.08);
55
- const padY = Math.round(height * 0.08);
56
- const availW = Math.max(64, width - 2 * padX);
57
- const availH = Math.max(64, height - 2 * padY);
58
- let zoom;
59
- if (zoomOverride > 0) {
60
- zoom = Math.max(MIN_ZOOM, Math.min(maxZoom, Math.round(zoomOverride)));
61
- }
62
- else {
63
- zoom = pullBackTinyTracks(fitZoomToTrack(bbox, availW, availH, maxZoom), bbox);
64
- zoom = Math.max(MIN_ZOOM, zoom - Math.max(0, Math.floor(zoomOut)));
65
- }
66
- const northWest = project(bbox.minLon, bbox.maxLat, zoom);
67
- const southEast = project(bbox.maxLon, bbox.minLat, zoom);
68
- const centerPx = {
69
- x: (northWest.x + southEast.x) / 2,
70
- y: (northWest.y + southEast.y) / 2,
71
- };
72
- const trackSpanPx = {
73
- x: southEast.x - northWest.x,
74
- y: southEast.y - northWest.y,
75
- };
76
- return {
77
- centerPx,
78
- zoom,
79
- tiles: tilesCovering(centerPx, trackSpanPx, zoom, width, height, follow, maxNativeZoom),
80
- };
81
- }
82
- export function planView(bbox, width, height, config) {
83
- const src = TILE_SOURCES[config.style];
84
- return computeOverview({
85
- bbox,
86
- width,
87
- height,
88
- maxZoom: zoomLimits(config.style).max,
89
- maxNativeZoom: src.maxNativeZoom ?? null,
90
- zoomOut: config.zoomOut,
91
- zoomOverride: config.zoom,
92
- follow: config.view === 'follow',
93
- });
94
- }
95
- export function planIntroOutroFrames(config, source) {
96
- let introN = Math.max(0, Math.round(config.introSec * source.fps));
97
- let outroN = Math.max(0, Math.round(config.outroSec * source.fps));
98
- const budget = Math.max(2, Math.floor(source.frames / 2));
99
- const clamped = introN + outroN > budget;
100
- if (clamped) {
101
- const scale = budget / (introN + outroN);
102
- introN = Math.floor(introN * scale);
103
- outroN = Math.floor(outroN * scale);
104
- }
105
- return { introN, outroN, clamped };
106
- }