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
@@ -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
+ }
package/dist/cammeta.js CHANGED
@@ -1,64 +1,10 @@
1
- import { execFile } from 'node:child_process';
2
1
  import fs from 'node:fs';
3
2
  import os from 'node:os';
4
3
  import path from 'node:path';
5
- import { promisify } from 'node:util';
6
- import { ffprobeJson } from './ff.js';
7
- import { gpsFix } from './geo.js';
8
- import { firstDouble, firstFloat, firstString, firstVarint, parseProtoFields, subMessage, } from './proto.js';
9
- const execFileAsync = promisify(execFile);
10
- // DVTM field numbers; the message layout is documented in docs/telemetry-protobuf.md.
11
- const CLIP_META = 1;
12
- const CLIP_META_HEADER = 1;
13
- const PROTO_FILE_NAME = 1;
14
- const PRODUCT_PROTO_VERSION = 3;
15
- const FRAME_META = 3;
16
- const CAMERA = 2;
17
- const ISO = 3;
18
- const WHITE_BALANCE_CCT = 6;
19
- const ABSOLUTE_ALTITUDE = 11;
20
- const DRONE = 4;
21
- const GPS_BASIC = 4;
22
- const POSITION_COORD = 1;
23
- const GPS_ALTITUDE_MM = 2;
24
- const RELATIVE_ALTITUDE = 5;
25
- const EULER_ANGLE = 3;
26
- const GIMBAL = 5;
27
- const GIMBAL_DEVICE_HEADER = 1;
28
- const GIMBAL_EULER_ANGLE = 2;
29
- const DEVICE_ID = 1;
30
- const DEVICE_TYPE = 2;
31
- const DEVICE_SUB_TYPE = 3;
32
- const DEVICE_NAME = 4;
33
- const DEVICE_FREQUENCY = 5;
34
- const DEVICE_TIMESTAMP = 6;
35
- const VALUE = 1;
36
- const PITCH = 1;
37
- const ROLL = 2;
38
- const YAW = 3;
39
- const LAT = 2;
40
- const LON = 3;
41
- // GPS double-pair wire signature (0x11 lat f64, 0x19 lon f64); see docs/telemetry-protobuf.md.
42
- const GPS_PAIR_SPAN = 18;
4
+ import { decodePacketSamples, scanBufferForGpsPairs, spreadSampleTimes, } from './cammeta-decode.js';
5
+ import { runTool } from './exec-tool.js';
6
+ import { ffprobeJson } from './ffmpeg.js';
43
7
  const FFMPEG_MAX_BUFFER = 64 * 1024 * 1024;
44
- function emptyProductMeta() {
45
- return {
46
- fix: null,
47
- noLock: false,
48
- relAlt: null,
49
- absAlt: null,
50
- yawDeg: null,
51
- pitchDeg: null,
52
- rollDeg: null,
53
- gpsAltMm: null,
54
- gimbalPitchDeg: null,
55
- gimbalRollDeg: null,
56
- gimbalYawDeg: null,
57
- gimbalDeviceTimestampMs: null,
58
- iso: null,
59
- whiteBalanceCctK: null,
60
- };
61
- }
62
8
  async function findCamMetaIndex(tools, videoPath) {
63
9
  let probe;
64
10
  try {
@@ -81,137 +27,6 @@ async function findCamMetaIndex(tools, videoPath) {
81
27
  }
82
28
  return null;
83
29
  }
84
- export function decodeProductMeta(buf, start = 0, end = buf.length) {
85
- const top = parseProtoFields(buf, start, end);
86
- const frameMeta = subMessage(buf, top, FRAME_META);
87
- const camera = frameMeta ? subMessage(buf, frameMeta, CAMERA) : null;
88
- const drone = frameMeta ? subMessage(buf, frameMeta, DRONE) : null;
89
- const gimbal = frameMeta ? subMessage(buf, frameMeta, GIMBAL) : null;
90
- const absAlt = camera ? decodeAbsoluteAltitude(buf, camera) : null;
91
- const gps = drone ? decodeGps(buf, drone) : null;
92
- const euler = drone ? decodeEulerAngles(buf, drone, EULER_ANGLE) : null;
93
- const gimbalEuler = gimbal
94
- ? decodeEulerAngles(buf, gimbal, GIMBAL_EULER_ANGLE)
95
- : null;
96
- const gimbalHeader = gimbal
97
- ? subMessage(buf, gimbal, GIMBAL_DEVICE_HEADER)
98
- : null;
99
- return {
100
- fix: gps?.fix ?? null,
101
- noLock: gps?.noLock ?? false,
102
- relAlt: drone ? decodeRelativeAltitude(buf, drone) : null,
103
- absAlt: absAlt ?? gpsAltMeters(gps?.gpsAltMm ?? null),
104
- yawDeg: euler?.yawDeg ?? null,
105
- pitchDeg: euler?.pitchDeg ?? null,
106
- rollDeg: euler?.rollDeg ?? null,
107
- gpsAltMm: gps?.gpsAltMm ?? null,
108
- gimbalPitchDeg: gimbalEuler?.pitchDeg ?? null,
109
- gimbalRollDeg: gimbalEuler?.rollDeg ?? null,
110
- gimbalYawDeg: gimbalEuler?.yawDeg ?? null,
111
- gimbalDeviceTimestampMs: gimbalHeader
112
- ? (firstVarint(gimbalHeader, DEVICE_TIMESTAMP) ?? 0)
113
- : null,
114
- iso: camera ? decodeCameraVarint(buf, camera, ISO) : null,
115
- whiteBalanceCctK: camera ? decodeCameraVarint(buf, camera, WHITE_BALANCE_CCT) : null,
116
- };
117
- }
118
- function decodeCameraVarint(buf, camera, fieldNumber) {
119
- const message = subMessage(buf, camera, fieldNumber);
120
- return message ? (firstVarint(message, VALUE) ?? 0) : null;
121
- }
122
- function decodeAbsoluteAltitude(buf, camera) {
123
- const absoluteAltitude = subMessage(buf, camera, ABSOLUTE_ALTITUDE);
124
- if (!absoluteAltitude)
125
- return null;
126
- const meters = firstFloat(absoluteAltitude, VALUE) ?? 0;
127
- return Number.isFinite(meters) ? meters : null;
128
- }
129
- function gpsAltMeters(gpsAltMm) {
130
- return gpsAltMm !== null ? gpsAltMm / 1000 : null;
131
- }
132
- function decodeGps(buf, drone) {
133
- const out = { fix: null, noLock: false, gpsAltMm: null };
134
- const gps = subMessage(buf, drone, GPS_BASIC);
135
- if (!gps)
136
- return out;
137
- const coord = subMessage(buf, gps, POSITION_COORD);
138
- if (coord) {
139
- const lat = firstDouble(coord, LAT);
140
- const lon = firstDouble(coord, LON);
141
- if (lat !== null && lon !== null) {
142
- const fix = gpsFix(lat, lon);
143
- if (fix !== null)
144
- out.fix = fix;
145
- else
146
- out.noLock = true;
147
- }
148
- }
149
- out.gpsAltMm = firstVarint(gps, GPS_ALTITUDE_MM) ?? 0;
150
- return out;
151
- }
152
- function decodeRelativeAltitude(buf, drone) {
153
- const relative = subMessage(buf, drone, RELATIVE_ALTITUDE);
154
- if (!relative)
155
- return null;
156
- const millimeters = firstFloat(relative, VALUE) ?? 0;
157
- return Number.isFinite(millimeters) ? millimeters / 1000 : null;
158
- }
159
- function decodeEulerAngles(buf, fields, fieldNumber) {
160
- const euler = subMessage(buf, fields, fieldNumber);
161
- if (!euler)
162
- return null;
163
- return {
164
- pitchDeg: (firstVarint(euler, PITCH) ?? 0) / 10,
165
- rollDeg: (firstVarint(euler, ROLL) ?? 0) / 10,
166
- yawDeg: (firstVarint(euler, YAW) ?? 0) / 10,
167
- };
168
- }
169
- export function decodeProvenance(buf, start = 0, end = buf.length) {
170
- const top = parseProtoFields(buf, start, end);
171
- return {
172
- protoFile: decodeProtoFile(buf, top),
173
- gimbalDevice: decodeGimbalDevice(buf, top),
174
- };
175
- }
176
- function decodeProtoFile(buf, top) {
177
- const clipMeta = subMessage(buf, top, CLIP_META);
178
- const header = clipMeta && subMessage(buf, clipMeta, CLIP_META_HEADER);
179
- if (!header)
180
- return null;
181
- const name = nonEmptyString(buf, header, PROTO_FILE_NAME);
182
- const version = nonEmptyString(buf, header, PRODUCT_PROTO_VERSION);
183
- if (!name)
184
- return null;
185
- return version ? `${name} ${version}` : name;
186
- }
187
- function nonEmptyString(buf, fields, fieldNumber) {
188
- const value = firstString(buf, fields, fieldNumber)?.trim() ?? '';
189
- return value === '' ? null : value;
190
- }
191
- function decodeGimbalDevice(buf, top) {
192
- const frameMeta = subMessage(buf, top, FRAME_META);
193
- const gimbal = frameMeta && subMessage(buf, frameMeta, GIMBAL);
194
- const header = gimbal && subMessage(buf, gimbal, GIMBAL_DEVICE_HEADER);
195
- if (!header)
196
- return null;
197
- return {
198
- id: firstVarint(header, DEVICE_ID) ?? 0,
199
- type: firstVarint(header, DEVICE_TYPE) ?? 0,
200
- subType: firstVarint(header, DEVICE_SUB_TYPE) ?? 0,
201
- name: firstString(buf, header, DEVICE_NAME) ?? '',
202
- frequency: firstFloat(header, DEVICE_FREQUENCY) ?? 0,
203
- };
204
- }
205
- export function scanGpsPair(buf, offset = 0, end = buf.length) {
206
- for (let i = offset; i <= end - GPS_PAIR_SPAN; i++) {
207
- if (buf[i] === 0x11 && buf[i + 9] === 0x19) {
208
- const fix = gpsFix(buf.readDoubleLE(i + 1), buf.readDoubleLE(i + 10));
209
- if (fix !== null)
210
- return { fix, at: i };
211
- }
212
- }
213
- return null;
214
- }
215
30
  async function listCamMetaPackets(tools, videoPath, streamIndex) {
216
31
  let probe;
217
32
  try {
@@ -237,7 +52,7 @@ async function dumpCamMetaStream(tools, videoPath, streamIndex) {
237
52
  const tmp = path.join(os.tmpdir(), `cammeta_${process.pid}_${Date.now().toString(36)}.bin`);
238
53
  try {
239
54
  try {
240
- await execFileAsync(tools.ffmpeg, [
55
+ await runTool(tools.ffmpeg, [
241
56
  '-v', 'error', '-y', '-i', videoPath,
242
57
  '-map', `0:${streamIndex}`, '-c', 'copy', '-f', 'rawvideo', tmp,
243
58
  ], { maxBuffer: FFMPEG_MAX_BUFFER });
@@ -251,59 +66,6 @@ async function dumpCamMetaStream(tools, videoPath, streamIndex) {
251
66
  fs.rmSync(tmp, { force: true });
252
67
  }
253
68
  }
254
- function toCamSample(meta, tSec) {
255
- return { tSec, ...meta };
256
- }
257
- export function decodePacketSamples(buf, packets, keepAll) {
258
- const samples = [];
259
- let noLock = 0;
260
- let offset = 0;
261
- let protoFile = null;
262
- let gimbalDevice = null;
263
- for (const packet of packets) {
264
- const end = offset + packet.size;
265
- if (protoFile === null || gimbalDevice === null) {
266
- const declared = decodeProvenance(buf, offset, end);
267
- protoFile ??= declared.protoFile;
268
- gimbalDevice ??= declared.gimbalDevice;
269
- }
270
- let meta = decodeProductMeta(buf, offset, end);
271
- if (meta.fix === null) {
272
- const hit = scanGpsPair(buf, offset, end);
273
- if (hit)
274
- meta = { ...meta, fix: hit.fix, noLock: false };
275
- }
276
- if (meta.noLock)
277
- noLock++;
278
- if (meta.fix !== null || keepAll) {
279
- const tSec = Number.isFinite(packet.tSec) ? packet.tSec : 0;
280
- samples.push(toCamSample(meta, tSec));
281
- }
282
- offset = end;
283
- }
284
- return { samples, noLock, provenance: { protoFile, gimbalDevice } };
285
- }
286
- function scanBufferForGpsPairs(buf) {
287
- const samples = [];
288
- for (let i = 0; i <= buf.length - GPS_PAIR_SPAN; i++) {
289
- const hit = scanGpsPair(buf, i, i + GPS_PAIR_SPAN);
290
- if (hit) {
291
- const meta = emptyProductMeta();
292
- meta.fix = hit.fix;
293
- samples.push(toCamSample(meta, 0));
294
- i += GPS_PAIR_SPAN - 1;
295
- }
296
- }
297
- return samples;
298
- }
299
- function spreadSampleTimes(samples, durationSec) {
300
- const span = Number.isFinite(durationSec) && durationSec > 0
301
- ? durationSec
302
- : samples.length;
303
- samples.forEach((sample, k) => {
304
- sample.tSec = (k / Math.max(1, samples.length - 1)) * span;
305
- });
306
- }
307
69
  // Resolves to null only when the video carries no CAM meta stream at all; a
308
70
  // present stream that yields nothing decodable resolves to empty samples so
309
71
  // callers can tell absence from a stream without GPS fix pairs.
package/dist/cli.js CHANGED
@@ -2,12 +2,12 @@ import fs from 'node:fs';
2
2
  import { Command, Option } from 'commander';
3
3
  import { ERROR_PREFIX, errorMessage } from './errors.js';
4
4
  import { VERSION } from './version.js';
5
- import { CONFIG_FILE_OPTION, CONFIG_OPTIONS, cliDefaultOf } from './config.js';
5
+ import { CONFIG_FILE_OPTION, CONFIG_OPTIONS, OVERRIDE_NORMALIZERS, TELEMETRY_JSON_ALIAS, cliDefaultOf, } from './config.js';
6
6
  import { resolveConfig } from './configfile.js';
7
- import { collectRecordings } from './inputs.js';
8
- import { requireTools } from './ff.js';
9
- import { resolveFfTools } from './fftools.js';
10
- import { runBatch } from './run.js';
7
+ import { collectRecordings } from './recordings.js';
8
+ import { requireFfmpegTools } from './ffmpeg.js';
9
+ import { resolveFfmpegTools } from './ffmpeg-tools.js';
10
+ import { runBatch } from './pipeline.js';
11
11
  export function buildProgram() {
12
12
  const program = new Command();
13
13
  program
@@ -26,6 +26,7 @@ export function buildProgram() {
26
26
  option.default(defaultValue);
27
27
  program.addOption(option);
28
28
  }
29
+ program.addOption(new Option(TELEMETRY_JSON_ALIAS.flags, TELEMETRY_JSON_ALIAS.help));
29
30
  program.option(CONFIG_FILE_OPTION.flags, CONFIG_FILE_OPTION.help);
30
31
  return program;
31
32
  }
@@ -36,7 +37,7 @@ export function longFlagOf(flags) {
36
37
  const tokens = flags.split(/[ ,|]+/);
37
38
  return tokens.find((token) => token.startsWith('--')) ?? tokens[0];
38
39
  }
39
- function collectOverrides(program) {
40
+ function collectOverrides(program, onDeprecated) {
40
41
  const opts = program.opts();
41
42
  const cli = {};
42
43
  for (const row of CONFIG_OPTIONS) {
@@ -46,17 +47,35 @@ function collectOverrides(program) {
46
47
  const raw = row.cli.parse ? row.cli.parse(opts[row.key]) : opts[row.key];
47
48
  Object.assign(cli, row.normalize(raw, flag));
48
49
  }
49
- return cli;
50
+ // The deprecated alias lands on the same trackOut override key; both
51
+ // spellings at once is ambiguous and rejected.
52
+ if (givenOnCommandLine(program, TELEMETRY_JSON_ALIAS.inputKey)) {
53
+ if (givenOnCommandLine(program, TELEMETRY_JSON_ALIAS.key)) {
54
+ throw new Error(`${longFlagOf(TELEMETRY_JSON_ALIAS.flags)} and --track-out cannot be combined (use --track-out)`);
55
+ }
56
+ onDeprecated(TELEMETRY_JSON_ALIAS.cliWarning);
57
+ Object.assign(cli, OVERRIDE_NORMALIZERS.trackOut(opts[TELEMETRY_JSON_ALIAS.inputKey], longFlagOf(TELEMETRY_JSON_ALIAS.flags)));
58
+ }
59
+ const trackOutSpelling = givenOnCommandLine(program, TELEMETRY_JSON_ALIAS.inputKey)
60
+ ? 'telemetry-json'
61
+ : givenOnCommandLine(program, TELEMETRY_JSON_ALIAS.key)
62
+ ? 'track-out'
63
+ : null;
64
+ return { cli, trackOutSpelling };
50
65
  }
51
66
  export function parseCliArgs(argv) {
52
67
  const program = buildProgram();
53
68
  program.exitOverride();
54
69
  program.parse(argv, { from: 'user' });
55
70
  const opts = program.opts();
71
+ const deprecationWarnings = [];
72
+ const collected = collectOverrides(program, (message) => deprecationWarnings.push(message));
56
73
  return {
57
74
  inputs: [...program.args],
58
- cli: collectOverrides(program),
75
+ cli: collected.cli,
76
+ trackOutSpelling: collected.trackOutSpelling,
59
77
  configPath: typeof opts.config === 'string' ? opts.config : null,
78
+ deprecationWarnings,
60
79
  };
61
80
  }
62
81
  function isCommanderExit(e) {
@@ -73,11 +92,14 @@ function commanderExitCode(e) {
73
92
  }
74
93
  function resolveInvocation(argv) {
75
94
  const parsed = parseCliArgs(argv.slice(2));
95
+ const deprecationWarnings = [...parsed.deprecationWarnings];
76
96
  const { config, configPath } = resolveConfig({
77
97
  cli: parsed.cli,
78
98
  configPath: parsed.configPath,
99
+ cliTrackOutSpelling: parsed.trackOutSpelling,
100
+ onDeprecated: (message) => deprecationWarnings.push(message),
79
101
  });
80
- return { inputs: parsed.inputs, config, configPath };
102
+ return { inputs: parsed.inputs, config, configPath, deprecationWarnings };
81
103
  }
82
104
  function createLogger(config) {
83
105
  return (msg) => {
@@ -87,8 +109,8 @@ function createLogger(config) {
87
109
  }
88
110
  async function runPipeline(invocation, log) {
89
111
  const { inputs, config, configPath } = invocation;
90
- const tools = resolveFfTools(config);
91
- await requireTools(tools);
112
+ const tools = resolveFfmpegTools(config);
113
+ await requireFfmpegTools(tools);
92
114
  const videos = collectRecordings(inputs, { recurse: config.recurse });
93
115
  if (config.outDir)
94
116
  fs.mkdirSync(config.outDir, { recursive: true });
@@ -109,6 +131,10 @@ async function runPipeline(invocation, log) {
109
131
  export async function main(argv = process.argv) {
110
132
  try {
111
133
  const invocation = resolveInvocation(argv);
134
+ // Deprecation warnings are not progress output: they print even with --quiet.
135
+ for (const warning of invocation.deprecationWarnings) {
136
+ process.stderr.write(`[drone-path] ${warning}\n`);
137
+ }
112
138
  const log = createLogger(invocation.config);
113
139
  await runPipeline(invocation, log);
114
140
  }