drone-path-engine 0.0.0-stage → 1.0.0-rc1
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/LICENSE +21 -0
- package/README.md +33 -2
- package/THIRD-PARTY-NOTICES.md +11 -0
- package/dist/assets.d.ts +34 -0
- package/dist/assets.js +60 -0
- package/dist/config.d.ts +207 -0
- package/dist/config.js +581 -0
- package/dist/configfile.d.ts +20 -0
- package/dist/configfile.js +86 -0
- package/dist/decimate.d.ts +11 -0
- package/dist/decimate.js +84 -0
- package/dist/ffmpeg-output.d.ts +9 -0
- package/dist/ffmpeg-output.js +40 -0
- package/dist/logging.d.ts +1 -0
- package/dist/logging.js +1 -0
- package/dist/paths.d.ts +4 -0
- package/dist/paths.js +21 -0
- package/dist/pipeline.d.ts +90 -0
- package/dist/pipeline.js +430 -0
- package/dist/plan.d.ts +47 -0
- package/dist/plan.js +112 -0
- package/dist/png.d.ts +1 -0
- package/dist/png.js +32 -0
- package/dist/range.d.ts +19 -0
- package/dist/range.js +50 -0
- package/dist/recordings.d.ts +5 -0
- package/dist/recordings.js +45 -0
- package/dist/render-page.d.ts +35 -0
- package/dist/render-page.js +85 -0
- package/dist/render.d.ts +57 -0
- package/dist/render.js +397 -0
- package/dist/renderer/boot.d.ts +4 -0
- package/dist/renderer/boot.js +28 -0
- package/dist/renderer/dom.d.ts +28 -0
- package/dist/renderer/dom.js +179 -0
- package/dist/renderer/framemath.d.ts +5 -0
- package/dist/renderer/framemath.js +30 -0
- package/dist/renderer/scene.d.ts +38 -0
- package/dist/renderer/scene.js +401 -0
- package/dist/renderer/theme.d.ts +13 -0
- package/dist/renderer/theme.js +82 -0
- package/dist/renderer/tilesources.d.ts +14 -0
- package/dist/renderer/tilesources.js +38 -0
- package/dist/renderer/trail.d.ts +18 -0
- package/dist/renderer/trail.js +42 -0
- package/dist/restyle.d.ts +13 -0
- package/dist/restyle.js +16 -0
- package/dist/serve.d.ts +6 -0
- package/dist/serve.js +27 -0
- package/dist/tilecache.d.ts +12 -0
- package/dist/tilecache.js +21 -0
- package/dist/tiles.d.ts +25 -0
- package/dist/tiles.js +215 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/package.json +37 -4
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface DecimatedTrack {
|
|
2
|
+
lat: number[];
|
|
3
|
+
lon: number[];
|
|
4
|
+
frame: number[];
|
|
5
|
+
}
|
|
6
|
+
interface DecimateOptions {
|
|
7
|
+
epsilonPx?: number;
|
|
8
|
+
maxPoints?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function decimateTrack(lat: readonly number[], lon: readonly number[], zoom: number, options?: DecimateOptions): DecimatedTrack;
|
|
11
|
+
export {};
|
package/dist/decimate.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { project } from 'drone-path-core/geo';
|
|
2
|
+
const DEFAULT_EPSILON_PX = 1;
|
|
3
|
+
const DEFAULT_MAX_POINTS = 3000;
|
|
4
|
+
export function decimateTrack(lat, lon, zoom, options = {}) {
|
|
5
|
+
const epsilonPx = options.epsilonPx ?? DEFAULT_EPSILON_PX;
|
|
6
|
+
const maxPoints = options.maxPoints ?? DEFAULT_MAX_POINTS;
|
|
7
|
+
if (!(epsilonPx >= 0))
|
|
8
|
+
throw new Error('epsilon must be >= 0');
|
|
9
|
+
if (!Number.isInteger(maxPoints) || maxPoints < 2) {
|
|
10
|
+
throw new Error('maxPoints must be an integer >= 2');
|
|
11
|
+
}
|
|
12
|
+
if (lat.length !== lon.length) {
|
|
13
|
+
throw new Error('lat and lon must have the same length');
|
|
14
|
+
}
|
|
15
|
+
const n = lat.length;
|
|
16
|
+
if (n === 0)
|
|
17
|
+
return { lat: [], lon: [], frame: [] };
|
|
18
|
+
if (n === 1)
|
|
19
|
+
return { lat: [lat[0]], lon: [lon[0]], frame: [0] };
|
|
20
|
+
const px = new Array(n);
|
|
21
|
+
for (let i = 0; i < n; i++)
|
|
22
|
+
px[i] = project(lon[i], lat[i], zoom);
|
|
23
|
+
let keep = douglasPeucker(px, epsilonPx);
|
|
24
|
+
if (keep.length > maxPoints) {
|
|
25
|
+
let hi = epsilonPx > 0 ? epsilonPx * 2 : 1;
|
|
26
|
+
let hiKeep = douglasPeucker(px, hi);
|
|
27
|
+
while (hiKeep.length > maxPoints) {
|
|
28
|
+
hi *= 2;
|
|
29
|
+
hiKeep = douglasPeucker(px, hi);
|
|
30
|
+
}
|
|
31
|
+
keep = hiKeep;
|
|
32
|
+
}
|
|
33
|
+
const track = { lat: [], lon: [], frame: [] };
|
|
34
|
+
for (const i of keep) {
|
|
35
|
+
track.lat.push(lat[i]);
|
|
36
|
+
track.lon.push(lon[i]);
|
|
37
|
+
track.frame.push(i);
|
|
38
|
+
}
|
|
39
|
+
return track;
|
|
40
|
+
}
|
|
41
|
+
function douglasPeucker(px, epsilon) {
|
|
42
|
+
const n = px.length;
|
|
43
|
+
const keep = new Uint8Array(n);
|
|
44
|
+
keep[0] = 1;
|
|
45
|
+
keep[n - 1] = 1;
|
|
46
|
+
const stack = [0, n - 1];
|
|
47
|
+
while (stack.length > 0) {
|
|
48
|
+
const end = stack.pop();
|
|
49
|
+
const start = stack.pop();
|
|
50
|
+
if (end - start < 2)
|
|
51
|
+
continue;
|
|
52
|
+
const a = px[start];
|
|
53
|
+
const b = px[end];
|
|
54
|
+
const mid = (start + end) / 2;
|
|
55
|
+
let maxDist = -1;
|
|
56
|
+
let maxIdx = -1;
|
|
57
|
+
for (let i = start + 1; i < end; i++) {
|
|
58
|
+
const d = distanceToSegment(px[i], a, b);
|
|
59
|
+
if (d > maxDist ||
|
|
60
|
+
(d === maxDist && Math.abs(i - mid) < Math.abs(maxIdx - mid))) {
|
|
61
|
+
maxDist = d;
|
|
62
|
+
maxIdx = i;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (maxDist > epsilon) {
|
|
66
|
+
keep[maxIdx] = 1;
|
|
67
|
+
stack.push(start, maxIdx, maxIdx, end);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const indices = [];
|
|
71
|
+
for (let i = 0; i < n; i++)
|
|
72
|
+
if (keep[i])
|
|
73
|
+
indices.push(i);
|
|
74
|
+
return indices;
|
|
75
|
+
}
|
|
76
|
+
function distanceToSegment(p, a, b) {
|
|
77
|
+
const dx = b.x - a.x;
|
|
78
|
+
const dy = b.y - a.y;
|
|
79
|
+
const lenSq = dx * dx + dy * dy;
|
|
80
|
+
if (lenSq === 0)
|
|
81
|
+
return Math.sqrt((p.x - a.x) ** 2 + (p.y - a.y) ** 2);
|
|
82
|
+
const t = Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / lenSq));
|
|
83
|
+
return Math.sqrt((p.x - (a.x + t * dx)) ** 2 + (p.y - (a.y + t * dy)) ** 2);
|
|
84
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FfmpegToolPaths } from 'drone-path-core/ffmpeg-tools';
|
|
2
|
+
interface OutputVerifyResult {
|
|
3
|
+
frames: number;
|
|
4
|
+
fps: string | null;
|
|
5
|
+
ok: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function verifyOutput(tools: FfmpegToolPaths, outPath: string, frames: number, fpsValue: number): Promise<OutputVerifyResult>;
|
|
8
|
+
export declare function outputMatchesSource(tools: FfmpegToolPaths, src: string, out: string): Promise<boolean>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { runTool } from 'drone-path-core/exec-tool';
|
|
2
|
+
import { ffprobeJson, firstVideoStream } from 'drone-path-core/ffmpeg';
|
|
3
|
+
import { parseRate } from 'drone-path-core/frametime';
|
|
4
|
+
const RATE_PROBE_MAX_BUFFER = 1 << 20;
|
|
5
|
+
export async function verifyOutput(tools, outPath, frames, fpsValue) {
|
|
6
|
+
const j = await ffprobeJson(tools, outPath, [
|
|
7
|
+
'-select_streams', 'v:0',
|
|
8
|
+
'-show_entries', 'stream=nb_frames,r_frame_rate',
|
|
9
|
+
'-of', 'json',
|
|
10
|
+
]);
|
|
11
|
+
const stream = firstVideoStream(j);
|
|
12
|
+
const gotFrames = Number.parseInt(stream.nb_frames ?? '', 10);
|
|
13
|
+
const rate = parseRate(stream.r_frame_rate ?? '0/0');
|
|
14
|
+
const gotValue = rate ? (rate.den ? rate.num / rate.den : rate.num) : null;
|
|
15
|
+
return {
|
|
16
|
+
frames: gotFrames,
|
|
17
|
+
fps: stream.r_frame_rate ?? null,
|
|
18
|
+
ok: gotFrames === frames &&
|
|
19
|
+
gotValue !== null &&
|
|
20
|
+
Math.abs(gotValue - fpsValue) < 1e-6,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async function probeRateFrames(ffprobe, file) {
|
|
24
|
+
const { stdout } = await runTool(ffprobe, [
|
|
25
|
+
'-v', 'error', '-select_streams', 'v:0',
|
|
26
|
+
'-show_entries', 'stream=avg_frame_rate,nb_frames',
|
|
27
|
+
'-of', 'csv=p=0', '--', file,
|
|
28
|
+
], { maxBuffer: RATE_PROBE_MAX_BUFFER });
|
|
29
|
+
return stdout.trim();
|
|
30
|
+
}
|
|
31
|
+
export async function outputMatchesSource(tools, src, out) {
|
|
32
|
+
try {
|
|
33
|
+
const [srcRate, srcFrames] = (await probeRateFrames(tools.ffprobe, src)).split(',');
|
|
34
|
+
const [outRate, outFrames] = (await probeRateFrames(tools.ffprobe, out)).split(',');
|
|
35
|
+
return Number(outFrames) > 0 && srcRate === outRate && srcFrames === outFrames;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type LogFn = (msg: string) => void;
|
package/dist/logging.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function pathKey(p: string, platform?: NodeJS.Platform): string;
|
|
2
|
+
export declare function samePath(a: string, b: string, platform?: NodeJS.Platform): boolean;
|
|
3
|
+
export declare function uniquePath(dir: string, stem: string, ext: string, isTaken: (candidate: string) => boolean): string;
|
|
4
|
+
export declare function userDataDir(): string;
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export function pathKey(p, platform = process.platform) {
|
|
4
|
+
const resolved = platform === 'win32' ? path.win32.resolve(p) : path.posix.resolve(p);
|
|
5
|
+
return platform === 'win32' ? resolved.toLowerCase() : resolved;
|
|
6
|
+
}
|
|
7
|
+
export function samePath(a, b, platform = process.platform) {
|
|
8
|
+
return pathKey(a, platform) === pathKey(b, platform);
|
|
9
|
+
}
|
|
10
|
+
export function uniquePath(dir, stem, ext, isTaken) {
|
|
11
|
+
for (let n = 1;; n++) {
|
|
12
|
+
const name = n === 1 ? `${stem}${ext}` : `${stem}-${n}${ext}`;
|
|
13
|
+
const candidate = path.join(dir, name);
|
|
14
|
+
if (!isTaken(candidate))
|
|
15
|
+
return candidate;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function userDataDir() {
|
|
19
|
+
const base = process.env['LOCALAPPDATA'] ?? path.join(os.homedir(), '.cache');
|
|
20
|
+
return path.join(base, 'drone-path');
|
|
21
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Bbox } from 'drone-path-core/geo';
|
|
2
|
+
import { probeVideo } from 'drone-path-core/ffmpeg';
|
|
3
|
+
import { outputMatchesSource, verifyOutput } from './ffmpeg-output.js';
|
|
4
|
+
import type { FfmpegToolPaths } from 'drone-path-core/ffmpeg-tools';
|
|
5
|
+
import type { VideoProbe } from 'drone-path-core/ffmpeg';
|
|
6
|
+
import type { GimbalDeviceConstants } from 'drone-path-core/cammeta-decode';
|
|
7
|
+
import { loadTelemetry } from 'drone-path-core/telemetry';
|
|
8
|
+
import type { FrameChannels, Telemetry } from 'drone-path-core/telemetry-math';
|
|
9
|
+
import type { TelemetryDocumentInput, TelemetryFrameInput } from 'drone-path-core/telemetry-json';
|
|
10
|
+
import type { TrackRecord, TrackStream } from 'drone-path-core/track';
|
|
11
|
+
import { prefetchTiles } from './tiles.js';
|
|
12
|
+
import { INITIAL_PREPARE_PROGRESS } from './plan.js';
|
|
13
|
+
import type { IntroOutroFrames, OverviewPlan, PrepareProgress, PrepareStage } from './plan.js';
|
|
14
|
+
import type { RenderPageOpts } from './render-page.js';
|
|
15
|
+
import { renderVideo } from './render.js';
|
|
16
|
+
import type { CaptureProgress } from './render.js';
|
|
17
|
+
import type { HudLayout, RenderConfig } from './config.js';
|
|
18
|
+
import type { FrameRange } from 'drone-path-core/frame-range';
|
|
19
|
+
import type { TelemetrySummary } from 'drone-path-core/telemetry-summary';
|
|
20
|
+
import type { LogFn } from './logging.js';
|
|
21
|
+
export { INITIAL_PREPARE_PROGRESS };
|
|
22
|
+
export type { PrepareProgress, PrepareStage };
|
|
23
|
+
export type PrepareProgressFn = (progress: PrepareProgress) => void;
|
|
24
|
+
export interface RecordingSummary extends Partial<Pick<TelemetrySummary, 'source' | 'method' | 'headingMode' | 'noLock' | 'trackDistanceM'>>, Partial<Pick<RenderConfig, 'width' | 'height' | 'style' | 'view' | 'zoom' | 'zoomOut'>> {
|
|
25
|
+
video: string;
|
|
26
|
+
out: string;
|
|
27
|
+
status: 'ok' | 'skipped' | 'error';
|
|
28
|
+
fixes?: TelemetrySummary['fixCount'];
|
|
29
|
+
introFrames?: number;
|
|
30
|
+
outroFrames?: number;
|
|
31
|
+
hud?: HudLayout;
|
|
32
|
+
frames?: number;
|
|
33
|
+
fps?: string;
|
|
34
|
+
frameRange?: FrameRange;
|
|
35
|
+
bbox?: Bbox;
|
|
36
|
+
zoomFixed?: boolean;
|
|
37
|
+
tilesDownloaded?: number;
|
|
38
|
+
verified?: boolean;
|
|
39
|
+
elapsedSec: number;
|
|
40
|
+
error?: string;
|
|
41
|
+
}
|
|
42
|
+
interface BatchResult {
|
|
43
|
+
ok: number;
|
|
44
|
+
skipped: number;
|
|
45
|
+
failed: number;
|
|
46
|
+
}
|
|
47
|
+
export declare function outputPathFor(videoPath: string, config: RenderConfig): string;
|
|
48
|
+
interface PlannedOutput {
|
|
49
|
+
out: string;
|
|
50
|
+
plain: string;
|
|
51
|
+
}
|
|
52
|
+
export declare function planOutputs(videos: string[], config: RenderConfig): PlannedOutput[];
|
|
53
|
+
export declare function frameChannelsOf(tel: Telemetry): FrameChannels;
|
|
54
|
+
export type TileWarmFn = (options: Omit<Parameters<typeof prefetchTiles>[0], 'cacheDir'>) => ReturnType<typeof prefetchTiles>;
|
|
55
|
+
export interface PipelineDeps {
|
|
56
|
+
probeVideo: typeof probeVideo;
|
|
57
|
+
loadTelemetry: typeof loadTelemetry;
|
|
58
|
+
prefetchTiles: TileWarmFn;
|
|
59
|
+
renderVideo: typeof renderVideo;
|
|
60
|
+
verifyOutput: typeof verifyOutput;
|
|
61
|
+
outputMatchesSource: typeof outputMatchesSource;
|
|
62
|
+
}
|
|
63
|
+
interface PipelineOptions {
|
|
64
|
+
deps?: Partial<PipelineDeps>;
|
|
65
|
+
tools?: FfmpegToolPaths;
|
|
66
|
+
range?: FrameRange;
|
|
67
|
+
signal?: AbortSignal;
|
|
68
|
+
onProgress?: PrepareProgressFn;
|
|
69
|
+
onCapture?: (progress: CaptureProgress) => void;
|
|
70
|
+
}
|
|
71
|
+
interface PreparedRecording {
|
|
72
|
+
width: number;
|
|
73
|
+
height: number;
|
|
74
|
+
probe: VideoProbe;
|
|
75
|
+
tel: Telemetry;
|
|
76
|
+
frameValues: TelemetryFrameInput[];
|
|
77
|
+
trackValues: TrackRecord[];
|
|
78
|
+
protoFile: string | null;
|
|
79
|
+
gimbalDevice: GimbalDeviceConstants | null;
|
|
80
|
+
hud: HudLayout;
|
|
81
|
+
introOutro: IntroOutroFrames;
|
|
82
|
+
overview: OverviewPlan;
|
|
83
|
+
frames: FrameChannels;
|
|
84
|
+
}
|
|
85
|
+
export declare function prepareSession(videoPath: string, config: RenderConfig, log: LogFn, options?: PipelineOptions): Promise<PreparedRecording>;
|
|
86
|
+
export declare function recordingPageOpts(prep: PreparedRecording, config: RenderConfig): RenderPageOpts;
|
|
87
|
+
export declare function telemetryExportInput(prep: PreparedRecording): TelemetryDocumentInput;
|
|
88
|
+
export declare function trackExportStream(prep: PreparedRecording): TrackStream;
|
|
89
|
+
export declare function processRecording(videoPath: string, config: RenderConfig, log: LogFn, outPath?: string, options?: PipelineOptions): Promise<RecordingSummary>;
|
|
90
|
+
export declare function runBatch(videos: string[], config: RenderConfig, log: LogFn, emit: (summary: RecordingSummary) => void, options?: PipelineOptions): Promise<BatchResult>;
|