drone-path-core 1.2.1 → 2.0.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.
package/dist/geo.d.ts CHANGED
@@ -16,6 +16,7 @@ export declare const EARTH_RADIUS_M = 6371008.8;
16
16
  export declare const DEG_TO_RAD: number;
17
17
  export declare const RAD_TO_DEG: number;
18
18
  export declare function clampMercatorLatitude(lat: number): number;
19
+ export declare function wrapLongitude(lon: number): number;
19
20
  export declare function isGpsFix(lat: number, lon: number): boolean;
20
21
  export declare function gpsFixOrNull(lat: number | null, lon: number | null): LatLon | null;
21
22
  export declare function haversineM(a: LatLon, b: LatLon): number;
package/dist/geo.js CHANGED
@@ -5,6 +5,13 @@ const MAX_MERCATOR_LAT = 85.05112878;
5
5
  export function clampMercatorLatitude(lat) {
6
6
  return Math.max(-MAX_MERCATOR_LAT, Math.min(MAX_MERCATOR_LAT, lat));
7
7
  }
8
+ export function wrapLongitude(lon) {
9
+ if (lon < -180)
10
+ return lon + 360;
11
+ if (lon > 180)
12
+ return lon - 360;
13
+ return lon;
14
+ }
8
15
  // (0, 0) is DJI's "no GPS lock" placeholder before the first fix, not a real fix.
9
16
  export function isGpsFix(lat, lon) {
10
17
  return (Number.isFinite(lat) &&
package/dist/keyframes.js CHANGED
@@ -3,9 +3,9 @@ import path from 'node:path';
3
3
  import { runTool } from './exec-tool.js';
4
4
  import { probeVideo } from './ffmpeg.js';
5
5
  import { timeAt } from './frametime.js';
6
- import { analyzeFrameSharpness } from './sharpness.js';
6
+ import { buildSharpnessFilterGraph, scoreFrameSharpnessOutput } from './sharpness.js';
7
7
  import { loadTelemetrySamples } from './telemetry.js';
8
- import { computeTelemetry } from './telemetry-math.js';
8
+ import { absoluteAltitudeM, computeTelemetryIfFixed } from './telemetry-math.js';
9
9
  function parseFrameToken(raw, token) {
10
10
  if (!/^\d+$/u.test(raw)) {
11
11
  throw new Error(`invalid keyframe frame selector: ${token}`);
@@ -77,16 +77,6 @@ function nearestTrackRecord(records, tSec) {
77
77
  ? records[lo]
78
78
  : records[hi];
79
79
  }
80
- function absAltitudeOf(record) {
81
- if (!record)
82
- return null;
83
- if (record.altAbs !== null && record.altAbs !== undefined)
84
- return record.altAbs;
85
- if (record.gpsAltMm !== null && record.gpsAltMm !== undefined) {
86
- return record.gpsAltMm / 1000;
87
- }
88
- return null;
89
- }
90
80
  function hasAnySnapshotValue(snapshot) {
91
81
  return (snapshot.lat !== null ||
92
82
  snapshot.lon !== null ||
@@ -103,10 +93,10 @@ function buildSnapshotLookup(loaded, probe) {
103
93
  if (!loaded || loaded.trackValues.length === 0) {
104
94
  return () => null;
105
95
  }
106
- const fixCount = loaded.samples.filter((sample) => sample.fix !== null).length;
107
- const telemetry = fixCount >= 2
108
- ? computeTelemetry(loaded, { frames: probe.frames, fpsValue: probe.fps.value })
109
- : null;
96
+ const telemetry = computeTelemetryIfFixed(loaded, {
97
+ frames: probe.frames,
98
+ fpsValue: probe.fps.value,
99
+ });
110
100
  return (tSec, frame) => {
111
101
  const record = nearestTrackRecord(loaded.trackValues, tSec);
112
102
  const frameData = telemetry?.frames[frame];
@@ -114,7 +104,7 @@ function buildSnapshotLookup(loaded, probe) {
114
104
  lat: frameData?.fix?.lat ?? record?.lat ?? null,
115
105
  lon: frameData?.fix?.lon ?? record?.lng ?? null,
116
106
  altRelM: record?.altRel ?? null,
117
- altAbsM: absAltitudeOf(record),
107
+ altAbsM: record ? absoluteAltitudeM(record) : null,
118
108
  speedMps: frameData?.speed ?? null,
119
109
  headingDeg: frameData?.headingDeg ?? record?.yawDeg ?? null,
120
110
  gimbalPitchDeg: record?.gimbalPitchDeg ?? null,
@@ -178,13 +168,19 @@ export async function extractKeyframes(videoPath, options) {
178
168
  fs.mkdirSync(outDir, { recursive: true });
179
169
  const stem = path.basename(videoPath, path.extname(videoPath));
180
170
  const usedPaths = new Set();
171
+ // Extra ffmpeg output on the same seek: the decoded frame is shared, so the
172
+ // JPEG and the sharpness score come from one process and one decode.
173
+ const sharpnessArgs = options.sharpness
174
+ ? ['-frames:v', '1', '-vf', buildSharpnessFilterGraph(), '-f', 'null', '-']
175
+ : [];
181
176
  const results = [];
182
177
  for (const { tSec, frame } of targets) {
183
178
  options.signal?.throwIfAborted();
184
179
  const outPath = allocateOutPath(outDir, stem, frame, tSec, usedPaths);
180
+ let output;
185
181
  try {
186
182
  // Fast input seeking: -ss before -i avoids decoding preceding GOPs.
187
- await runTool(options.tools.ffmpeg, [
183
+ output = await runTool(options.tools.ffmpeg, [
188
184
  '-v', 'error',
189
185
  '-y',
190
186
  '-ss', tSec.toFixed(3),
@@ -192,6 +188,7 @@ export async function extractKeyframes(videoPath, options) {
192
188
  '-frames:v', '1',
193
189
  ...scaleArgs,
194
190
  outPath,
191
+ ...sharpnessArgs,
195
192
  ], { signal: options.signal });
196
193
  }
197
194
  catch (e) {
@@ -210,9 +207,7 @@ export async function extractKeyframes(videoPath, options) {
210
207
  telemetry: snapshotAt(tSec, frame),
211
208
  };
212
209
  if (options.sharpness) {
213
- entry.sharpness = await analyzeFrameSharpness(options.tools, videoPath, tSec, {
214
- signal: options.signal,
215
- });
210
+ entry.sharpness = scoreFrameSharpnessOutput(output.stdout, output.stderr, tSec);
216
211
  }
217
212
  results.push(entry);
218
213
  }
@@ -0,0 +1,5 @@
1
+ /** Comparable identity of a path: resolved, and case-folded on Windows. */
2
+ export declare function pathKey(p: string, platform?: NodeJS.Platform): string;
3
+ export declare function samePath(a: string, b: string, platform?: NodeJS.Platform): boolean;
4
+ /** True when `filePath` lies strictly below `root` (the root itself does not count). */
5
+ export declare function isWithinRoot(root: string, filePath: string, platform?: NodeJS.Platform): boolean;
package/dist/paths.js ADDED
@@ -0,0 +1,18 @@
1
+ import path from 'node:path';
2
+ function pathApi(platform) {
3
+ return platform === 'win32' ? path.win32 : path.posix;
4
+ }
5
+ /** Comparable identity of a path: resolved, and case-folded on Windows. */
6
+ export function pathKey(p, platform = process.platform) {
7
+ const resolved = pathApi(platform).resolve(p);
8
+ return platform === 'win32' ? resolved.toLowerCase() : resolved;
9
+ }
10
+ export function samePath(a, b, platform = process.platform) {
11
+ return pathKey(a, platform) === pathKey(b, platform);
12
+ }
13
+ /** True when `filePath` lies strictly below `root` (the root itself does not count). */
14
+ export function isWithinRoot(root, filePath, platform = process.platform) {
15
+ const api = pathApi(platform);
16
+ const rel = api.relative(pathKey(root, platform), pathKey(filePath, platform));
17
+ return rel !== '' && rel !== '..' && !rel.startsWith(`..${api.sep}`) && !api.isAbsolute(rel);
18
+ }
@@ -58,5 +58,7 @@ export declare function parseBlurdetectMetadata(output: string): RawSharpnessFra
58
58
  export declare function scoreSharpnessSample(blurWidth: number | null, edgeCoverage: number, minEdgeCoverage?: number): FrameSharpness;
59
59
  /** Analyze sharpness of a single decoded video frame at the given timestamp. */
60
60
  export declare function analyzeFrameSharpness(tools: FfmpegToolPaths, videoPath: string, tSec: number, options?: AnalyzeFrameSharpnessOptions): Promise<FrameSharpness>;
61
+ /** Score the first frame of single-frame blurdetect metadata printed by an FFmpeg run. */
62
+ export declare function scoreFrameSharpnessOutput(stdout: string, stderr: string, tSec: number, minEdgeCoverage?: number): FrameSharpness;
61
63
  /** Stream clip-wide sharpness samples from FFmpeg using sampled (1/sec) or every-frame mode. */
62
64
  export declare function analyzeClipSharpness(tools: FfmpegToolPaths, videoPath: string, options?: AnalyzeClipSharpnessOptions): Promise<ClipSharpnessResult>;
package/dist/sharpness.js CHANGED
@@ -132,12 +132,16 @@ export async function analyzeFrameSharpness(tools, videoPath, tSec, options) {
132
132
  cause: e,
133
133
  });
134
134
  }
135
+ return scoreFrameSharpnessOutput(stdout, stderr, tSec, options?.minEdgeCoverage);
136
+ }
137
+ /** Score the first frame of single-frame blurdetect metadata printed by an FFmpeg run. */
138
+ export function scoreFrameSharpnessOutput(stdout, stderr, tSec, minEdgeCoverage) {
135
139
  const parsedStdout = parseBlurdetectMetadata(stdout);
136
140
  const frames = parsedStdout.length > 0 ? parsedStdout : parseBlurdetectMetadata(stderr);
137
141
  if (frames.length === 0) {
138
142
  throw new Error(`ffmpeg blurdetect produced no frame metadata at ${tSec.toFixed(3)}s`);
139
143
  }
140
- return scoreSharpnessSample(frames[0].blurWidth, frames[0].edgeCoverage, options?.minEdgeCoverage);
144
+ return scoreSharpnessSample(frames[0].blurWidth, frames[0].edgeCoverage, minEdgeCoverage);
141
145
  }
142
146
  /** Stream clip-wide sharpness samples from FFmpeg using sampled (1/sec) or every-frame mode. */
143
147
  export async function analyzeClipSharpness(tools, videoPath, options) {
package/dist/spatial.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DEG_TO_RAD, EARTH_RADIUS_M, RAD_TO_DEG } from './geo.js';
1
+ import { DEG_TO_RAD, EARTH_RADIUS_M, RAD_TO_DEG, wrapLongitude } from './geo.js';
2
2
  const ANGLE_EPSILON = 1e-12;
3
3
  export function longitudeRanges({ minLon, maxLon }) {
4
4
  if (minLon > maxLon)
@@ -59,13 +59,6 @@ export function resolveTrackBbox(bbox, segments) {
59
59
  }
60
60
  return { ...bbox, minLon, maxLon };
61
61
  }
62
- function wrapLongitude(lon) {
63
- if (lon < -180)
64
- return lon + 360;
65
- if (lon > 180)
66
- return lon - 360;
67
- return lon;
68
- }
69
62
  export function radiusBbox(center, radiusM) {
70
63
  // Round outward so a hit on the radius boundary survives the SQL prefilter.
71
64
  const angle = radiusM / EARTH_RADIUS_M + ANGLE_EPSILON;
@@ -1,5 +1,4 @@
1
1
  import { z } from 'zod';
2
- import type { FrameRange } from './frame-range.js';
3
2
  import type { HeadingMode, TelemetrySource } from './telemetry-math.js';
4
3
  export declare const TELEMETRY_JSON_SCHEMA_VERSION = 1;
5
4
  declare const GimbalDeviceSchema: z.ZodObject<{
@@ -89,14 +88,11 @@ export interface TelemetryDocumentInput {
89
88
  source: TelemetrySource;
90
89
  headingMode: HeadingMode;
91
90
  frameCount: number;
92
- frameStart?: number;
93
91
  gimbalDevice?: TelemetryGimbalDevice | null;
94
92
  frames: readonly TelemetryFrameInput[];
95
93
  headingDeg: readonly number[];
96
94
  }
97
- export declare function segmentTelemetryInput(input: TelemetryDocumentInput, range: FrameRange | null): TelemetryDocumentInput;
98
95
  export declare function buildTelemetryDocument(input: TelemetryDocumentInput): TelemetryDocument;
99
96
  export declare function serializeTelemetryDocument(doc: TelemetryDocument): string;
100
- export declare function writeTelemetryDocument(file: string, input: TelemetryDocumentInput): void;
101
97
  export declare function generateTelemetryJsonSchema(): string;
102
98
  export {};
@@ -1,7 +1,4 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
1
  import { z } from 'zod';
4
- import { resolveFrameRange } from './frame-range.js';
5
2
  export const TELEMETRY_JSON_SCHEMA_VERSION = 1;
6
3
  const GimbalDeviceSchema = z.strictObject({
7
4
  id: z.int(),
@@ -73,7 +70,7 @@ function copyValue(record, key, value) {
73
70
  function buildRecord(input, index) {
74
71
  const row = input.frames[index] ?? {};
75
72
  const record = {
76
- frame: (input.frameStart ?? 0) + index,
73
+ frame: index,
77
74
  };
78
75
  for (const key of BEFORE_HEADING_KEYS)
79
76
  copyValue(record, key, row[key]);
@@ -83,18 +80,6 @@ function buildRecord(input, index) {
83
80
  copyValue(record, key, row[key]);
84
81
  return record;
85
82
  }
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
- }
98
83
  export function buildTelemetryDocument(input) {
99
84
  if (input.headingDeg.length !== input.frameCount) {
100
85
  throw new Error('telemetry JSON: heading count does not match the frame count');
@@ -116,11 +101,6 @@ export function buildTelemetryDocument(input) {
116
101
  export function serializeTelemetryDocument(doc) {
117
102
  return `${JSON.stringify(doc, null, 2)}\n`;
118
103
  }
119
- export function writeTelemetryDocument(file, input) {
120
- const doc = buildTelemetryDocument(input);
121
- fs.mkdirSync(path.dirname(file), { recursive: true });
122
- fs.writeFileSync(file, serializeTelemetryDocument(doc));
123
- }
124
104
  export function generateTelemetryJsonSchema() {
125
105
  return `${JSON.stringify(z.toJSONSchema(TelemetryDocumentSchema), null, 2)}\n`;
126
106
  }
@@ -1,5 +1,6 @@
1
1
  import type { Bbox, LatLon } from './geo.js';
2
2
  import type { CamMetaMethod } from './cammeta-decode.js';
3
+ import type { TelemetryFrameInput } from './telemetry-json.js';
3
4
  export type TelemetrySource = 'srt' | 'cammeta';
4
5
  type TelemetryMethod = 'srt-cues' | CamMetaMethod;
5
6
  export type HeadingMode = 'yaw' | 'cog';
@@ -40,8 +41,15 @@ export interface TelemetrySamples {
40
41
  method: TelemetryMethod;
41
42
  noLock: number;
42
43
  }
44
+ export declare const MIN_TELEMETRY_FIXES = 2;
43
45
  export declare function computeTelemetry(loaded: TelemetrySamples, timing: {
44
46
  frames: number;
45
47
  fpsValue: number;
46
48
  }): Telemetry;
49
+ export declare function countTelemetryFixes(samples: readonly TelemetrySample[]): number;
50
+ export declare function computeTelemetryIfFixed(loaded: TelemetrySamples, timing: {
51
+ frames: number;
52
+ fpsValue: number;
53
+ }): Telemetry | null;
54
+ export declare function absoluteAltitudeM(record: Pick<TelemetryFrameInput, 'altAbs' | 'gpsAltMm'>): number | null;
47
55
  export {};
@@ -1,5 +1,6 @@
1
- import { bearingDeg, circularMeanDeg, haversineM } from './geo.js';
1
+ import { bearingDeg, circularMeanDeg, haversineM, wrapLongitude } from './geo.js';
2
2
  import { timeAt } from './frametime.js';
3
+ export const MIN_TELEMETRY_FIXES = 2;
3
4
  const MAX_INTERPOLATION_GAP_S = 3;
4
5
  const SPEED_SMOOTHING_SPAN = 5;
5
6
  const HEADING_MIN_MOVE_M = 1.5;
@@ -56,10 +57,11 @@ function positionAt(samples, t, maxGapSec = MAX_INTERPOLATION_GAP_S) {
56
57
  const dt = b.tSec - a.tSec;
57
58
  const gapOk = dt > 0 && dt <= maxGapSec;
58
59
  const fraction = gapOk ? (t - a.tSec) / dt : 0;
60
+ const longitudeDelta = wrapLongitude(b.fix.lon - a.fix.lon);
59
61
  return {
60
62
  fix: {
61
63
  lat: a.fix.lat + (b.fix.lat - a.fix.lat) * fraction,
62
- lon: a.fix.lon + (b.fix.lon - a.fix.lon) * fraction,
64
+ lon: wrapLongitude(a.fix.lon + longitudeDelta * fraction),
63
65
  },
64
66
  alt: interpolateAltitude(a, b, fraction),
65
67
  };
@@ -244,8 +246,9 @@ function bridgeMissingFramePositions(frameData) {
244
246
  export function computeTelemetry(loaded, timing) {
245
247
  const { samples, source, method, noLock } = loaded;
246
248
  const fixes = samples.filter(isFixSample);
247
- if (fixes.length < 2)
248
- throw new Error('telemetry has fewer than 2 GPS fixes');
249
+ if (fixes.length < MIN_TELEMETRY_FIXES) {
250
+ throw new Error(`telemetry has fewer than ${MIN_TELEMETRY_FIXES} GPS fixes`);
251
+ }
249
252
  const { bbox, trackDistanceM } = computeTrackStats(fixes);
250
253
  const speedByFix = computeSpeedByFix(fixes);
251
254
  const { headingByFix, headingMode } = computeHeadingByFix(fixes, speedByFix);
@@ -263,3 +266,20 @@ export function computeTelemetry(loaded, timing) {
263
266
  trackDistanceM,
264
267
  };
265
268
  }
269
+ export function countTelemetryFixes(samples) {
270
+ return samples.filter(isFixSample).length;
271
+ }
272
+ // Null when the samples carry too few GPS fixes to derive a track.
273
+ export function computeTelemetryIfFixed(loaded, timing) {
274
+ return countTelemetryFixes(loaded.samples) >= MIN_TELEMETRY_FIXES
275
+ ? computeTelemetry(loaded, timing)
276
+ : null;
277
+ }
278
+ // Prefers the recorded absolute altitude, falling back to the GPS altitude.
279
+ export function absoluteAltitudeM(record) {
280
+ if (record.altAbs !== null && record.altAbs !== undefined)
281
+ return record.altAbs;
282
+ if (record.gpsAltMm !== null && record.gpsAltMm !== undefined)
283
+ return record.gpsAltMm / 1000;
284
+ return null;
285
+ }
@@ -1,4 +1,3 @@
1
- import type { FrameRange } from './frame-range.js';
2
1
  import type { TelemetryDocumentInput } from './telemetry-json.js';
3
2
  import type { TrackStream } from './track.js';
4
3
  export interface TrackExportInput {
@@ -7,5 +6,5 @@ export interface TrackExportInput {
7
6
  /** The fix-faithful, time-keyed records; serve the track formats. */
8
7
  track: TrackStream;
9
8
  }
10
- export declare function trackFileBytes(file: string, input: TrackExportInput, range: FrameRange | null): string | Buffer;
11
- export declare function writeTrackFile(file: string, input: TrackExportInput, range: FrameRange | null): void;
9
+ export declare function trackFileBytes(file: string, input: TrackExportInput): string | Buffer;
10
+ export declare function writeTrackFile(file: string, input: TrackExportInput): void;
@@ -1,19 +1,18 @@
1
1
  // The imperative shell for track exports: routes one export input to the
2
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.
3
+ // the telemetry document, byte-for-byte unchanged; the track formats export
4
+ // every decoded record of the recording.
6
5
  import fs from 'node:fs';
7
6
  import path from 'node:path';
8
- import { buildTelemetryDocument, segmentTelemetryInput, serializeTelemetryDocument, writeTelemetryDocument, } from './telemetry-json.js';
7
+ import { buildTelemetryDocument, serializeTelemetryDocument, } from './telemetry-json.js';
9
8
  import { serializeGeoJson } from './track-geojson.js';
10
9
  import { serializeGpx } from './track-gpx.js';
11
10
  import { serializeKml } from './track-kml.js';
12
11
  import { kmzBytes } from './track-kmz.js';
13
12
  import { trackFormatOf } from './track-format.js';
14
- import { buildTrack, selectTrackRecords } from './track.js';
15
- function serializeTrack(format, input, range) {
16
- const track = buildTrack(selectTrackRecords(input.track, range));
13
+ import { buildTrack } from './track.js';
14
+ function serializeTrack(format, input) {
15
+ const track = buildTrack(input.track.records);
17
16
  switch (format) {
18
17
  case 'gpx':
19
18
  return serializeGpx(track);
@@ -25,20 +24,15 @@ function serializeTrack(format, input, range) {
25
24
  return kmzBytes(serializeKml(track));
26
25
  }
27
26
  }
28
- export function trackFileBytes(file, input, range) {
27
+ export function trackFileBytes(file, input) {
29
28
  const format = trackFormatOf(file);
30
29
  if (format === 'json') {
31
- return serializeTelemetryDocument(buildTelemetryDocument(segmentTelemetryInput(input.document, range)));
30
+ return serializeTelemetryDocument(buildTelemetryDocument(input.document));
32
31
  }
33
- return serializeTrack(format, input, range);
32
+ return serializeTrack(format, input);
34
33
  }
35
- export function writeTrackFile(file, input, range) {
36
- const format = trackFormatOf(file);
34
+ export function writeTrackFile(file, input) {
35
+ const bytes = trackFileBytes(file, input);
37
36
  fs.mkdirSync(path.dirname(file), { recursive: true });
38
- if (format === 'json') {
39
- // Delegated so the telemetry document bytes can never drift.
40
- writeTelemetryDocument(file, segmentTelemetryInput(input.document, range));
41
- return;
42
- }
43
- fs.writeFileSync(file, serializeTrack(format, input, range));
37
+ fs.writeFileSync(file, bytes);
44
38
  }
package/dist/track.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { FrameRange } from './frame-range.js';
2
1
  import type { TelemetryFrameInput } from './telemetry-json.js';
3
2
  export interface TrackVertex {
4
3
  lat: number;
@@ -22,14 +21,8 @@ export interface TrackRecord extends TelemetryFrameInput {
22
21
  }
23
22
  export interface TrackStream {
24
23
  records: readonly TrackRecord[];
25
- /** Frame rate that maps record times onto frame indices. */
24
+ /** Frame rate of the recording. */
26
25
  fpsValue: number;
27
- /** Frame count of the recording: bounds-checks ranges and clamps the clip end. */
26
+ /** Frame count of the recording. */
28
27
  frameCount: number;
29
28
  }
30
- /**
31
- * Selects the records for a frame range (inclusive bounds) by their source
32
- * time; a null range keeps every record, however many there are per frame.
33
- * Invalid and out-of-bounds ranges are rejected like on the document path.
34
- */
35
- export declare function selectTrackRecords(stream: TrackStream, range: FrameRange | null): readonly TrackRecord[];
package/dist/track.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // time only where the source carries trustworthy UTC. Built from the same
4
4
  // per-source-frame records as the telemetry JSON document, so the CLI and the
5
5
  // desktop app export byte-identical tracks for the same records.
6
- import { resolveFrameRange } from './frame-range.js';
6
+ import { absoluteAltitudeM } from './telemetry-math.js';
7
7
  // The one rendering of a vertex's timeMs shared by the GPX, GeoJSON and KML
8
8
  // serializers: UTC ISO-8601, never a relative or zone-less clock.
9
9
  export function isoUtc(timeMs) {
@@ -20,18 +20,11 @@ function timeOf(row) {
20
20
  void row;
21
21
  return null;
22
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
23
  function vertexOf(row) {
31
24
  return {
32
25
  lat: row.lat,
33
26
  lon: row.lng,
34
- altM: altitudeOf(row),
27
+ altM: absoluteAltitudeM(row),
35
28
  timeMs: timeOf(row),
36
29
  };
37
30
  }
@@ -58,22 +51,3 @@ export function buildTrack(rows) {
58
51
  segments.push(current);
59
52
  return segments;
60
53
  }
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-core",
3
- "version": "1.2.1",
3
+ "version": "2.0.1",
4
4
  "description": "Extract drone telemetry from DJI CAM-meta video streams and SRT sidecars.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "author": "Manuel Warum",
25
25
  "license": "MIT",
26
- "homepage": "https://www.dronepath.dev",
26
+ "homepage": "https://dronepath.dev",
27
27
  "keywords": [
28
28
  "dji",
29
29
  "drone",
@@ -40,9 +40,9 @@
40
40
  "directory": "packages/core"
41
41
  },
42
42
  "dependencies": {
43
- "zod": "~4.6.7"
43
+ "zod": "^4.6.7"
44
44
  },
45
45
  "optionalDependencies": {
46
- "ffmpeg-ffprobe-static": "~7.1.0-rc.1"
46
+ "ffmpeg-ffprobe-static": "^7.1.0-rc.1"
47
47
  }
48
48
  }
@@ -1,6 +0,0 @@
1
- export interface FrameRange {
2
- start: number;
3
- end: number;
4
- }
5
- export declare function parseFrameRange(raw: unknown, name?: string): FrameRange;
6
- export declare function resolveFrameRange(range: FrameRange | null | undefined, frames: number): FrameRange | null;
@@ -1,30 +0,0 @@
1
- import { numberValue, parseValue, strictShape } from './validation.js';
2
- function assertValidFrameRange(range, name = 'frame range') {
3
- if (!Number.isInteger(range.start) || !Number.isInteger(range.end)) {
4
- throw new Error(`invalid ${name}: start and end must be integer frame indices`);
5
- }
6
- // A single-frame span (start === end) is a valid export range.
7
- if (range.start < 0 || range.start > range.end) {
8
- throw new Error(`invalid ${name}: expected 0 <= start <= end, got ${range.start}-${range.end}`);
9
- }
10
- }
11
- export function parseFrameRange(raw, name = 'frame range') {
12
- const range = parseValue(strictShape({
13
- start: numberValue(`${name}: start`),
14
- end: numberValue(`${name}: end`),
15
- }, {
16
- invalid: `invalid ${name}`,
17
- unknownKey: (key) => `unknown ${name} key ${key}`,
18
- }), raw);
19
- assertValidFrameRange(range, name);
20
- return range;
21
- }
22
- export function resolveFrameRange(range, frames) {
23
- if (!range)
24
- return null;
25
- assertValidFrameRange(range);
26
- if (range.end >= frames) {
27
- throw new Error(`frame range ${range.start}-${range.end} is beyond the recording (${frames} frames)`);
28
- }
29
- return range;
30
- }