drone-path-core 1.2.0 → 2.0.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.
- package/dist/geo.d.ts +2 -0
- package/dist/geo.js +12 -1
- package/dist/keyframes.js +16 -21
- package/dist/paths.d.ts +5 -0
- package/dist/paths.js +18 -0
- package/dist/rounding.d.ts +1 -0
- package/dist/rounding.js +5 -0
- package/dist/sharpness.d.ts +2 -0
- package/dist/sharpness.js +6 -6
- package/dist/shot-segmentation.js +1 -5
- package/dist/spatial.js +1 -8
- package/dist/telemetry-json.d.ts +0 -4
- package/dist/telemetry-json.js +1 -21
- package/dist/telemetry-math.d.ts +8 -0
- package/dist/telemetry-math.js +24 -4
- package/dist/track-write.d.ts +2 -3
- package/dist/track-write.js +12 -18
- package/dist/track.d.ts +2 -9
- package/dist/track.js +2 -28
- package/package.json +4 -4
- package/dist/frame-range.d.ts +0 -6
- package/dist/frame-range.js +0 -30
package/dist/geo.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export interface MercatorPixel {
|
|
|
15
15
|
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
|
+
export declare function clampMercatorLatitude(lat: number): number;
|
|
19
|
+
export declare function wrapLongitude(lon: number): number;
|
|
18
20
|
export declare function isGpsFix(lat: number, lon: number): boolean;
|
|
19
21
|
export declare function gpsFixOrNull(lat: number | null, lon: number | null): LatLon | null;
|
|
20
22
|
export declare function haversineM(a: LatLon, b: LatLon): number;
|
package/dist/geo.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
export const EARTH_RADIUS_M = 6371008.8;
|
|
2
2
|
export const DEG_TO_RAD = Math.PI / 180;
|
|
3
3
|
export const RAD_TO_DEG = 180 / Math.PI;
|
|
4
|
+
const MAX_MERCATOR_LAT = 85.05112878;
|
|
5
|
+
export function clampMercatorLatitude(lat) {
|
|
6
|
+
return Math.max(-MAX_MERCATOR_LAT, Math.min(MAX_MERCATOR_LAT, lat));
|
|
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
|
+
}
|
|
4
15
|
// (0, 0) is DJI's "no GPS lock" placeholder before the first fix, not a real fix.
|
|
5
16
|
export function isGpsFix(lat, lon) {
|
|
6
17
|
return (Number.isFinite(lat) &&
|
|
@@ -47,7 +58,7 @@ export function circularMeanDeg(degList) {
|
|
|
47
58
|
export function project(lon, lat, zoom) {
|
|
48
59
|
const scale = 256 * 2 ** zoom;
|
|
49
60
|
const x = ((lon + 180) / 360) * scale;
|
|
50
|
-
const sinLat = Math.sin(
|
|
61
|
+
const sinLat = Math.sin(clampMercatorLatitude(lat) * DEG_TO_RAD);
|
|
51
62
|
const y = (0.5 - Math.log((1 + sinLat) / (1 - sinLat)) / (4 * Math.PI)) * scale;
|
|
52
63
|
return { x, y };
|
|
53
64
|
}
|
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 {
|
|
6
|
+
import { buildSharpnessFilterGraph, scoreFrameSharpnessOutput } from './sharpness.js';
|
|
7
7
|
import { loadTelemetrySamples } from './telemetry.js';
|
|
8
|
-
import {
|
|
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
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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:
|
|
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 =
|
|
214
|
-
signal: options.signal,
|
|
215
|
-
});
|
|
210
|
+
entry.sharpness = scoreFrameSharpnessOutput(output.stdout, output.stderr, tSec);
|
|
216
211
|
}
|
|
217
212
|
results.push(entry);
|
|
218
213
|
}
|
package/dist/paths.d.ts
ADDED
|
@@ -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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function roundTo(value: number, decimals: number): number;
|
package/dist/rounding.js
ADDED
package/dist/sharpness.d.ts
CHANGED
|
@@ -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
|
@@ -2,6 +2,7 @@ import { StringDecoder } from 'node:string_decoder';
|
|
|
2
2
|
import { runTool, spawnTool } from './exec-tool.js';
|
|
3
3
|
import { probeVideo } from './ffmpeg.js';
|
|
4
4
|
import { timeAt } from './frametime.js';
|
|
5
|
+
import { roundTo } from './rounding.js';
|
|
5
6
|
export const SHARPNESS_ANALYZER_METHOD = 'ffmpeg-blurdetect';
|
|
6
7
|
export const SHARPNESS_ANALYZER_VERSION = '1';
|
|
7
8
|
export const SHARPNESS_ANALYSIS_WIDTH = 640;
|
|
@@ -9,11 +10,6 @@ export const DEFAULT_MIN_EDGE_COVERAGE = 0.002;
|
|
|
9
10
|
function clamp(value, min, max) {
|
|
10
11
|
return Math.min(max, Math.max(min, value));
|
|
11
12
|
}
|
|
12
|
-
function roundTo(value, decimals) {
|
|
13
|
-
const factor = 10 ** decimals;
|
|
14
|
-
const rounded = Math.round(value * factor) / factor;
|
|
15
|
-
return rounded === 0 ? 0 : rounded;
|
|
16
|
-
}
|
|
17
13
|
function parseFiniteOrNull(raw) {
|
|
18
14
|
const num = Number(raw.trim());
|
|
19
15
|
return Number.isFinite(num) ? num : null;
|
|
@@ -136,12 +132,16 @@ export async function analyzeFrameSharpness(tools, videoPath, tSec, options) {
|
|
|
136
132
|
cause: e,
|
|
137
133
|
});
|
|
138
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) {
|
|
139
139
|
const parsedStdout = parseBlurdetectMetadata(stdout);
|
|
140
140
|
const frames = parsedStdout.length > 0 ? parsedStdout : parseBlurdetectMetadata(stderr);
|
|
141
141
|
if (frames.length === 0) {
|
|
142
142
|
throw new Error(`ffmpeg blurdetect produced no frame metadata at ${tSec.toFixed(3)}s`);
|
|
143
143
|
}
|
|
144
|
-
return scoreSharpnessSample(frames[0].blurWidth, frames[0].edgeCoverage,
|
|
144
|
+
return scoreSharpnessSample(frames[0].blurWidth, frames[0].edgeCoverage, minEdgeCoverage);
|
|
145
145
|
}
|
|
146
146
|
/** Stream clip-wide sharpness samples from FFmpeg using sampled (1/sec) or every-frame mode. */
|
|
147
147
|
export async function analyzeClipSharpness(tools, videoPath, options) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { bearingDeg, gpsFixOrNull, haversineM } from './geo.js';
|
|
2
|
+
import { roundTo } from './rounding.js';
|
|
2
3
|
export const SHOT_TYPES = [
|
|
3
4
|
'takeoff',
|
|
4
5
|
'landing',
|
|
@@ -16,11 +17,6 @@ const EXPOSURE_REL_THRESHOLD = 0.25;
|
|
|
16
17
|
const EXPOSURE_CCT_THRESHOLD_K = 200;
|
|
17
18
|
const SHORT_CLIP_MAX_S = 4;
|
|
18
19
|
const BLIP_MAX_DURATION_S = 2;
|
|
19
|
-
function roundTo(value, decimals) {
|
|
20
|
-
const factor = 10 ** decimals;
|
|
21
|
-
const rounded = Math.round(value * factor) / factor;
|
|
22
|
-
return rounded === 0 ? 0 : rounded;
|
|
23
|
-
}
|
|
24
20
|
function shortestAngleDiffDeg(fromDeg, toDeg) {
|
|
25
21
|
return ((((toDeg - fromDeg + 540) % 360) + 360) % 360) - 180;
|
|
26
22
|
}
|
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;
|
package/dist/telemetry-json.d.ts
CHANGED
|
@@ -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 {};
|
package/dist/telemetry-json.js
CHANGED
|
@@ -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:
|
|
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
|
}
|
package/dist/telemetry-math.d.ts
CHANGED
|
@@ -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 {};
|
package/dist/telemetry-math.js
CHANGED
|
@@ -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 +
|
|
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 <
|
|
248
|
-
throw new Error(
|
|
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
|
+
}
|
package/dist/track-write.d.ts
CHANGED
|
@@ -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
|
|
11
|
-
export declare function writeTrackFile(file: string, input: TrackExportInput
|
|
9
|
+
export declare function trackFileBytes(file: string, input: TrackExportInput): string | Buffer;
|
|
10
|
+
export declare function writeTrackFile(file: string, input: TrackExportInput): void;
|
package/dist/track-write.js
CHANGED
|
@@ -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
|
|
4
|
-
//
|
|
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,
|
|
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
|
|
15
|
-
function serializeTrack(format, input
|
|
16
|
-
const track = buildTrack(
|
|
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
|
|
27
|
+
export function trackFileBytes(file, input) {
|
|
29
28
|
const format = trackFormatOf(file);
|
|
30
29
|
if (format === 'json') {
|
|
31
|
-
return serializeTelemetryDocument(buildTelemetryDocument(
|
|
30
|
+
return serializeTelemetryDocument(buildTelemetryDocument(input.document));
|
|
32
31
|
}
|
|
33
|
-
return serializeTrack(format, input
|
|
32
|
+
return serializeTrack(format, input);
|
|
34
33
|
}
|
|
35
|
-
export function writeTrackFile(file, input
|
|
36
|
-
const
|
|
34
|
+
export function writeTrackFile(file, input) {
|
|
35
|
+
const bytes = trackFileBytes(file, input);
|
|
37
36
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
38
|
-
|
|
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
|
|
24
|
+
/** Frame rate of the recording. */
|
|
26
25
|
fpsValue: number;
|
|
27
|
-
/** Frame count of the recording
|
|
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 {
|
|
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:
|
|
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": "
|
|
3
|
+
"version": "2.0.0",
|
|
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://
|
|
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": "
|
|
43
|
+
"zod": "^4.6.7"
|
|
44
44
|
},
|
|
45
45
|
"optionalDependencies": {
|
|
46
|
-
"ffmpeg-ffprobe-static": "
|
|
46
|
+
"ffmpeg-ffprobe-static": "^7.1.0-rc.1"
|
|
47
47
|
}
|
|
48
48
|
}
|
package/dist/frame-range.d.ts
DELETED
package/dist/frame-range.js
DELETED
|
@@ -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
|
-
}
|