drone-path-core 0.0.0-bootstrap

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 (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +34 -0
  3. package/THIRD-PARTY-NOTICES.md +21 -0
  4. package/dist/cammeta-decode.d.ts +57 -0
  5. package/dist/cammeta-decode.js +237 -0
  6. package/dist/cammeta.d.ts +5 -0
  7. package/dist/cammeta.js +92 -0
  8. package/dist/errors.d.ts +18 -0
  9. package/dist/errors.js +34 -0
  10. package/dist/exec-tool.d.ts +7 -0
  11. package/dist/exec-tool.js +14 -0
  12. package/dist/ffmpeg-tools.d.ts +14 -0
  13. package/dist/ffmpeg-tools.js +56 -0
  14. package/dist/ffmpeg.d.ts +21 -0
  15. package/dist/ffmpeg.js +58 -0
  16. package/dist/frame-range.d.ts +6 -0
  17. package/dist/frame-range.js +30 -0
  18. package/dist/frametime.d.ts +14 -0
  19. package/dist/frametime.js +32 -0
  20. package/dist/geo.d.ts +21 -0
  21. package/dist/geo.js +60 -0
  22. package/dist/protobuf-wire.d.ts +16 -0
  23. package/dist/protobuf-wire.js +102 -0
  24. package/dist/srt-sidecar.d.ts +1 -0
  25. package/dist/srt-sidecar.js +13 -0
  26. package/dist/srt.d.ts +19 -0
  27. package/dist/srt.js +98 -0
  28. package/dist/telemetry-json.d.ts +102 -0
  29. package/dist/telemetry-json.js +126 -0
  30. package/dist/telemetry-math.d.ts +47 -0
  31. package/dist/telemetry-math.js +262 -0
  32. package/dist/telemetry-summary.d.ts +6 -0
  33. package/dist/telemetry-summary.js +19 -0
  34. package/dist/telemetry.d.ts +18 -0
  35. package/dist/telemetry.js +95 -0
  36. package/dist/track-format.d.ts +4 -0
  37. package/dist/track-format.js +13 -0
  38. package/dist/track-geojson.d.ts +2 -0
  39. package/dist/track-geojson.js +44 -0
  40. package/dist/track-gpx.d.ts +2 -0
  41. package/dist/track-gpx.js +34 -0
  42. package/dist/track-kml.d.ts +2 -0
  43. package/dist/track-kml.js +47 -0
  44. package/dist/track-kmz.d.ts +1 -0
  45. package/dist/track-kmz.js +68 -0
  46. package/dist/track-write.d.ts +11 -0
  47. package/dist/track-write.js +41 -0
  48. package/dist/track.d.ts +35 -0
  49. package/dist/track.js +79 -0
  50. package/dist/validation.d.ts +9 -0
  51. package/dist/validation.js +22 -0
  52. package/package.json +37 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Manuel Warum
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # drone-path-core
2
+
3
+ Extract telemetry from DJI CAM-meta streams and SRT sidecars. This package
4
+ also owns the telemetry document, frame ranges, and track export formats.
5
+
6
+ ```sh
7
+ npm install drone-path-core
8
+ ```
9
+
10
+ Use the module subpaths in Node.js 24 or later.
11
+
12
+ ```js
13
+ import { parseSrt } from 'drone-path-core/srt';
14
+
15
+ const result = await parseSrt('flight.SRT');
16
+ ```
17
+
18
+ Each module ships TypeScript declarations.
19
+
20
+ Install `@types/node` for your Node.js major version. In TypeScript 6, list
21
+ `node` in `compilerOptions.types` to load the Node declarations.
22
+
23
+ ```json
24
+ {
25
+ "compilerOptions": {
26
+ "module": "NodeNext",
27
+ "types": ["node"]
28
+ }
29
+ }
30
+ ```
31
+
32
+ Use `drone-path-engine` for render planning and video export.
33
+ See the [project manual](https://github.com/MrManny/drone-path/tree/main/docs/user)
34
+ for DJI input formats and telemetry details.
@@ -0,0 +1,21 @@
1
+ # Third-party notices
2
+
3
+ Zod is licensed under MIT and ships its license in its npm package.
4
+
5
+ ## FFmpeg and FFprobe binaries
6
+
7
+ The `ffmpeg-ffprobe-static` optional dependency downloads FFmpeg and FFprobe
8
+ 7.1.0 builds from its
9
+ [b7.1.0-rc.1 release](https://github.com/descriptinc/ffmpeg-ffprobe-static/releases/tag/b7.1.0-rc.1).
10
+ Drone Path spawns these binaries as separate processes. The x264 and x265
11
+ encoders make these builds GPL-3.0-or-later.
12
+
13
+ - Windows x64 uses the gyan.dev `7.1-essentials_build-www.gyan.dev` build.
14
+ The corresponding source is the [FFmpeg 7.1 release](https://ffmpeg.org/releases/ffmpeg-7.1.tar.xz).
15
+ - Linux x64 uses the BtbN FFmpeg-Builds autobuild
16
+ `ffmpeg-n7.1-15-g9fbbd924f2-linux64-gpl-7.1`. The corresponding source
17
+ is [FFmpeg commit 9fbbd924f2](https://github.com/FFmpeg/FFmpeg/commit/9fbbd924f2).
18
+
19
+ The dependency places the full GPL license text beside the binaries as
20
+ `ffmpeg.LICENSE` (`ffmpeg.exe.LICENSE` on Windows). The wrapper's own
21
+ `LICENSE` file is BSD-3-Clause and credits Eugene Ware and contributors.
@@ -0,0 +1,57 @@
1
+ import type { LatLon } from './geo.js';
2
+ interface ProductMeta {
3
+ fix: LatLon | null;
4
+ noLock: boolean;
5
+ relAlt: number | null;
6
+ absAlt: number | null;
7
+ yawDeg: number | null;
8
+ pitchDeg: number | null;
9
+ rollDeg: number | null;
10
+ gpsAltMm: number | null;
11
+ gimbalPitchDeg: number | null;
12
+ gimbalRollDeg: number | null;
13
+ gimbalYawDeg: number | null;
14
+ gimbalDeviceTimestampMs: number | null;
15
+ iso: number | null;
16
+ whiteBalanceCctK: number | null;
17
+ }
18
+ export interface CamSample extends ProductMeta {
19
+ tSec: number;
20
+ }
21
+ export type CamMetaMethod = 'dvtm-packets' | 'cammeta-scan';
22
+ export interface GimbalDeviceConstants {
23
+ id: number;
24
+ type: number;
25
+ subType: number;
26
+ name: string;
27
+ frequency: number;
28
+ }
29
+ interface ClipProvenance {
30
+ protoFile: string | null;
31
+ gimbalDevice: GimbalDeviceConstants | null;
32
+ }
33
+ export interface CamMetaResult {
34
+ samples: CamSample[];
35
+ noLock: number;
36
+ method: CamMetaMethod;
37
+ protoFile: string | null;
38
+ gimbalDevice: GimbalDeviceConstants | null;
39
+ }
40
+ export declare function decodeProductMeta(buf: Buffer, start?: number, end?: number): ProductMeta;
41
+ export declare function decodeProvenance(buf: Buffer, start?: number, end?: number): ClipProvenance;
42
+ export declare function scanGpsPair(buf: Buffer, offset?: number, end?: number): {
43
+ fix: LatLon;
44
+ at: number;
45
+ } | null;
46
+ export interface CamMetaPacket {
47
+ tSec: number;
48
+ size: number;
49
+ }
50
+ export declare function decodePacketSamples(buf: Buffer, packets: CamMetaPacket[], keepAll: boolean): {
51
+ samples: CamSample[];
52
+ noLock: number;
53
+ provenance: ClipProvenance;
54
+ };
55
+ export declare function scanBufferForGpsPairs(buf: Buffer): CamSample[];
56
+ export declare function spreadSampleTimes(samples: CamSample[], durationSec: number): void;
57
+ export {};
@@ -0,0 +1,237 @@
1
+ import { gpsFixOrNull } from './geo.js';
2
+ import { firstDoubleField, firstFloatField, firstStringField, firstVarintField, parseProtoFields, firstSubMessage, } from './protobuf-wire.js';
3
+ // DVTM field numbers; the message layout is documented in docs/telemetry-protobuf.md.
4
+ const CLIP_META = 1;
5
+ const CLIP_META_HEADER = 1;
6
+ const PROTO_FILE_NAME = 1;
7
+ const PRODUCT_PROTO_VERSION = 3;
8
+ const FRAME_META = 3;
9
+ const CAMERA = 2;
10
+ const ISO = 3;
11
+ const WHITE_BALANCE_CCT = 6;
12
+ const ABSOLUTE_ALTITUDE = 11;
13
+ const DRONE = 4;
14
+ const GPS_BASIC = 4;
15
+ const POSITION_COORD = 1;
16
+ const GPS_ALTITUDE_MM = 2;
17
+ const RELATIVE_ALTITUDE = 5;
18
+ const EULER_ANGLE = 3;
19
+ const GIMBAL = 5;
20
+ const GIMBAL_DEVICE_HEADER = 1;
21
+ const GIMBAL_EULER_ANGLE = 2;
22
+ const DEVICE_ID = 1;
23
+ const DEVICE_TYPE = 2;
24
+ const DEVICE_SUB_TYPE = 3;
25
+ const DEVICE_NAME = 4;
26
+ const DEVICE_FREQUENCY = 5;
27
+ const DEVICE_TIMESTAMP = 6;
28
+ const VALUE = 1;
29
+ const PITCH = 1;
30
+ const ROLL = 2;
31
+ const YAW = 3;
32
+ const LAT = 2;
33
+ const LON = 3;
34
+ // GPS double-pair wire signature (0x11 lat f64, 0x19 lon f64); see docs/telemetry-protobuf.md.
35
+ const GPS_PAIR_SPAN = 18;
36
+ function emptyProductMeta() {
37
+ return {
38
+ fix: null,
39
+ noLock: false,
40
+ relAlt: null,
41
+ absAlt: null,
42
+ yawDeg: null,
43
+ pitchDeg: null,
44
+ rollDeg: null,
45
+ gpsAltMm: null,
46
+ gimbalPitchDeg: null,
47
+ gimbalRollDeg: null,
48
+ gimbalYawDeg: null,
49
+ gimbalDeviceTimestampMs: null,
50
+ iso: null,
51
+ whiteBalanceCctK: null,
52
+ };
53
+ }
54
+ export function decodeProductMeta(buf, start = 0, end = buf.length) {
55
+ const top = parseProtoFields(buf, start, end);
56
+ const frameMeta = firstSubMessage(buf, top, FRAME_META);
57
+ const camera = frameMeta ? firstSubMessage(buf, frameMeta, CAMERA) : null;
58
+ const drone = frameMeta ? firstSubMessage(buf, frameMeta, DRONE) : null;
59
+ const gimbal = frameMeta ? firstSubMessage(buf, frameMeta, GIMBAL) : null;
60
+ const absAlt = camera ? decodeAbsoluteAltitude(buf, camera) : null;
61
+ const gps = drone ? decodeGps(buf, drone) : null;
62
+ const euler = drone ? decodeEulerAngles(buf, drone, EULER_ANGLE) : null;
63
+ const gimbalEuler = gimbal
64
+ ? decodeEulerAngles(buf, gimbal, GIMBAL_EULER_ANGLE)
65
+ : null;
66
+ const gimbalHeader = gimbal
67
+ ? firstSubMessage(buf, gimbal, GIMBAL_DEVICE_HEADER)
68
+ : null;
69
+ return {
70
+ fix: gps?.fix ?? null,
71
+ noLock: gps?.noLock ?? false,
72
+ relAlt: drone ? decodeRelativeAltitude(buf, drone) : null,
73
+ absAlt: absAlt ?? gpsAltMeters(gps?.gpsAltMm ?? null),
74
+ yawDeg: euler?.yawDeg ?? null,
75
+ pitchDeg: euler?.pitchDeg ?? null,
76
+ rollDeg: euler?.rollDeg ?? null,
77
+ gpsAltMm: gps?.gpsAltMm ?? null,
78
+ gimbalPitchDeg: gimbalEuler?.pitchDeg ?? null,
79
+ gimbalRollDeg: gimbalEuler?.rollDeg ?? null,
80
+ gimbalYawDeg: gimbalEuler?.yawDeg ?? null,
81
+ gimbalDeviceTimestampMs: gimbalHeader
82
+ ? (firstVarintField(gimbalHeader, DEVICE_TIMESTAMP) ?? 0)
83
+ : null,
84
+ iso: camera ? decodeCameraVarint(buf, camera, ISO) : null,
85
+ whiteBalanceCctK: camera ? decodeCameraVarint(buf, camera, WHITE_BALANCE_CCT) : null,
86
+ };
87
+ }
88
+ function decodeCameraVarint(buf, camera, fieldNumber) {
89
+ const message = firstSubMessage(buf, camera, fieldNumber);
90
+ return message ? (firstVarintField(message, VALUE) ?? 0) : null;
91
+ }
92
+ function decodeAbsoluteAltitude(buf, camera) {
93
+ const absoluteAltitude = firstSubMessage(buf, camera, ABSOLUTE_ALTITUDE);
94
+ if (!absoluteAltitude)
95
+ return null;
96
+ const meters = firstFloatField(absoluteAltitude, VALUE) ?? 0;
97
+ return Number.isFinite(meters) ? meters : null;
98
+ }
99
+ function gpsAltMeters(gpsAltMm) {
100
+ return gpsAltMm !== null ? gpsAltMm / 1000 : null;
101
+ }
102
+ function decodeGps(buf, drone) {
103
+ const out = { fix: null, noLock: false, gpsAltMm: null };
104
+ const gps = firstSubMessage(buf, drone, GPS_BASIC);
105
+ if (!gps)
106
+ return out;
107
+ const coord = firstSubMessage(buf, gps, POSITION_COORD);
108
+ if (coord) {
109
+ const lat = firstDoubleField(coord, LAT);
110
+ const lon = firstDoubleField(coord, LON);
111
+ if (lat !== null && lon !== null) {
112
+ const fix = gpsFixOrNull(lat, lon);
113
+ if (fix !== null)
114
+ out.fix = fix;
115
+ else
116
+ out.noLock = true;
117
+ }
118
+ }
119
+ out.gpsAltMm = firstVarintField(gps, GPS_ALTITUDE_MM) ?? 0;
120
+ return out;
121
+ }
122
+ function decodeRelativeAltitude(buf, drone) {
123
+ const relative = firstSubMessage(buf, drone, RELATIVE_ALTITUDE);
124
+ if (!relative)
125
+ return null;
126
+ const millimeters = firstFloatField(relative, VALUE) ?? 0;
127
+ return Number.isFinite(millimeters) ? millimeters / 1000 : null;
128
+ }
129
+ function decodeEulerAngles(buf, fields, fieldNumber) {
130
+ const euler = firstSubMessage(buf, fields, fieldNumber);
131
+ if (!euler)
132
+ return null;
133
+ return {
134
+ pitchDeg: (firstVarintField(euler, PITCH) ?? 0) / 10,
135
+ rollDeg: (firstVarintField(euler, ROLL) ?? 0) / 10,
136
+ yawDeg: (firstVarintField(euler, YAW) ?? 0) / 10,
137
+ };
138
+ }
139
+ export function decodeProvenance(buf, start = 0, end = buf.length) {
140
+ const top = parseProtoFields(buf, start, end);
141
+ return {
142
+ protoFile: decodeProtoFile(buf, top),
143
+ gimbalDevice: decodeGimbalDevice(buf, top),
144
+ };
145
+ }
146
+ function decodeProtoFile(buf, top) {
147
+ const clipMeta = firstSubMessage(buf, top, CLIP_META);
148
+ const header = clipMeta && firstSubMessage(buf, clipMeta, CLIP_META_HEADER);
149
+ if (!header)
150
+ return null;
151
+ const name = nonEmptyString(buf, header, PROTO_FILE_NAME);
152
+ const version = nonEmptyString(buf, header, PRODUCT_PROTO_VERSION);
153
+ if (!name)
154
+ return null;
155
+ return version ? `${name} ${version}` : name;
156
+ }
157
+ function nonEmptyString(buf, fields, fieldNumber) {
158
+ const value = firstStringField(buf, fields, fieldNumber)?.trim() ?? '';
159
+ return value === '' ? null : value;
160
+ }
161
+ function decodeGimbalDevice(buf, top) {
162
+ const frameMeta = firstSubMessage(buf, top, FRAME_META);
163
+ const gimbal = frameMeta && firstSubMessage(buf, frameMeta, GIMBAL);
164
+ const header = gimbal && firstSubMessage(buf, gimbal, GIMBAL_DEVICE_HEADER);
165
+ if (!header)
166
+ return null;
167
+ return {
168
+ id: firstVarintField(header, DEVICE_ID) ?? 0,
169
+ type: firstVarintField(header, DEVICE_TYPE) ?? 0,
170
+ subType: firstVarintField(header, DEVICE_SUB_TYPE) ?? 0,
171
+ name: firstStringField(buf, header, DEVICE_NAME) ?? '',
172
+ frequency: firstFloatField(header, DEVICE_FREQUENCY) ?? 0,
173
+ };
174
+ }
175
+ export function scanGpsPair(buf, offset = 0, end = buf.length) {
176
+ for (let i = offset; i <= end - GPS_PAIR_SPAN; i++) {
177
+ if (buf[i] === 0x11 && buf[i + 9] === 0x19) {
178
+ const fix = gpsFixOrNull(buf.readDoubleLE(i + 1), buf.readDoubleLE(i + 10));
179
+ if (fix !== null)
180
+ return { fix, at: i };
181
+ }
182
+ }
183
+ return null;
184
+ }
185
+ function toCamSample(meta, tSec) {
186
+ return { tSec, ...meta };
187
+ }
188
+ export function decodePacketSamples(buf, packets, keepAll) {
189
+ const samples = [];
190
+ let noLock = 0;
191
+ let offset = 0;
192
+ let protoFile = null;
193
+ let gimbalDevice = null;
194
+ for (const packet of packets) {
195
+ const end = offset + packet.size;
196
+ if (protoFile === null || gimbalDevice === null) {
197
+ const declared = decodeProvenance(buf, offset, end);
198
+ protoFile ??= declared.protoFile;
199
+ gimbalDevice ??= declared.gimbalDevice;
200
+ }
201
+ let meta = decodeProductMeta(buf, offset, end);
202
+ if (meta.fix === null) {
203
+ const hit = scanGpsPair(buf, offset, end);
204
+ if (hit)
205
+ meta = { ...meta, fix: hit.fix, noLock: false };
206
+ }
207
+ if (meta.noLock)
208
+ noLock++;
209
+ if (meta.fix !== null || keepAll) {
210
+ const tSec = Number.isFinite(packet.tSec) ? packet.tSec : 0;
211
+ samples.push(toCamSample(meta, tSec));
212
+ }
213
+ offset = end;
214
+ }
215
+ return { samples, noLock, provenance: { protoFile, gimbalDevice } };
216
+ }
217
+ export function scanBufferForGpsPairs(buf) {
218
+ const samples = [];
219
+ for (let i = 0; i <= buf.length - GPS_PAIR_SPAN; i++) {
220
+ const hit = scanGpsPair(buf, i, i + GPS_PAIR_SPAN);
221
+ if (hit) {
222
+ const meta = emptyProductMeta();
223
+ meta.fix = hit.fix;
224
+ samples.push(toCamSample(meta, 0));
225
+ i += GPS_PAIR_SPAN - 1;
226
+ }
227
+ }
228
+ return samples;
229
+ }
230
+ export function spreadSampleTimes(samples, durationSec) {
231
+ const span = Number.isFinite(durationSec) && durationSec > 0
232
+ ? durationSec
233
+ : samples.length;
234
+ samples.forEach((sample, k) => {
235
+ sample.tSec = (k / Math.max(1, samples.length - 1)) * span;
236
+ });
237
+ }
@@ -0,0 +1,5 @@
1
+ import type { CamMetaResult } from './cammeta-decode.js';
2
+ import type { FfmpegToolPaths } from './ffmpeg-tools.js';
3
+ export declare function parseCamMeta(tools: FfmpegToolPaths, videoPath: string, durationSec: number, opts?: {
4
+ keepAll?: boolean;
5
+ }): Promise<CamMetaResult | null>;
@@ -0,0 +1,92 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { decodePacketSamples, scanBufferForGpsPairs, spreadSampleTimes, } from './cammeta-decode.js';
5
+ import { runTool } from './exec-tool.js';
6
+ import { ffprobeJson } from './ffmpeg.js';
7
+ const FFMPEG_MAX_BUFFER = 64 * 1024 * 1024;
8
+ async function findCamMetaIndex(tools, videoPath) {
9
+ let probe;
10
+ try {
11
+ probe = await ffprobeJson(tools, videoPath, [
12
+ '-select_streams',
13
+ 'd',
14
+ '-show_entries',
15
+ 'stream=index:stream_tags=handler_name',
16
+ '-of',
17
+ 'json',
18
+ ]);
19
+ }
20
+ catch (e) {
21
+ throw new Error('ffprobe failed while probing the cam meta stream', { cause: e });
22
+ }
23
+ const streams = (probe['streams'] ?? []);
24
+ for (const stream of streams) {
25
+ if (stream.tags && stream.tags.handler_name === 'CAM meta')
26
+ return stream.index;
27
+ }
28
+ return null;
29
+ }
30
+ async function listCamMetaPackets(tools, videoPath, streamIndex) {
31
+ let probe;
32
+ try {
33
+ probe = await ffprobeJson(tools, videoPath, [
34
+ // NOTE: bare stream index - `d:N` would mean the N-th *data* stream.
35
+ '-select_streams',
36
+ String(streamIndex),
37
+ '-show_entries',
38
+ 'packet=pts_time,size',
39
+ '-of',
40
+ 'json',
41
+ ]);
42
+ }
43
+ catch (e) {
44
+ throw new Error('ffprobe failed while listing the cam meta packets', { cause: e });
45
+ }
46
+ return (probe['packets'] ?? []).map((packet) => ({
47
+ tSec: Number.parseFloat(packet.pts_time),
48
+ size: Number.parseInt(packet.size, 10),
49
+ }));
50
+ }
51
+ async function dumpCamMetaStream(tools, videoPath, streamIndex) {
52
+ const tmp = path.join(os.tmpdir(), `cammeta_${process.pid}_${Date.now().toString(36)}.bin`);
53
+ try {
54
+ try {
55
+ await runTool(tools.ffmpeg, [
56
+ '-v', 'error', '-y', '-i', videoPath,
57
+ '-map', `0:${streamIndex}`, '-c', 'copy', '-f', 'rawvideo', tmp,
58
+ ], { maxBuffer: FFMPEG_MAX_BUFFER });
59
+ }
60
+ catch (e) {
61
+ throw new Error('ffmpeg failed while dumping the cam meta stream', { cause: e });
62
+ }
63
+ return fs.readFileSync(tmp);
64
+ }
65
+ finally {
66
+ fs.rmSync(tmp, { force: true });
67
+ }
68
+ }
69
+ // Resolves to null only when the video carries no CAM meta stream at all; a
70
+ // present stream that yields nothing decodable resolves to empty samples so
71
+ // callers can tell absence from a stream without GPS fix pairs.
72
+ export async function parseCamMeta(tools, videoPath, durationSec, opts = {}) {
73
+ const streamIndex = await findCamMetaIndex(tools, videoPath);
74
+ if (streamIndex === null)
75
+ return null;
76
+ const packets = await listCamMetaPackets(tools, videoPath, streamIndex);
77
+ const buf = await dumpCamMetaStream(tools, videoPath, streamIndex);
78
+ const sizeSum = packets.reduce((sum, packet) => sum + (Number.isFinite(packet.size) ? packet.size : 0), 0);
79
+ if (buf.length > 0 && packets.length > 0 && sizeSum === buf.length) {
80
+ const { samples, noLock, provenance } = decodePacketSamples(buf, packets, opts.keepAll === true);
81
+ return { samples, noLock, method: 'dvtm-packets', ...provenance };
82
+ }
83
+ const samples = scanBufferForGpsPairs(buf);
84
+ spreadSampleTimes(samples, durationSec);
85
+ return {
86
+ samples,
87
+ noLock: 0,
88
+ method: 'cammeta-scan',
89
+ protoFile: null,
90
+ gimbalDevice: null,
91
+ };
92
+ }
@@ -0,0 +1,18 @@
1
+ export declare const ERROR_PREFIX = "[drone-path] ERROR: ";
2
+ export declare function errorMessage(error: unknown): string;
3
+ export declare const ERR_NO_RECORDING = "no recording loaded";
4
+ export declare const ERR_EXPORT_ALREADY_RUNNING = "an export is already running";
5
+ export declare const ERR_EXPORT_COULD_NOT_START = "export could not start";
6
+ export declare const ERR_EXPORT_COULD_NOT_BE_CANCELED = "export could not be canceled";
7
+ export declare const ERR_OUTPUT_OVERWRITES_SOURCE = "the output must not overwrite the source recording";
8
+ export declare const ERR_OUTPUT_PATH_ABSOLUTE = "output path must be absolute: ";
9
+ export declare const ERR_APP_BRIDGE_UNAVAILABLE = "app bridge unavailable";
10
+ export declare const ERR_RENDER_CANCELED = "render canceled";
11
+ export declare const ERR_NOT_READABLE_MP4 = "not a readable .mp4 file: ";
12
+ export declare const ERR_NO_TELEMETRY = "no telemetry found: ";
13
+ export declare const ERR_OUTPUT_VERIFICATION = "output verification failed: ";
14
+ export declare const ERR_COULD_NOT_REPLACE = "could not replace ";
15
+ export declare const ERR_RENDER_KEPT_AT = "the finished render is at ";
16
+ export declare const ERR_NO_FRAME_RATE = "could not determine the frame rate of the video";
17
+ export declare const ERR_UNKNOWN = "unknown error";
18
+ export declare function runToolMain(fn: () => void | Promise<void>): Promise<void>;
package/dist/errors.js ADDED
@@ -0,0 +1,34 @@
1
+ export const ERROR_PREFIX = '[drone-path] ERROR: ';
2
+ export function errorMessage(error) {
3
+ return error instanceof Error ? error.message : String(error);
4
+ }
5
+ // The backend-to-UI error protocol: ui/lib/errortext.ts builds its sentence
6
+ // patterns from these exact strings, so every producer spells its message
7
+ // through here — rewording one is greppable and cannot silently downgrade
8
+ // its UI sentence.
9
+ export const ERR_NO_RECORDING = 'no recording loaded';
10
+ export const ERR_EXPORT_ALREADY_RUNNING = 'an export is already running';
11
+ export const ERR_EXPORT_COULD_NOT_START = 'export could not start';
12
+ export const ERR_EXPORT_COULD_NOT_BE_CANCELED = 'export could not be canceled';
13
+ export const ERR_OUTPUT_OVERWRITES_SOURCE = 'the output must not overwrite the source recording';
14
+ export const ERR_OUTPUT_PATH_ABSOLUTE = 'output path must be absolute: ';
15
+ export const ERR_APP_BRIDGE_UNAVAILABLE = 'app bridge unavailable';
16
+ export const ERR_RENDER_CANCELED = 'render canceled';
17
+ export const ERR_NOT_READABLE_MP4 = 'not a readable .mp4 file: ';
18
+ export const ERR_NO_TELEMETRY = 'no telemetry found: ';
19
+ export const ERR_OUTPUT_VERIFICATION = 'output verification failed: ';
20
+ export const ERR_COULD_NOT_REPLACE = 'could not replace ';
21
+ export const ERR_RENDER_KEPT_AT = 'the finished render is at ';
22
+ export const ERR_NO_FRAME_RATE = 'could not determine the frame rate of the video';
23
+ export const ERR_UNKNOWN = 'unknown error';
24
+ // The mandated failure shell for generated-art tool entries (AGENTS.md): one
25
+ // ERROR line on stderr and process.exitCode = 1, never a mid-flow exit.
26
+ export async function runToolMain(fn) {
27
+ try {
28
+ await fn();
29
+ }
30
+ catch (e) {
31
+ process.stderr.write(`${ERROR_PREFIX}${errorMessage(e)}\n`);
32
+ process.exitCode = 1;
33
+ }
34
+ }
@@ -0,0 +1,7 @@
1
+ import type { ExecFileOptions } from 'node:child_process';
2
+ interface ToolOutput {
3
+ stdout: string;
4
+ stderr: string;
5
+ }
6
+ export declare function runTool(command: string, args: readonly string[], opts?: ExecFileOptions): Promise<ToolOutput>;
7
+ export {};
@@ -0,0 +1,14 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ const execFileAsync = promisify(execFile);
4
+ // One child-process seam for src/: command, argv and buffer budget pass
5
+ // through untouched, and the spawned error propagates unwrapped so each
6
+ // caller keeps its own { cause } wording. Tool output is text (utf8).
7
+ // Hide the console window on Windows so GUI callers do not flash a terminal.
8
+ export async function runTool(command, args, opts) {
9
+ const result = await execFileAsync(command, args, { windowsHide: true, ...opts });
10
+ return {
11
+ stdout: String(result?.stdout ?? ''),
12
+ stderr: String(result?.stderr ?? ''),
13
+ };
14
+ }
@@ -0,0 +1,14 @@
1
+ export declare const FFMPEG_TOOL_NAMES: readonly ["ffmpeg", "ffprobe"];
2
+ export type FfmpegToolName = (typeof FFMPEG_TOOL_NAMES)[number];
3
+ export interface FfmpegToolPaths {
4
+ ffmpeg: string;
5
+ ffprobe: string;
6
+ }
7
+ export type FfmpegToolOverrides = Record<FfmpegToolName, string | null>;
8
+ interface FfmpegToolEnv {
9
+ exists: (file: string) => boolean;
10
+ candidates: (tool: FfmpegToolName) => (string | null)[];
11
+ }
12
+ export declare function pickFfmpegTool(tool: FfmpegToolName, override: string | null, candidates: readonly (string | null)[], exists: (file: string) => boolean): string;
13
+ export declare function resolveFfmpegTools(overrides: FfmpegToolOverrides, env?: FfmpegToolEnv): FfmpegToolPaths;
14
+ export {};
@@ -0,0 +1,56 @@
1
+ import fs from 'node:fs';
2
+ import { createRequire } from 'node:module';
3
+ import path from 'node:path';
4
+ export const FFMPEG_TOOL_NAMES = ['ffmpeg', 'ffprobe'];
5
+ function isPathLike(value) {
6
+ return value.includes('/') || value.includes('\\') || path.isAbsolute(value);
7
+ }
8
+ export function pickFfmpegTool(tool, override, candidates, exists) {
9
+ if (override) {
10
+ if (isPathLike(override) && !exists(override)) {
11
+ throw new Error(`invalid ${tool} override (CLI --${tool} or config key \`${tool}\`): no such file: ${override}`);
12
+ }
13
+ return override;
14
+ }
15
+ for (const candidate of candidates) {
16
+ if (candidate && exists(candidate))
17
+ return candidate;
18
+ }
19
+ return tool;
20
+ }
21
+ function exeName(tool) {
22
+ return process.platform === 'win32' ? `${tool}.exe` : tool;
23
+ }
24
+ function packagedCandidate(tool) {
25
+ const resourcesPath = process.resourcesPath;
26
+ return resourcesPath ? path.join(resourcesPath, 'ff', exeName(tool)) : null;
27
+ }
28
+ function devCandidate(tool) {
29
+ try {
30
+ const mod = createRequire(import.meta.url)('ffmpeg-ffprobe-static');
31
+ const candidate = tool === 'ffmpeg' ? mod.ffmpegPath : mod.ffprobePath;
32
+ return typeof candidate === 'string' ? candidate : null;
33
+ }
34
+ catch {
35
+ return null;
36
+ }
37
+ }
38
+ function realEnv() {
39
+ return {
40
+ exists: (file) => {
41
+ try {
42
+ return fs.statSync(file).isFile();
43
+ }
44
+ catch {
45
+ return false;
46
+ }
47
+ },
48
+ candidates: (tool) => [packagedCandidate(tool), devCandidate(tool)],
49
+ };
50
+ }
51
+ export function resolveFfmpegTools(overrides, env = realEnv()) {
52
+ return {
53
+ ffmpeg: pickFfmpegTool('ffmpeg', overrides.ffmpeg, env.candidates('ffmpeg'), env.exists),
54
+ ffprobe: pickFfmpegTool('ffprobe', overrides.ffprobe, env.candidates('ffprobe'), env.exists),
55
+ };
56
+ }
@@ -0,0 +1,21 @@
1
+ import type { Fps } from './frametime.js';
2
+ import type { FfmpegToolPaths } from './ffmpeg-tools.js';
3
+ export interface VideoProbe {
4
+ fps: Fps;
5
+ frames: number;
6
+ durationSec: number;
7
+ width: number;
8
+ height: number;
9
+ }
10
+ export declare function requireFfmpegTools(tools: FfmpegToolPaths): Promise<void>;
11
+ export declare function ffprobeJson(tools: FfmpegToolPaths, videoPath: string, args: string[]): Promise<Record<string, unknown>>;
12
+ interface ProbeStream {
13
+ r_frame_rate?: string;
14
+ avg_frame_rate?: string;
15
+ nb_frames?: string;
16
+ width?: number;
17
+ height?: number;
18
+ }
19
+ export declare function firstVideoStream(j: Record<string, unknown>): ProbeStream;
20
+ export declare function probeVideo(tools: FfmpegToolPaths, videoPath: string, log?: (msg: string) => void): Promise<VideoProbe>;
21
+ export {};