drone-path 0.9.0 → 0.11.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +16 -14
  3. package/THIRD-PARTY-NOTICES.md +7 -7
  4. package/app/ipc.d.mts +43 -0
  5. package/app/ipc.mjs +216 -0
  6. package/app/main.mjs +10 -204
  7. package/dist/appsession.js +34 -75
  8. package/dist/appstate.js +24 -21
  9. package/dist/buildinfo.js +9 -16
  10. package/dist/cammeta-decode.js +237 -0
  11. package/dist/cammeta.js +8 -247
  12. package/dist/cli.js +40 -32
  13. package/dist/config.js +333 -173
  14. package/dist/configfile.js +20 -7
  15. package/dist/errors.js +30 -0
  16. package/dist/exec-tool.js +13 -0
  17. package/dist/exportjob.js +7 -7
  18. package/dist/{fftools.js → ffmpeg-tools.js} +5 -4
  19. package/dist/{ff.js → ffmpeg.js} +14 -29
  20. package/dist/frametime.js +32 -0
  21. package/dist/geo.js +1 -1
  22. package/dist/manual/build.js +5 -10
  23. package/dist/manual/cliref.js +4 -1
  24. package/dist/manual/reference.js +6 -11
  25. package/dist/{run.js → pipeline.js} +100 -143
  26. package/dist/png.js +1 -18
  27. package/dist/{proto.js → protobuf-wire.js} +5 -5
  28. package/dist/range.js +3 -3
  29. package/dist/{page.js → render-page.js} +2 -2
  30. package/dist/render.js +25 -115
  31. package/dist/renderer/boot.js +2 -2
  32. package/dist/renderer/dom.js +32 -10
  33. package/dist/renderer/scene.js +14 -6
  34. package/dist/restyle.js +1 -1
  35. package/dist/serve.js +1 -31
  36. package/dist/srt.js +2 -2
  37. package/dist/telemetry-json-schema.js +6 -11
  38. package/dist/telemetry-json.js +46 -27
  39. package/dist/telemetry-math.js +3 -2
  40. package/dist/{summary.js → telemetry-summary.js} +4 -4
  41. package/dist/telemetry.js +32 -18
  42. package/dist/tiles.js +30 -86
  43. package/dist/track-format.js +13 -0
  44. package/dist/track-geojson.js +44 -0
  45. package/dist/track-gpx.js +34 -0
  46. package/dist/track-kml.js +47 -0
  47. package/dist/track-kmz.js +68 -0
  48. package/dist/track-write.js +41 -0
  49. package/dist/track.js +79 -0
  50. package/package.json +13 -14
  51. package/dist/tracing.js +0 -184
  52. /package/dist/{renderer/leaflet.js → logging.js} +0 -0
  53. /package/dist/{inputs.js → recordings.js} +0 -0
package/dist/telemetry.js CHANGED
@@ -1,7 +1,8 @@
1
+ import { ERR_NO_TELEMETRY } from './errors.js';
1
2
  import { parseSrt } from './srt.js';
2
3
  import { parseCamMeta } from './cammeta.js';
3
- import { findSrtSidecar } from './inputs.js';
4
- import { buildTelemetry } from './telemetry-math.js';
4
+ import { findSrtSidecar } from './recordings.js';
5
+ import { computeTelemetry } from './telemetry-math.js';
5
6
  function srtCueToFrameValues(cue) {
6
7
  return {
7
8
  lat: cue.fix?.lat ?? null,
@@ -33,6 +34,27 @@ function camSampleToFrameValues(sample) {
33
34
  };
34
35
  }
35
36
  async function loadSamples(tools, videoPath, durationSec) {
37
+ const cam = await parseCamMeta(tools, videoPath, durationSec, { keepAll: true });
38
+ if (cam) {
39
+ const fixSamples = cam.samples.filter((sample) => sample.fix !== null);
40
+ if (fixSamples.length === 0) {
41
+ throw new Error(`${ERR_NO_TELEMETRY}the CAM meta (DVTM) stream has no GPS fix pairs; ` +
42
+ 'the .SRT sidecar is only consulted when no CAM meta stream is present');
43
+ }
44
+ return {
45
+ samples: fixSamples,
46
+ source: 'cammeta',
47
+ method: cam.method,
48
+ noLock: cam.noLock,
49
+ frameValues: cam.method === 'dvtm-packets' ? cam.samples.map(camSampleToFrameValues) : [],
50
+ trackValues: cam.samples.map((sample) => ({
51
+ ...camSampleToFrameValues(sample),
52
+ tSec: sample.tSec,
53
+ })),
54
+ protoFile: cam.protoFile,
55
+ gimbalDevice: cam.gimbalDevice,
56
+ };
57
+ }
36
58
  const srtPath = findSrtSidecar(videoPath);
37
59
  if (srtPath) {
38
60
  const parsed = await parseSrt(srtPath);
@@ -50,31 +72,23 @@ async function loadSamples(tools, videoPath, durationSec) {
50
72
  method: 'srt-cues',
51
73
  noLock: parsed.noLock,
52
74
  frameValues: parsed.cues.map(srtCueToFrameValues),
75
+ trackValues: parsed.cues.map((cue) => ({
76
+ ...srtCueToFrameValues(cue),
77
+ tSec: cue.tSec,
78
+ })),
53
79
  protoFile: null,
54
80
  gimbalDevice: null,
55
81
  };
56
82
  }
57
- const cam = await parseCamMeta(tools, videoPath, durationSec, { keepAll: true });
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
- };
83
+ throw new Error(`${ERR_NO_TELEMETRY}no CAM meta (DVTM) stream and no .SRT sidecar`);
71
84
  }
72
85
  export async function loadTelemetry(videoPath, { frames, fpsValue, durationSec, tools, }) {
73
86
  const loaded = await loadSamples(tools, videoPath, durationSec);
74
- const { frameValues, protoFile, gimbalDevice, ...samples } = loaded;
87
+ const { frameValues, trackValues, protoFile, gimbalDevice, ...samples } = loaded;
75
88
  return {
76
- telemetry: buildTelemetry(samples, { frames, fpsValue }),
89
+ telemetry: computeTelemetry(samples, { frames, fpsValue }),
77
90
  frameValues,
91
+ trackValues,
78
92
  protoFile,
79
93
  gimbalDevice,
80
94
  };
package/dist/tiles.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
+ import PQueue from 'p-queue';
3
4
  import { errorMessage } from './errors.js';
4
5
  import { solidPng } from './png.js';
5
6
  import { tilePaths } from './tilecache.js';
@@ -12,24 +13,8 @@ const DOWNLOAD_WORKERS = 2;
12
13
  const REQUEST_INTERVAL_MS = 500;
13
14
  const RETRY_DELAY_MS = 500;
14
15
  const FETCH_TIMEOUT_MS = 20000;
15
- function createRequestGate() {
16
- let nextFreeAt = 0;
17
- let tail = Promise.resolve();
18
- return () => {
19
- const turn = tail.then(async () => {
20
- for (;;) {
21
- const now = Date.now();
22
- if (now >= nextFreeAt) {
23
- nextFreeAt = now + REQUEST_INTERVAL_MS;
24
- return;
25
- }
26
- await sleep(nextFreeAt - now);
27
- }
28
- });
29
- tail = turn.catch(() => { });
30
- return turn;
31
- };
32
- }
16
+ // p-queue starts higher priorities first, so 'now' jumps the queued pre-warm.
17
+ const TASK_PRIORITY = { now: 1, background: 0 };
33
18
  function tileUrl(style, tile) {
34
19
  const source = TILE_SOURCES[style];
35
20
  const subdomain = source.subdomains.length
@@ -44,18 +29,24 @@ function tileUrl(style, tile) {
44
29
  function canceledError(signal) {
45
30
  return new Error('tile download canceled', { cause: signal.reason });
46
31
  }
47
- async function downloadTile(url, acquire, signal) {
32
+ async function fetchBody(url, signal) {
33
+ const res = await fetch(url, {
34
+ headers: { 'User-Agent': USER_AGENT },
35
+ signal: signal
36
+ ? AbortSignal.any([AbortSignal.timeout(FETCH_TIMEOUT_MS), signal])
37
+ : AbortSignal.timeout(FETCH_TIMEOUT_MS),
38
+ });
39
+ return res.ok ? Buffer.from(await res.arrayBuffer()) : null;
40
+ }
41
+ async function downloadTile(queue, url, priority, signal) {
48
42
  for (let attempt = 0; attempt < DOWNLOAD_ATTEMPTS; attempt++) {
49
- await acquire();
50
43
  try {
51
- const res = await fetch(url, {
52
- headers: { 'User-Agent': USER_AGENT },
53
- signal: signal
54
- ? AbortSignal.any([AbortSignal.timeout(FETCH_TIMEOUT_MS), signal])
55
- : AbortSignal.timeout(FETCH_TIMEOUT_MS),
44
+ const body = await queue.add(() => fetchBody(url, signal), {
45
+ priority: TASK_PRIORITY[priority],
46
+ signal,
56
47
  });
57
- if (res.ok)
58
- return Buffer.from(await res.arrayBuffer());
48
+ if (body)
49
+ return body;
59
50
  }
60
51
  catch {
61
52
  if (signal?.aborted)
@@ -85,11 +76,11 @@ function createPlaceholderSource() {
85
76
  return png;
86
77
  };
87
78
  }
88
- async function fetchTileToCache(ctx, style, tile, signal) {
79
+ async function fetchTileToCache(ctx, style, tile, priority, signal) {
89
80
  const paths = tilePaths(ctx.cacheDir, style, tile);
90
81
  if (fs.existsSync(paths.file))
91
82
  return { file: paths.file, status: 'cached' };
92
- const body = await downloadTile(tileUrl(style, tile), ctx.acquire, signal);
83
+ const body = await downloadTile(ctx.queue, tileUrl(style, tile), priority, signal);
93
84
  if (body) {
94
85
  writeCacheFile(paths.file, body);
95
86
  return { file: paths.file, status: 'downloaded' };
@@ -98,36 +89,16 @@ async function fetchTileToCache(ctx, style, tile, signal) {
98
89
  return { file: paths.placeholder, status: 'failed' };
99
90
  }
100
91
  function createDownloader(cacheDir, placeholderPng) {
101
- const ctx = { cacheDir, acquire: createRequestGate(), placeholderPng };
92
+ const queue = new PQueue({
93
+ concurrency: DOWNLOAD_WORKERS,
94
+ intervalCap: 1,
95
+ interval: REQUEST_INTERVAL_MS,
96
+ // Sliding window: no more than intervalCap starts in any interval window,
97
+ // matching the old request gate's nextFreeAt semantics.
98
+ strict: true,
99
+ });
100
+ const ctx = { cacheDir, queue, placeholderPng };
102
101
  const inFlight = new Map();
103
- const queue = [];
104
- let active = 0;
105
- function pump() {
106
- while (active < DOWNLOAD_WORKERS) {
107
- const job = queue.shift();
108
- if (!job)
109
- break;
110
- if (job.signal?.aborted) {
111
- job.detach();
112
- job.fail(canceledError(job.signal));
113
- continue;
114
- }
115
- active++;
116
- void (async () => {
117
- try {
118
- job.settle(await fetchTileToCache(ctx, job.style, job.tile, job.signal));
119
- }
120
- catch (e) {
121
- job.fail(e);
122
- }
123
- finally {
124
- job.detach();
125
- active--;
126
- pump();
127
- }
128
- })();
129
- }
130
- }
131
102
  return {
132
103
  enqueue(style, tile, options = {}) {
133
104
  const priority = options.priority ?? 'background';
@@ -136,34 +107,7 @@ function createDownloader(cacheDir, placeholderPng) {
136
107
  const shared = inFlight.get(key);
137
108
  if (shared && shared.signal === options.signal)
138
109
  return shared.promise;
139
- const task = new Promise((resolve, reject) => {
140
- const job = {
141
- style,
142
- tile,
143
- signal: options.signal,
144
- settle: resolve,
145
- fail: reject,
146
- detach: () => { },
147
- };
148
- const signal = options.signal;
149
- if (signal) {
150
- const onAbort = () => {
151
- const at = queue.indexOf(job);
152
- if (at < 0)
153
- return;
154
- queue.splice(at, 1);
155
- job.detach();
156
- reject(canceledError(signal));
157
- };
158
- signal.addEventListener('abort', onAbort, { once: true });
159
- job.detach = () => signal.removeEventListener('abort', onAbort);
160
- }
161
- if (priority === 'now')
162
- queue.unshift(job);
163
- else
164
- queue.push(job);
165
- pump();
166
- });
110
+ const task = fetchTileToCache(ctx, style, tile, priority, options.signal);
167
111
  const entry = { promise: task, signal: options.signal };
168
112
  const clear = () => {
169
113
  if (inFlight.get(key) === entry)
@@ -0,0 +1,13 @@
1
+ // The --track-out vocabulary: the file extension alone selects the track
2
+ // format, shared by the CLI writer and the desktop save request. The one
3
+ // values list is both the vocabulary and the extension set.
4
+ export const TRACK_FORMAT_VALUES = ['gpx', 'geojson', 'kml', 'kmz', 'json'];
5
+ export function trackFormatOf(file) {
6
+ const match = /\.([^.\\/]+)$/.exec(file);
7
+ const ext = match ? match[1].toLowerCase() : '';
8
+ const format = TRACK_FORMAT_VALUES.find((candidate) => candidate === ext);
9
+ if (!format) {
10
+ throw new Error(`unsupported track file extension: ${file} (use .gpx, .geojson, .kml, .kmz or .json)`);
11
+ }
12
+ return format;
13
+ }
@@ -0,0 +1,44 @@
1
+ // Pure GeoJSON serializer (RFC 7946): one MultiLineString line per track
2
+ // segment, [lon, lat] or [lon, lat, altM] positions, and the QGIS
3
+ // coordinateProperties.times convention only where every vertex carries
4
+ // trustworthy UTC. Assembled with fixed formatting and key order, so identical
5
+ // input yields identical bytes.
6
+ import { isoUtc } from './track.js';
7
+ function position(vertex) {
8
+ return vertex.altM !== null
9
+ ? `[${vertex.lon}, ${vertex.lat}, ${vertex.altM}]`
10
+ : `[${vertex.lon}, ${vertex.lat}]`;
11
+ }
12
+ function oneLineList(items) {
13
+ return items.length > 0 ? `[${items.join(', ')}]` : '[]';
14
+ }
15
+ function itemLines(indents, itemsBySegment) {
16
+ const lines = [];
17
+ itemsBySegment.forEach((items, index) => {
18
+ const last = index === itemsBySegment.length - 1;
19
+ lines.push(`${indents}${oneLineList(items)}${last ? '' : ','}`);
20
+ });
21
+ return lines;
22
+ }
23
+ export function serializeGeoJson(segments) {
24
+ const allTimed = segments.length > 0 &&
25
+ segments.every((segment) => segment.every((vertex) => vertex.timeMs !== null));
26
+ const lines = [
27
+ '{',
28
+ ' "type": "Feature",',
29
+ ' "geometry": {',
30
+ ' "type": "MultiLineString",',
31
+ ' "coordinates": [',
32
+ ];
33
+ lines.push(...itemLines(' ', segments.map((s) => s.map(position))));
34
+ lines.push(' ]', ' },');
35
+ if (allTimed) {
36
+ lines.push(' "properties": {', ' "coordinateProperties": {', ' "times": [');
37
+ lines.push(...itemLines(' ', segments.map((segment) => segment.map((vertex) => JSON.stringify(isoUtc(vertex.timeMs))))));
38
+ lines.push(' ]', ' }', ' }', '}', '');
39
+ }
40
+ else {
41
+ lines.push(' "properties": {}', '}', '');
42
+ }
43
+ return lines.join('\n');
44
+ }
@@ -0,0 +1,34 @@
1
+ // Pure GPX 1.1 serializer: one <trkseg> per track segment, altitude as <ele>,
2
+ // and a <time> only where the vertex carries trustworthy UTC. No metadata
3
+ // wall-clock or version strings, so identical input yields identical bytes.
4
+ import { isoUtc } from './track.js';
5
+ function trkptLines(vertex) {
6
+ const children = [];
7
+ if (vertex.altM !== null)
8
+ children.push(`<ele>${vertex.altM}</ele>`);
9
+ if (vertex.timeMs !== null)
10
+ children.push(`<time>${isoUtc(vertex.timeMs)}</time>`);
11
+ const open = `<trkpt lat="${vertex.lat}" lon="${vertex.lon}">`;
12
+ if (children.length === 0)
13
+ return [` <trkpt lat="${vertex.lat}" lon="${vertex.lon}"/>`];
14
+ return [
15
+ ` ${open}`,
16
+ ...children.map((child) => ` ${child}`),
17
+ ' </trkpt>',
18
+ ];
19
+ }
20
+ export function serializeGpx(segments) {
21
+ const lines = [
22
+ '<?xml version="1.0" encoding="UTF-8"?>',
23
+ '<gpx version="1.1" creator="drone-path" xmlns="http://www.topografix.com/GPX/1/1">',
24
+ ' <trk>',
25
+ ];
26
+ for (const segment of segments) {
27
+ lines.push(' <trkseg>');
28
+ for (const vertex of segment)
29
+ lines.push(...trkptLines(vertex));
30
+ lines.push(' </trkseg>');
31
+ }
32
+ lines.push(' </trk>', '</gpx>', '');
33
+ return lines.join('\n');
34
+ }
@@ -0,0 +1,47 @@
1
+ // Pure KML 2.2 serializer: one placemark per track segment. A segment whose
2
+ // vertices all carry trustworthy UTC becomes a timed gx:Track (the Google
3
+ // Earth flythrough); anything else becomes a plain LineString. Coordinates are
4
+ // always 3-tuples in meters: a segment with any unknown altitude uses 0 there
5
+ // and clamps the placemark to the ground, while fully known segments fly at
6
+ // absolute (mean sea level) altitude. No wall-clock or version strings, so
7
+ // identical input yields identical bytes.
8
+ import { isoUtc } from './track.js';
9
+ function altitudeMode(segment) {
10
+ return segment.every((vertex) => vertex.altM !== null) ? 'absolute' : 'clampToGround';
11
+ }
12
+ // One coordinate rendering for both KML spellings: space-separated inside
13
+ // <gx:coord>, comma-separated inside <coordinates>.
14
+ function coordOf(vertex, separator) {
15
+ return `${vertex.lon}${separator}${vertex.lat}${separator}${vertex.altM ?? 0}`;
16
+ }
17
+ function placemarkLines(segment) {
18
+ const mode = altitudeMode(segment);
19
+ const timed = segment.every((vertex) => vertex.timeMs !== null);
20
+ const lines = [' <Placemark>'];
21
+ if (timed) {
22
+ lines.push(' <gx:Track>', ` <altitudeMode>${mode}</altitudeMode>`);
23
+ for (const vertex of segment) {
24
+ lines.push(` <when>${isoUtc(vertex.timeMs)}</when>`);
25
+ lines.push(` <gx:coord>${coordOf(vertex, ' ')}</gx:coord>`);
26
+ }
27
+ lines.push(' </gx:Track>');
28
+ }
29
+ else {
30
+ lines.push(' <LineString>', ` <altitudeMode>${mode}</altitudeMode>`);
31
+ lines.push(` <coordinates>${segment.map((vertex) => coordOf(vertex, ',')).join(' ')}</coordinates>`);
32
+ lines.push(' </LineString>');
33
+ }
34
+ lines.push(' </Placemark>');
35
+ return lines;
36
+ }
37
+ export function serializeKml(segments) {
38
+ const lines = [
39
+ '<?xml version="1.0" encoding="UTF-8"?>',
40
+ '<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">',
41
+ ' <Document>',
42
+ ];
43
+ for (const segment of segments)
44
+ lines.push(...placemarkLines(segment));
45
+ lines.push(' </Document>', '</kml>', '');
46
+ return lines.join('\n');
47
+ }
@@ -0,0 +1,68 @@
1
+ // Deterministic KMZ packaging: a zip archive with exactly one stored (method 0)
2
+ // `doc.kml` entry and fixed zip metadata - 1980-01-01 00:00 entry timestamps,
3
+ // no extra fields, no comments. Stored entries keep the bytes independent of
4
+ // any compressor version, so the same KML always produces the same KMZ.
5
+ import { crc32 } from 'node:zlib';
6
+ const ENTRY_NAME = 'doc.kml';
7
+ // The zip epoch (1980-01-01 00:00:00) in MS-DOS date/time fields.
8
+ const DOS_DATE_1980_01_01 = 0x0021;
9
+ const DOS_TIME_MIDNIGHT = 0x0000;
10
+ function localHeader(name, data) {
11
+ const header = Buffer.alloc(30);
12
+ header.writeUInt32LE(0x04034b50, 0);
13
+ header.writeUInt16LE(20, 4); // version needed: 2.0
14
+ header.writeUInt16LE(0, 6); // flags
15
+ header.writeUInt16LE(0, 8); // method: stored
16
+ header.writeUInt16LE(DOS_TIME_MIDNIGHT, 10);
17
+ header.writeUInt16LE(DOS_DATE_1980_01_01, 12);
18
+ header.writeUInt32LE(crc32(data), 14);
19
+ header.writeUInt32LE(data.length, 18);
20
+ header.writeUInt32LE(data.length, 22);
21
+ header.writeUInt16LE(name.length, 26);
22
+ header.writeUInt16LE(0, 28); // extra field length
23
+ return Buffer.concat([header, name, data]);
24
+ }
25
+ function centralDirectoryEntry(name, data, offset) {
26
+ const entry = Buffer.alloc(46);
27
+ entry.writeUInt32LE(0x02014b50, 0);
28
+ entry.writeUInt16LE(20, 4); // version made by: 2.0, MS-DOS
29
+ entry.writeUInt16LE(20, 6); // version needed: 2.0
30
+ entry.writeUInt16LE(0, 8); // flags
31
+ entry.writeUInt16LE(0, 10); // method: stored
32
+ entry.writeUInt16LE(DOS_TIME_MIDNIGHT, 12);
33
+ entry.writeUInt16LE(DOS_DATE_1980_01_01, 14);
34
+ entry.writeUInt32LE(crc32(data), 16);
35
+ entry.writeUInt32LE(data.length, 20);
36
+ entry.writeUInt32LE(data.length, 24);
37
+ entry.writeUInt16LE(name.length, 28);
38
+ entry.writeUInt16LE(0, 30); // extra field length
39
+ entry.writeUInt16LE(0, 32); // comment length
40
+ entry.writeUInt16LE(0, 34); // disk number start
41
+ entry.writeUInt16LE(0, 36); // internal attributes
42
+ entry.writeUInt32LE(0, 38); // external attributes
43
+ entry.writeUInt32LE(offset, 42);
44
+ return Buffer.concat([entry, name]);
45
+ }
46
+ function endOfCentralDirectory(entryCount, cdSize, cdOffset) {
47
+ const eocd = Buffer.alloc(22);
48
+ eocd.writeUInt32LE(0x06054b50, 0);
49
+ eocd.writeUInt16LE(0, 4); // disk number
50
+ eocd.writeUInt16LE(0, 6); // disk with central directory
51
+ eocd.writeUInt16LE(entryCount, 8);
52
+ eocd.writeUInt16LE(entryCount, 10);
53
+ eocd.writeUInt32LE(cdSize, 12);
54
+ eocd.writeUInt32LE(cdOffset, 16);
55
+ eocd.writeUInt16LE(0, 20); // comment length
56
+ return eocd;
57
+ }
58
+ export function kmzBytes(kml) {
59
+ const name = Buffer.from(ENTRY_NAME, 'utf8');
60
+ const data = Buffer.from(kml, 'utf8');
61
+ const local = localHeader(name, data);
62
+ const central = centralDirectoryEntry(name, data, 0);
63
+ return Buffer.concat([
64
+ local,
65
+ central,
66
+ endOfCentralDirectory(1, central.length, local.length),
67
+ ]);
68
+ }
@@ -0,0 +1,41 @@
1
+ // The imperative shell for track exports: routes one export input to the
2
+ // format its file extension selects and writes the bytes. The .json format is
3
+ // the existing telemetry document, byte-for-byte unchanged (it is segmented
4
+ // and written by the very functions the --telemetry-json export has used);
5
+ // the track formats select their records by source time against the range.
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+ import { buildTelemetryDocument, segmentTelemetryInput, serializeTelemetryDocument, writeTelemetryDocument, } from './telemetry-json.js';
9
+ import { serializeGeoJson } from './track-geojson.js';
10
+ import { serializeGpx } from './track-gpx.js';
11
+ import { serializeKml } from './track-kml.js';
12
+ import { kmzBytes } from './track-kmz.js';
13
+ import { trackFormatOf } from './track-format.js';
14
+ import { buildTrack, selectTrackRecords } from './track.js';
15
+ export function trackFileBytes(file, input, range) {
16
+ const format = trackFormatOf(file);
17
+ if (format === 'json') {
18
+ return serializeTelemetryDocument(buildTelemetryDocument(segmentTelemetryInput(input.document, range)));
19
+ }
20
+ const track = buildTrack(selectTrackRecords(input.track, range));
21
+ switch (format) {
22
+ case 'gpx':
23
+ return serializeGpx(track);
24
+ case 'geojson':
25
+ return serializeGeoJson(track);
26
+ case 'kml':
27
+ return serializeKml(track);
28
+ case 'kmz':
29
+ return kmzBytes(serializeKml(track));
30
+ }
31
+ }
32
+ export function writeTrackFile(file, input, range) {
33
+ const format = trackFormatOf(file);
34
+ fs.mkdirSync(path.dirname(file), { recursive: true });
35
+ if (format === 'json') {
36
+ // Delegated so the telemetry document bytes can never drift.
37
+ writeTelemetryDocument(file, segmentTelemetryInput(input.document, range));
38
+ return;
39
+ }
40
+ fs.writeFileSync(file, trackFileBytes(file, input, range));
41
+ }
package/dist/track.js ADDED
@@ -0,0 +1,79 @@
1
+ // The flight track model the pure serializers consume: vertices at decoded
2
+ // GPS fixes, telemetry gaps breaking the line, absolute/GPS altitude, and a
3
+ // time only where the source carries trustworthy UTC. Built from the same
4
+ // per-source-frame records as the telemetry JSON document, so the CLI and the
5
+ // desktop app export byte-identical tracks for the same records.
6
+ import { resolveFrameRange } from './config.js';
7
+ // The one rendering of a vertex's timeMs shared by the GPX, GeoJSON and KML
8
+ // serializers: UTC ISO-8601, never a relative or zone-less clock.
9
+ export function isoUtc(timeMs) {
10
+ return new Date(timeMs).toISOString();
11
+ }
12
+ // Time policy: a vertex carries a time only where the source provides
13
+ // trustworthy UTC. Neither telemetry source does, measured against real
14
+ // footage: the DVTM gimbal device timestamp is milliseconds since power-up
15
+ // (34229 ms at clip start, spanning the clip - not an epoch), and the .SRT cue
16
+ // wall-clock has no time zone. A relative or zone-less clock is never exported
17
+ // as UTC, so no times appear anywhere today. A future source with real UTC
18
+ // epoch milliseconds turns on times here and nowhere else.
19
+ function timeOf(row) {
20
+ void row;
21
+ return null;
22
+ }
23
+ function altitudeOf(row) {
24
+ if (row.altAbs !== null && row.altAbs !== undefined)
25
+ return row.altAbs;
26
+ if (row.gpsAltMm !== null && row.gpsAltMm !== undefined)
27
+ return row.gpsAltMm / 1000;
28
+ return null;
29
+ }
30
+ function vertexOf(row) {
31
+ return {
32
+ lat: row.lat,
33
+ lon: row.lng,
34
+ altM: altitudeOf(row),
35
+ timeMs: timeOf(row),
36
+ };
37
+ }
38
+ /**
39
+ * Splits decoded records into track segments: one vertex per record with a
40
+ * GPS fix, a new segment after every run of records without one. Nothing is
41
+ * interpolated or bridged across a gap.
42
+ */
43
+ export function buildTrack(rows) {
44
+ const segments = [];
45
+ let current = [];
46
+ for (const row of rows) {
47
+ const fixed = row.lat !== null && row.lat !== undefined && row.lng !== null && row.lng !== undefined;
48
+ if (!fixed) {
49
+ if (current.length > 0) {
50
+ segments.push(current);
51
+ current = [];
52
+ }
53
+ continue;
54
+ }
55
+ current.push(vertexOf(row));
56
+ }
57
+ if (current.length > 0)
58
+ segments.push(current);
59
+ return segments;
60
+ }
61
+ function frameOf(record, stream) {
62
+ // The final sample of a spread sample stream sits at exactly the clip
63
+ // duration - it belongs to the last frame, never past it.
64
+ return Math.min(Math.round(record.tSec * stream.fpsValue), stream.frameCount - 1);
65
+ }
66
+ /**
67
+ * Selects the records for a frame range (inclusive bounds) by their source
68
+ * time; a null range keeps every record, however many there are per frame.
69
+ * Invalid and out-of-bounds ranges are rejected like on the document path.
70
+ */
71
+ export function selectTrackRecords(stream, range) {
72
+ const span = resolveFrameRange(range, stream.frameCount);
73
+ if (!span)
74
+ return stream.records;
75
+ return stream.records.filter((record) => {
76
+ const frame = frameOf(record, stream);
77
+ return frame >= span.start && frame <= span.end;
78
+ });
79
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "drone-path",
3
- "version": "0.9.0",
4
- "description": "Render flight-path map overlay videos (exactly the source frame rate and frame count) from DJI drone recordings - telemetry from the .SRT sidecar or the embedded CAM-meta (DVTM) stream.",
3
+ "version": "0.11.0",
4
+ "description": "Render flight-path map overlay videos (exactly the source frame rate and frame count) from DJI drone recordings - telemetry from the embedded CAM-meta (DVTM) stream or the .SRT sidecar.",
5
5
  "type": "module",
6
6
  "main": "app/main.mjs",
7
7
  "bin": {
@@ -61,13 +61,10 @@
61
61
  },
62
62
  "homepage": "https://github.com/MrManny/drone-path#readme",
63
63
  "dependencies": {
64
- "@opentelemetry/api": "~1.10.0",
65
- "@opentelemetry/exporter-trace-otlp-proto": "~0.301.0",
66
- "@opentelemetry/resources": "~3.1.0",
67
- "@opentelemetry/sdk-trace": "~3.1.0",
68
- "commander": "~15.0.0",
64
+ "commander": "~15.1.0",
69
65
  "electron-updater": "~6.8.11",
70
66
  "leaflet": "~1.9.4",
67
+ "p-queue": "~10.0.0",
71
68
  "playwright-core": "~1.65.0",
72
69
  "zod": "~4.6.7"
73
70
  },
@@ -77,24 +74,26 @@
77
74
  "devDependencies": {
78
75
  "@changesets/cli": "~3.0.3",
79
76
  "@eslint/js": "~10.0.1",
80
- "@next/eslint-plugin-next": "~16.4.3",
77
+ "@next/eslint-plugin-next": "~16.4.6",
81
78
  "@testing-library/react": "~16.3.3",
82
- "@testing-library/user-event": "~14.6.8",
79
+ "@testing-library/user-event": "~14.6.10",
80
+ "@types/leaflet": "~1.9.22",
83
81
  "@types/node": "~24.19.2",
84
82
  "@types/react": "~19.3.0",
85
83
  "@types/react-dom": "~19.3.0",
86
- "concurrently": "~10.0.6",
84
+ "concurrently": "~10.0.7",
87
85
  "electron": "~45.2.1",
88
86
  "electron-builder": "~26.18.0",
89
87
  "eslint": "~10.14.0",
90
88
  "eslint-plugin-react-hooks": "~7.1.1",
91
- "jsdom": "~31.0.0",
92
- "marked": "~18.1.3",
93
- "next": "~16.4.3",
89
+ "jsdom": "~31.0.1",
90
+ "lucide-react": "~1.72.0",
91
+ "marked": "~18.2.0",
92
+ "next": "~16.4.6",
94
93
  "react": "~19.3.1",
95
94
  "react-dom": "~19.3.1",
96
95
  "typescript": "~6.0.3",
97
- "typescript-eslint": "~8.72.1",
96
+ "typescript-eslint": "~8.72.2",
98
97
  "vitest": "~5.1.0",
99
98
  "wait-on": "~9.5.1"
100
99
  },