drone-path 0.10.0 → 0.11.1

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 (48) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +16 -11
  3. package/app/ipc.d.mts +43 -0
  4. package/app/ipc.mjs +92 -54
  5. package/app/main.mjs +6 -6
  6. package/dist/appsession.js +17 -24
  7. package/dist/appstate.js +2 -1
  8. package/dist/buildinfo.js +9 -16
  9. package/dist/cammeta-decode.js +237 -0
  10. package/dist/cammeta.js +4 -242
  11. package/dist/cli.js +37 -11
  12. package/dist/config.js +181 -82
  13. package/dist/configfile.js +20 -7
  14. package/dist/errors.js +30 -0
  15. package/dist/exec-tool.js +13 -0
  16. package/dist/exportjob.js +7 -7
  17. package/dist/{fftools.js → ffmpeg-tools.js} +5 -4
  18. package/dist/{ff.js → ffmpeg.js} +12 -10
  19. package/dist/geo.js +1 -1
  20. package/dist/logging.js +1 -0
  21. package/dist/manual/build.js +5 -10
  22. package/dist/manual/cliref.js +4 -1
  23. package/dist/manual/reference.js +6 -11
  24. package/dist/{run.js → pipeline.js} +59 -39
  25. package/dist/{proto.js → protobuf-wire.js} +5 -5
  26. package/dist/range.js +3 -3
  27. package/dist/{page.js → render-page.js} +2 -2
  28. package/dist/render.js +5 -18
  29. package/dist/renderer/boot.js +2 -2
  30. package/dist/renderer/dom.js +32 -10
  31. package/dist/renderer/scene.js +14 -6
  32. package/dist/restyle.js +1 -1
  33. package/dist/serve.js +1 -31
  34. package/dist/srt.js +2 -2
  35. package/dist/telemetry-json-schema.js +6 -11
  36. package/dist/telemetry-json.js +13 -0
  37. package/dist/telemetry-math.js +1 -1
  38. package/dist/{summary.js → telemetry-summary.js} +4 -4
  39. package/dist/telemetry.js +16 -6
  40. package/dist/track-format.js +13 -0
  41. package/dist/track-geojson.js +44 -0
  42. package/dist/track-gpx.js +34 -0
  43. package/dist/track-kml.js +47 -0
  44. package/dist/track-kmz.js +68 -0
  45. package/dist/track-write.js +41 -0
  46. package/dist/track.js +79 -0
  47. package/package.json +8 -8
  48. /package/dist/{inputs.js → recordings.js} +0 -0
@@ -34,15 +34,18 @@ class SceneState {
34
34
  decor;
35
35
  altEl = null;
36
36
  speedEl = null;
37
+ /** Chip container: inside the map frame for exports, or an external strip. */
38
+ hudRoot;
37
39
  curIdx = 0;
38
- constructor(host, firstData, L) {
40
+ constructor(host, firstData, L, hudHost) {
39
41
  this.host = host;
40
42
  this.data = firstData;
41
43
  this.L = L;
42
44
  host.classList.add(this.scopeClass);
43
45
  this.styleEl = document.createElement('style');
44
46
  document.head.appendChild(this.styleEl);
45
- host.innerHTML = mapMarkup(firstData.hud, firstData.attribution);
47
+ host.innerHTML = mapMarkup(hudHost ? null : firstData.hud, firstData.attribution);
48
+ this.hudRoot = hudHost ?? el(host, '#hud');
46
49
  this.attrEl = el(host, '#attr');
47
50
  this.applyChrome();
48
51
  this.mapEl = el(host, '#map');
@@ -94,6 +97,9 @@ class SceneState {
94
97
  applyChrome() {
95
98
  this.styleEl.textContent = sceneCss(TILE_SOURCES[this.data.style], themeFor(this.data.style, this.data.trailColor), this.data.width, this.data.height, this.scale(), this.scopeClass);
96
99
  this.attrEl.innerHTML = this.data.attribution;
100
+ // The compact map card truncates the credit to one line; the hover title
101
+ // carries the full text wherever the browser can show it.
102
+ this.attrEl.title = this.attrEl.textContent ?? '';
97
103
  quietAttributionLinks(this.attrEl);
98
104
  }
99
105
  layoutMap() {
@@ -236,9 +242,11 @@ class SceneState {
236
242
  this.decor = this.buildDecor();
237
243
  }
238
244
  rebuildHud() {
239
- el(this.host, '#hud').innerHTML = hudMarkup(this.data.hud);
240
- this.altEl = this.host.querySelector('#chip-alt .num');
241
- this.speedEl = this.host.querySelector('#chip-speed .num');
245
+ // Scoped to the chip container so an external strip and a second scene
246
+ // (the export preview) can never cross-write.
247
+ this.hudRoot.innerHTML = hudMarkup(this.data.hud);
248
+ this.altEl = this.hudRoot.querySelector('#chip-alt .num');
249
+ this.speedEl = this.hudRoot.querySelector('#chip-speed .num');
242
250
  if (this.decor.arrowEl) {
243
251
  this.decor.arrowEl.style.display = this.data.hud.heading ? '' : 'none';
244
252
  }
@@ -330,5 +338,5 @@ class SceneState {
330
338
  }
331
339
  }
332
340
  export function createScene(host, firstData, deps) {
333
- return new SceneState(host, firstData, deps.L);
341
+ return new SceneState(host, firstData, deps.L, deps.hudHost);
334
342
  }
package/dist/restyle.js CHANGED
@@ -1,4 +1,4 @@
1
- import { buildSceneData, planPageOpts } from './page.js';
1
+ import { buildSceneData, planPageOpts } from './render-page.js';
2
2
  export function restyleSceneData(prev, config, meta, size = { width: prev.width, height: prev.height }) {
3
3
  const planned = planPageOpts({
4
4
  bbox: meta.bbox,
package/dist/serve.js CHANGED
@@ -1,10 +1,8 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { createRequire } from 'node:module';
4
- import { pipeline } from 'node:stream';
5
4
  import { fileURLToPath } from 'node:url';
6
- import { mimeFor, resolveAsset } from './assets.js';
7
- import { rangePlan } from './range.js';
5
+ import { resolveAsset } from './assets.js';
8
6
  const require_ = createRequire(import.meta.url);
9
7
  const LEAFLET_DIR = path.dirname(require_.resolve('leaflet/dist/leaflet.js'));
10
8
  export const RENDERER_DIR = fileURLToPath(new URL('./renderer/', import.meta.url));
@@ -27,31 +25,3 @@ export function serveAsset(url, res, routes) {
27
25
  res.end('not found');
28
26
  return true;
29
27
  }
30
- export function serveFileWithRange(req, res, filePath) {
31
- let size;
32
- try {
33
- size = fs.statSync(filePath).size;
34
- }
35
- catch {
36
- res.writeHead(404, { 'Content-Type': 'text/plain' });
37
- res.end('not found');
38
- return Promise.resolve();
39
- }
40
- const mime = mimeFor(filePath);
41
- const plan = rangePlan(req.headers['range'], size, mime);
42
- res.writeHead(plan.status, plan.headers);
43
- if (plan.status === 416) {
44
- res.end(plan.body);
45
- return Promise.resolve();
46
- }
47
- if (req.method === 'HEAD') {
48
- res.end();
49
- return Promise.resolve();
50
- }
51
- const stream = plan.status === 206
52
- ? fs.createReadStream(filePath, { start: plan.span.start, end: plan.span.end })
53
- : fs.createReadStream(filePath);
54
- return new Promise((resolve) => {
55
- pipeline(stream, res, () => resolve());
56
- });
57
- }
package/dist/srt.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { readFile } from 'node:fs/promises';
2
- import { gpsFix } from './geo.js';
2
+ import { gpsFixOrNull } from './geo.js';
3
3
  const RX_TIMING = /^(\d{2}):(\d{2}):(\d{2})[,.](\d{3})\s*-->/;
4
4
  const RX_LATLON = /\[latitude:\s*(-?\d+\.?\d*)\]\s*\[longitude:\s*(-?\d+\.?\d*)\]/;
5
5
  const RX_ALT = /\[rel_alt:\s*(-?\d+\.?\d*)\s+abs_alt:\s*(-?\d+\.?\d*)\]/;
@@ -65,7 +65,7 @@ export function parseSrtText(text) {
65
65
  const latLon = RX_LATLON.exec(line);
66
66
  if (latLon && !cueSawLatLon) {
67
67
  cueSawLatLon = true;
68
- const fix = gpsFix(parseNumber(latLon[1]), parseNumber(latLon[2]));
68
+ const fix = gpsFixOrNull(parseNumber(latLon[1]), parseNumber(latLon[2]));
69
69
  if (fix !== null) {
70
70
  cue.fix = fix;
71
71
  }
@@ -1,23 +1,18 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
+ import { runToolMain } from './errors.js';
4
5
  import { generateTelemetryJsonSchema } from './telemetry-json.js';
5
6
  export function writeTelemetryJsonSchema(file) {
6
7
  fs.mkdirSync(path.dirname(file), { recursive: true });
7
8
  fs.writeFileSync(file, generateTelemetryJsonSchema());
8
9
  }
9
10
  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
- }
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`);
20
15
  }
21
16
  if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
22
- main();
17
+ void runToolMain(main);
23
18
  }
@@ -1,6 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { z } from 'zod';
4
+ import { resolveFrameRange } from './config.js';
4
5
  export const TELEMETRY_JSON_SCHEMA_VERSION = 1;
5
6
  const GimbalDeviceSchema = z.strictObject({
6
7
  id: z.int(),
@@ -82,6 +83,18 @@ function buildRecord(input, index) {
82
83
  copyValue(record, key, row[key]);
83
84
  return record;
84
85
  }
86
+ export function segmentTelemetryInput(input, range) {
87
+ const segment = resolveFrameRange(range, input.frameCount);
88
+ if (!segment)
89
+ return input;
90
+ return {
91
+ ...input,
92
+ frameCount: segment.end - segment.start + 1,
93
+ frames: input.frames.slice(segment.start, segment.end + 1),
94
+ headingDeg: input.headingDeg.slice(segment.start, segment.end + 1),
95
+ frameStart: segment.start,
96
+ };
97
+ }
85
98
  export function buildTelemetryDocument(input) {
86
99
  if (input.headingDeg.length !== input.frameCount) {
87
100
  throw new Error('telemetry JSON: heading count does not match the frame count');
@@ -243,7 +243,7 @@ function bridgeMissingFramePositions(frameData) {
243
243
  trail--;
244
244
  }
245
245
  }
246
- export function buildTelemetry(loaded, timing) {
246
+ export function computeTelemetry(loaded, timing) {
247
247
  const { samples, source, method, noLock } = loaded;
248
248
  const fixes = fixRefs(samples);
249
249
  if (fixes.length < 2)
@@ -3,15 +3,15 @@ export function telemetrySummary(tel) {
3
3
  source: tel.source,
4
4
  method: tel.method,
5
5
  headingMode: tel.headingMode,
6
- fixes: tel.fixCount,
6
+ fixCount: tel.fixCount,
7
7
  noLock: tel.noLock,
8
8
  trackDistanceM: Math.round(tel.trackDistanceM),
9
9
  };
10
10
  }
11
- export function fixesLabel(fixes) {
12
- return `${fixes} fixes`;
11
+ export function fixCountLabel(fixCount) {
12
+ return `${fixCount} fixes`;
13
13
  }
14
- export function noLockCuesLabel(noLock) {
14
+ export function noLockCountLabel(noLock) {
15
15
  return `${noLock} no-lock cues`;
16
16
  }
17
17
  export function trackDistanceLabel(trackDistanceM) {
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,
@@ -37,7 +38,7 @@ async function loadSamples(tools, videoPath, durationSec) {
37
38
  if (cam) {
38
39
  const fixSamples = cam.samples.filter((sample) => sample.fix !== null);
39
40
  if (fixSamples.length === 0) {
40
- throw new Error('no telemetry found: the CAM meta (DVTM) stream has no GPS fix pairs; ' +
41
+ throw new Error(`${ERR_NO_TELEMETRY}the CAM meta (DVTM) stream has no GPS fix pairs; ` +
41
42
  'the .SRT sidecar is only consulted when no CAM meta stream is present');
42
43
  }
43
44
  return {
@@ -46,6 +47,10 @@ async function loadSamples(tools, videoPath, durationSec) {
46
47
  method: cam.method,
47
48
  noLock: cam.noLock,
48
49
  frameValues: cam.method === 'dvtm-packets' ? cam.samples.map(camSampleToFrameValues) : [],
50
+ trackValues: cam.samples.map((sample) => ({
51
+ ...camSampleToFrameValues(sample),
52
+ tSec: sample.tSec,
53
+ })),
49
54
  protoFile: cam.protoFile,
50
55
  gimbalDevice: cam.gimbalDevice,
51
56
  };
@@ -67,18 +72,23 @@ async function loadSamples(tools, videoPath, durationSec) {
67
72
  method: 'srt-cues',
68
73
  noLock: parsed.noLock,
69
74
  frameValues: parsed.cues.map(srtCueToFrameValues),
75
+ trackValues: parsed.cues.map((cue) => ({
76
+ ...srtCueToFrameValues(cue),
77
+ tSec: cue.tSec,
78
+ })),
70
79
  protoFile: null,
71
80
  gimbalDevice: null,
72
81
  };
73
82
  }
74
- throw new Error('no telemetry found: no CAM meta (DVTM) stream and no .SRT sidecar');
83
+ throw new Error(`${ERR_NO_TELEMETRY}no CAM meta (DVTM) stream and no .SRT sidecar`);
75
84
  }
76
85
  export async function loadTelemetry(videoPath, { frames, fpsValue, durationSec, tools, }) {
77
86
  const loaded = await loadSamples(tools, videoPath, durationSec);
78
- const { frameValues, protoFile, gimbalDevice, ...samples } = loaded;
87
+ const { frameValues, trackValues, protoFile, gimbalDevice, ...samples } = loaded;
79
88
  return {
80
- telemetry: buildTelemetry(samples, { frames, fpsValue }),
89
+ telemetry: computeTelemetry(samples, { frames, fpsValue }),
81
90
  frameValues,
91
+ trackValues,
82
92
  protoFile,
83
93
  gimbalDevice,
84
94
  };
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "drone-path",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
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",
@@ -74,9 +74,9 @@
74
74
  "devDependencies": {
75
75
  "@changesets/cli": "~3.0.3",
76
76
  "@eslint/js": "~10.0.1",
77
- "@next/eslint-plugin-next": "~16.4.3",
77
+ "@next/eslint-plugin-next": "~16.4.6",
78
78
  "@testing-library/react": "~16.3.3",
79
- "@testing-library/user-event": "~14.6.8",
79
+ "@testing-library/user-event": "~14.6.10",
80
80
  "@types/leaflet": "~1.9.22",
81
81
  "@types/node": "~24.19.2",
82
82
  "@types/react": "~19.3.0",
@@ -86,14 +86,14 @@
86
86
  "electron-builder": "~26.18.0",
87
87
  "eslint": "~10.14.0",
88
88
  "eslint-plugin-react-hooks": "~7.1.1",
89
- "jsdom": "~31.0.0",
90
- "lucide-react": "~1.71.0",
91
- "marked": "~18.1.3",
92
- "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",
93
93
  "react": "~19.3.1",
94
94
  "react-dom": "~19.3.1",
95
95
  "typescript": "~6.0.3",
96
- "typescript-eslint": "~8.72.1",
96
+ "typescript-eslint": "~8.72.2",
97
97
  "vitest": "~5.1.0",
98
98
  "wait-on": "~9.5.1"
99
99
  },
File without changes