drone-path-engine 0.0.0-stage → 1.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/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 +208 -0
- package/dist/config.js +577 -0
- package/dist/configfile.d.ts +20 -0
- package/dist/configfile.js +82 -0
- package/dist/decimate.d.ts +2 -0
- package/dist/decimate.js +1 -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 +436 -0
- package/dist/plan.d.ts +47 -0
- package/dist/plan.js +113 -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 +394 -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,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>;
|
package/dist/pipeline.js
ADDED
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { ERR_OUTPUT_VERIFICATION, ERR_RENDER_CANCELED, errorMessage } from 'drone-path-core/errors';
|
|
4
|
+
import { probeVideo } from 'drone-path-core/ffmpeg';
|
|
5
|
+
import { outputMatchesSource, verifyOutput } from './ffmpeg-output.js';
|
|
6
|
+
import { resolveFfmpegTools } from 'drone-path-core/ffmpeg-tools';
|
|
7
|
+
import { videoBaseName } from './recordings.js';
|
|
8
|
+
import { pathKey, uniquePath } from './paths.js';
|
|
9
|
+
import { loadTelemetry } from 'drone-path-core/telemetry';
|
|
10
|
+
import { writeTrackFile } from 'drone-path-core/track-write';
|
|
11
|
+
import { prefetchTiles } from './tiles.js';
|
|
12
|
+
import { INITIAL_PREPARE_PROGRESS, PREPARE_STAGE_ORDER, planIntroOutroFrames, planView, } from './plan.js';
|
|
13
|
+
import { buildPageHtml, planPageOpts } from './render-page.js';
|
|
14
|
+
import { renderVideo } from './render.js';
|
|
15
|
+
import { effectiveZoomOut, hasAltitude, resolveHudLayout } from './config.js';
|
|
16
|
+
import { resolveFrameRange } from 'drone-path-core/frame-range';
|
|
17
|
+
import { fixCountLabel, noLockCountLabel, telemetrySummary, trackDistanceLabel, } from 'drone-path-core/telemetry-summary';
|
|
18
|
+
export { INITIAL_PREPARE_PROGRESS };
|
|
19
|
+
export function outputPathFor(videoPath, config) {
|
|
20
|
+
const base = videoBaseName(videoPath);
|
|
21
|
+
const name = `${base}${config.outSuffix}.mp4`;
|
|
22
|
+
return config.outDir
|
|
23
|
+
? path.join(config.outDir, name)
|
|
24
|
+
: path.join(path.dirname(videoPath), name);
|
|
25
|
+
}
|
|
26
|
+
export function planOutputs(videos, config) {
|
|
27
|
+
const used = new Set();
|
|
28
|
+
return videos.map((video) => {
|
|
29
|
+
const plain = outputPathFor(video, config);
|
|
30
|
+
const key = pathKey(plain);
|
|
31
|
+
if (!used.has(key)) {
|
|
32
|
+
used.add(key);
|
|
33
|
+
return { out: plain, plain };
|
|
34
|
+
}
|
|
35
|
+
const ext = path.extname(plain);
|
|
36
|
+
const stem = path.basename(plain, ext);
|
|
37
|
+
const out = uniquePath(path.dirname(plain), stem, ext, (candidate) => used.has(pathKey(candidate)));
|
|
38
|
+
used.add(pathKey(out));
|
|
39
|
+
return { out, plain };
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function resolveHud(config, tel, log) {
|
|
43
|
+
const hud = resolveHudLayout(config.hud, hasAltitude(tel.frames.map((f) => f.alt)));
|
|
44
|
+
if (config.hud.alt && !hud.alt) {
|
|
45
|
+
log('hud: altitude unavailable in this telemetry source (chip disabled)');
|
|
46
|
+
}
|
|
47
|
+
return hud;
|
|
48
|
+
}
|
|
49
|
+
export function frameChannelsOf(tel) {
|
|
50
|
+
const lat = [];
|
|
51
|
+
const lon = [];
|
|
52
|
+
tel.frames.forEach((frame, i) => {
|
|
53
|
+
if (frame.fix === null) {
|
|
54
|
+
throw new Error(`telemetry frame ${i} has no GPS position`);
|
|
55
|
+
}
|
|
56
|
+
lat.push(frame.fix.lat);
|
|
57
|
+
lon.push(frame.fix.lon);
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
lat,
|
|
61
|
+
lon,
|
|
62
|
+
alt: tel.frames.map((f) => f.alt),
|
|
63
|
+
speed: tel.frames.map((f) => f.speed),
|
|
64
|
+
headingDeg: tel.frames.map((f) => f.headingDeg),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function describeView(config, overview, tilesLabel) {
|
|
68
|
+
const zoomNote = config.zoom
|
|
69
|
+
? ' (fixed)'
|
|
70
|
+
: config.zoomOut
|
|
71
|
+
? ` (-${config.zoomOut})`
|
|
72
|
+
: '';
|
|
73
|
+
return (`view: ${config.view} at zoom ${overview.zoom}${zoomNote}, ` +
|
|
74
|
+
`${overview.tiles.length} tiles (${tilesLabel})`);
|
|
75
|
+
}
|
|
76
|
+
function mtimeOf(outPath) {
|
|
77
|
+
try {
|
|
78
|
+
return fs.statSync(outPath).mtimeMs;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function removePartialOutput(outPath, mtimeBefore, log) {
|
|
85
|
+
const mtimeNow = mtimeOf(outPath);
|
|
86
|
+
if (mtimeNow !== null && (mtimeBefore === null || mtimeNow !== mtimeBefore)) {
|
|
87
|
+
try {
|
|
88
|
+
// Retry brief Windows file-lock release delays after killing ffmpeg.
|
|
89
|
+
fs.rmSync(outPath, { force: true, maxRetries: 5, retryDelay: 50 });
|
|
90
|
+
log(`removed partial output: ${outPath}`);
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
log(`warning: could not remove partial output ${outPath}: ${errorMessage(e)}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async function renderWithOutputCleanup(outPath, log, render) {
|
|
98
|
+
const mtimeBefore = mtimeOf(outPath);
|
|
99
|
+
try {
|
|
100
|
+
await render();
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
removePartialOutput(outPath, mtimeBefore, log);
|
|
104
|
+
throw e;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const realDeps = {
|
|
108
|
+
probeVideo,
|
|
109
|
+
loadTelemetry,
|
|
110
|
+
renderVideo,
|
|
111
|
+
verifyOutput,
|
|
112
|
+
outputMatchesSource,
|
|
113
|
+
};
|
|
114
|
+
function resolveDeps(overrides, tileCache) {
|
|
115
|
+
return {
|
|
116
|
+
probeVideo: overrides?.probeVideo ?? realDeps.probeVideo,
|
|
117
|
+
loadTelemetry: overrides?.loadTelemetry ?? realDeps.loadTelemetry,
|
|
118
|
+
prefetchTiles: overrides?.prefetchTiles ??
|
|
119
|
+
((options) => prefetchTiles({ ...options, cacheDir: tileCache })),
|
|
120
|
+
renderVideo: overrides?.renderVideo ?? realDeps.renderVideo,
|
|
121
|
+
verifyOutput: overrides?.verifyOutput ?? realDeps.verifyOutput,
|
|
122
|
+
outputMatchesSource: overrides?.outputMatchesSource ?? realDeps.outputMatchesSource,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function createPrepareReporter(onProgress = () => { }) {
|
|
126
|
+
return (stage) => onProgress({
|
|
127
|
+
stage,
|
|
128
|
+
done: PREPARE_STAGE_ORDER.indexOf(stage),
|
|
129
|
+
total: PREPARE_STAGE_ORDER.length,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
async function probeStage(env) {
|
|
133
|
+
const { videoPath, config, log, deps, tools, report } = env;
|
|
134
|
+
report('probe');
|
|
135
|
+
const probe = await deps.probeVideo(tools, videoPath, log);
|
|
136
|
+
log(`source: ${path.basename(videoPath)} ${probe.width}x${probe.height} @ ${probe.fps.str} fps, ${probe.frames} frames`);
|
|
137
|
+
const introOutro = planIntroOutroFrames(config, {
|
|
138
|
+
fps: probe.fps.value,
|
|
139
|
+
frames: probe.frames,
|
|
140
|
+
});
|
|
141
|
+
if (introOutro.clamped) {
|
|
142
|
+
log(`intro/outro shortened to ${introOutro.introN}/${introOutro.outroN} frames for this clip`);
|
|
143
|
+
}
|
|
144
|
+
return { probe, introOutro };
|
|
145
|
+
}
|
|
146
|
+
async function telemetryStage(env, probe) {
|
|
147
|
+
const { videoPath, config, log, deps, tools, report } = env;
|
|
148
|
+
report('telemetry');
|
|
149
|
+
const loaded = await deps.loadTelemetry(videoPath, {
|
|
150
|
+
frames: probe.frames,
|
|
151
|
+
fpsValue: probe.fps.value,
|
|
152
|
+
durationSec: probe.durationSec,
|
|
153
|
+
camMeta: probe.camMeta,
|
|
154
|
+
tools,
|
|
155
|
+
});
|
|
156
|
+
const tel = loaded.telemetry;
|
|
157
|
+
const summary = telemetrySummary(tel);
|
|
158
|
+
log(`telemetry: ${summary.source} (${summary.method}), ${fixCountLabel(summary.fixCount)}, ` +
|
|
159
|
+
`heading=${summary.headingMode}, track ${trackDistanceLabel(summary.trackDistanceM)}` +
|
|
160
|
+
(summary.noLock ? `, ${noLockCountLabel(summary.noLock)}` : ''));
|
|
161
|
+
const hud = resolveHud(config, tel, log);
|
|
162
|
+
return {
|
|
163
|
+
tel,
|
|
164
|
+
frameValues: loaded.frameValues,
|
|
165
|
+
trackValues: loaded.trackValues,
|
|
166
|
+
protoFile: loaded.protoFile,
|
|
167
|
+
gimbalDevice: loaded.gimbalDevice,
|
|
168
|
+
hud,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
async function viewPlanStage(env, tel) {
|
|
172
|
+
const { config, log, report } = env;
|
|
173
|
+
report('plan');
|
|
174
|
+
const overview = planView(tel.bbox, config.width, config.height, config);
|
|
175
|
+
log(describeView(config, overview, config.style));
|
|
176
|
+
return overview;
|
|
177
|
+
}
|
|
178
|
+
async function tileWarmStage(deps, config, overview, log, signal) {
|
|
179
|
+
if (signal?.aborted)
|
|
180
|
+
throw new Error(ERR_RENDER_CANCELED);
|
|
181
|
+
let tileStats;
|
|
182
|
+
try {
|
|
183
|
+
tileStats = await deps.prefetchTiles({
|
|
184
|
+
style: config.style,
|
|
185
|
+
tiles: overview.tiles,
|
|
186
|
+
log,
|
|
187
|
+
signal,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
if (signal?.aborted)
|
|
192
|
+
throw new Error(ERR_RENDER_CANCELED, { cause: err });
|
|
193
|
+
throw err;
|
|
194
|
+
}
|
|
195
|
+
if (signal?.aborted)
|
|
196
|
+
throw new Error(ERR_RENDER_CANCELED);
|
|
197
|
+
if (tileStats.downloaded) {
|
|
198
|
+
log(`tiles: ${tileStats.downloaded} downloaded, ${tileStats.failed} placeholders`);
|
|
199
|
+
}
|
|
200
|
+
return tileStats;
|
|
201
|
+
}
|
|
202
|
+
async function prepareWithEnv(env) {
|
|
203
|
+
const { width, height } = env.config;
|
|
204
|
+
const { probe, introOutro } = await probeStage(env);
|
|
205
|
+
const { tel, frameValues, trackValues, protoFile, gimbalDevice, hud } = await telemetryStage(env, probe);
|
|
206
|
+
const overview = await viewPlanStage(env, tel);
|
|
207
|
+
const frames = frameChannelsOf(tel);
|
|
208
|
+
return {
|
|
209
|
+
width,
|
|
210
|
+
height,
|
|
211
|
+
probe,
|
|
212
|
+
tel,
|
|
213
|
+
frameValues,
|
|
214
|
+
trackValues,
|
|
215
|
+
protoFile,
|
|
216
|
+
gimbalDevice,
|
|
217
|
+
hud,
|
|
218
|
+
introOutro,
|
|
219
|
+
overview,
|
|
220
|
+
frames,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
export async function prepareSession(videoPath, config, log, options = {}) {
|
|
224
|
+
return prepareWithEnv({
|
|
225
|
+
videoPath,
|
|
226
|
+
config,
|
|
227
|
+
log,
|
|
228
|
+
deps: resolveDeps(options.deps, config.tileCache),
|
|
229
|
+
tools: options.tools ?? resolveFfmpegTools(config),
|
|
230
|
+
report: createPrepareReporter(options.onProgress),
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
export function recordingPageOpts(prep, config) {
|
|
234
|
+
return planPageOpts({
|
|
235
|
+
bbox: prep.tel.bbox,
|
|
236
|
+
width: prep.width,
|
|
237
|
+
height: prep.height,
|
|
238
|
+
config,
|
|
239
|
+
source: { fps: prep.probe.fps.value, frames: prep.probe.frames },
|
|
240
|
+
frames: prep.frames,
|
|
241
|
+
planned: {
|
|
242
|
+
overview: prep.overview,
|
|
243
|
+
introOutro: prep.introOutro,
|
|
244
|
+
hud: prep.hud,
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
function buildOkSummary(ctx, elapsedSec) {
|
|
249
|
+
const { config, probe, tel, hud, introOutro, overview, tileStats } = ctx;
|
|
250
|
+
const telemetry = telemetrySummary(tel);
|
|
251
|
+
return {
|
|
252
|
+
video: ctx.videoPath,
|
|
253
|
+
out: ctx.outPath,
|
|
254
|
+
status: 'ok',
|
|
255
|
+
width: ctx.width,
|
|
256
|
+
height: ctx.height,
|
|
257
|
+
style: config.style,
|
|
258
|
+
view: config.view,
|
|
259
|
+
introFrames: introOutro.introN,
|
|
260
|
+
outroFrames: introOutro.outroN,
|
|
261
|
+
hud,
|
|
262
|
+
// Field by field, not a spread: a TelemetrySummary rename must land here visibly, not silently drop a --json key.
|
|
263
|
+
source: telemetry.source,
|
|
264
|
+
method: telemetry.method,
|
|
265
|
+
headingMode: telemetry.headingMode,
|
|
266
|
+
fixes: telemetry.fixCount,
|
|
267
|
+
noLock: telemetry.noLock,
|
|
268
|
+
trackDistanceM: telemetry.trackDistanceM,
|
|
269
|
+
frames: ctx.outFrames,
|
|
270
|
+
fps: probe.fps.str,
|
|
271
|
+
frameRange: ctx.frameRange ?? undefined,
|
|
272
|
+
bbox: tel.bbox,
|
|
273
|
+
zoom: overview.zoom,
|
|
274
|
+
zoomFixed: config.zoom > 0,
|
|
275
|
+
zoomOut: effectiveZoomOut(config),
|
|
276
|
+
tilesDownloaded: tileStats.downloaded,
|
|
277
|
+
verified: true,
|
|
278
|
+
elapsedSec,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
async function verifyRenderedOutput(env) {
|
|
282
|
+
const { ctx, deps, tools } = env;
|
|
283
|
+
const verify = await deps.verifyOutput(tools, ctx.outPath, ctx.outFrames, ctx.probe.fps.value);
|
|
284
|
+
if (!verify.ok) {
|
|
285
|
+
throw new Error(`${ERR_OUTPUT_VERIFICATION}got ${verify.frames} frames @ ${verify.fps ?? 'unknown'}, ` +
|
|
286
|
+
`expected ${ctx.outFrames} @ ${ctx.probe.fps.str}`);
|
|
287
|
+
}
|
|
288
|
+
ctx.log(ctx.frameRange
|
|
289
|
+
? 'verified: frame count and frame rate are 1:1 within the exported range'
|
|
290
|
+
: 'verified: frame count and frame rate match the source');
|
|
291
|
+
}
|
|
292
|
+
async function renderToOutput(env) {
|
|
293
|
+
const { ctx, deps, tools, options } = env;
|
|
294
|
+
const html = buildPageHtml(recordingPageOpts(ctx, ctx.config));
|
|
295
|
+
fs.mkdirSync(path.dirname(ctx.outPath), { recursive: true });
|
|
296
|
+
await renderWithOutputCleanup(ctx.outPath, ctx.log, async () => {
|
|
297
|
+
await deps.renderVideo({
|
|
298
|
+
html,
|
|
299
|
+
capture: ctx.config.capture,
|
|
300
|
+
codec: ctx.config.codec,
|
|
301
|
+
quality: ctx.config.quality,
|
|
302
|
+
preset: ctx.config.preset,
|
|
303
|
+
style: ctx.config.style,
|
|
304
|
+
tileCache: ctx.config.tileCache,
|
|
305
|
+
tools,
|
|
306
|
+
width: ctx.width,
|
|
307
|
+
height: ctx.height,
|
|
308
|
+
frames: ctx.outFrames,
|
|
309
|
+
frameStart: ctx.frameRange?.start ?? 0,
|
|
310
|
+
fpsStr: ctx.probe.fps.str,
|
|
311
|
+
workers: ctx.config.workers,
|
|
312
|
+
outPath: ctx.outPath,
|
|
313
|
+
browserPath: ctx.config.browser,
|
|
314
|
+
signal: options.signal,
|
|
315
|
+
log: ctx.log,
|
|
316
|
+
onCapture: options.onCapture,
|
|
317
|
+
});
|
|
318
|
+
await verifyRenderedOutput(env);
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
export function telemetryExportInput(prep) {
|
|
322
|
+
return {
|
|
323
|
+
source: prep.tel.source,
|
|
324
|
+
headingMode: prep.tel.headingMode,
|
|
325
|
+
frameCount: prep.probe.frames,
|
|
326
|
+
protoFile: prep.protoFile,
|
|
327
|
+
gimbalDevice: prep.gimbalDevice,
|
|
328
|
+
frames: prep.frameValues,
|
|
329
|
+
headingDeg: prep.tel.frames.map((frame) => frame.headingDeg),
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
// The track formats read the fix-faithful records (which carry positions and
|
|
333
|
+
// source times for every telemetry source); the .json document keeps its own
|
|
334
|
+
// record stream.
|
|
335
|
+
export function trackExportStream(prep) {
|
|
336
|
+
return {
|
|
337
|
+
records: prep.trackValues,
|
|
338
|
+
fpsValue: prep.probe.fps.value,
|
|
339
|
+
frameCount: prep.probe.frames,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
function writeTrackExport(file, prep, log) {
|
|
343
|
+
// The export intentionally covers the whole recording: a frame range
|
|
344
|
+
// limits the render, never this export.
|
|
345
|
+
writeTrackFile(file, { document: telemetryExportInput(prep), track: trackExportStream(prep) }, null);
|
|
346
|
+
log(`track: wrote ${file}`);
|
|
347
|
+
}
|
|
348
|
+
export async function processRecording(videoPath, config, log, outPath = outputPathFor(videoPath, config), options = {}) {
|
|
349
|
+
const t0 = Date.now();
|
|
350
|
+
const deps = resolveDeps(options.deps, config.tileCache);
|
|
351
|
+
const tools = options.tools ?? resolveFfmpegTools(config);
|
|
352
|
+
if (options.signal?.aborted)
|
|
353
|
+
throw new Error(ERR_RENDER_CANCELED);
|
|
354
|
+
const prep = await prepareWithEnv({
|
|
355
|
+
videoPath,
|
|
356
|
+
config,
|
|
357
|
+
log,
|
|
358
|
+
deps,
|
|
359
|
+
tools,
|
|
360
|
+
report: createPrepareReporter(options.onProgress),
|
|
361
|
+
});
|
|
362
|
+
if (options.signal?.aborted)
|
|
363
|
+
throw new Error(ERR_RENDER_CANCELED);
|
|
364
|
+
if (config.trackOut) {
|
|
365
|
+
writeTrackExport(config.trackOut, prep, log);
|
|
366
|
+
}
|
|
367
|
+
const tileStats = await tileWarmStage(deps, config, prep.overview, log, options.signal);
|
|
368
|
+
const range = resolveFrameRange(options.range, prep.probe.frames);
|
|
369
|
+
const outFrames = range ? range.end - range.start + 1 : prep.probe.frames;
|
|
370
|
+
const ctx = {
|
|
371
|
+
...prep,
|
|
372
|
+
videoPath,
|
|
373
|
+
outPath,
|
|
374
|
+
config,
|
|
375
|
+
log,
|
|
376
|
+
outFrames,
|
|
377
|
+
frameRange: range,
|
|
378
|
+
tileStats,
|
|
379
|
+
};
|
|
380
|
+
await renderToOutput({ ctx, deps, tools, options });
|
|
381
|
+
return buildOkSummary(ctx, Math.round((Date.now() - t0) / 1000));
|
|
382
|
+
}
|
|
383
|
+
export async function runBatch(videos, config, log, emit, options = {}) {
|
|
384
|
+
const result = { ok: 0, skipped: 0, failed: 0 };
|
|
385
|
+
const deps = resolveDeps(options.deps, config.tileCache);
|
|
386
|
+
const tools = options.tools ?? resolveFfmpegTools(config);
|
|
387
|
+
if (config.trackOut && videos.length > 1) {
|
|
388
|
+
throw new Error('--track-out writes one file per run: give a single recording');
|
|
389
|
+
}
|
|
390
|
+
const plans = planOutputs(videos, config);
|
|
391
|
+
function collisionWarning(base, plan) {
|
|
392
|
+
if (plan.out !== plan.plain) {
|
|
393
|
+
log(`warning: output name collision for ${base} - writing ${path.basename(plan.out)} instead`);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
async function maybeSkip(video, plan) {
|
|
397
|
+
if (!(config.skipExisting && (await deps.outputMatchesSource(tools, video, plan.out)))) {
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
log(`SKIP ${plan.out} (exists and matches the source)`);
|
|
401
|
+
return 'skipped';
|
|
402
|
+
}
|
|
403
|
+
async function runOne(video, plan) {
|
|
404
|
+
return processRecording(video, config, log, plan.out, { ...options, deps, tools });
|
|
405
|
+
}
|
|
406
|
+
for (const [idx, video] of videos.entries()) {
|
|
407
|
+
const base = path.basename(video);
|
|
408
|
+
log(`=== ${base} ===`);
|
|
409
|
+
const plan = plans[idx];
|
|
410
|
+
collisionWarning(base, plan);
|
|
411
|
+
if ((await maybeSkip(video, plan)) !== null) {
|
|
412
|
+
emit({ video, out: plan.out, status: 'skipped', elapsedSec: 0 });
|
|
413
|
+
result.skipped++;
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
try {
|
|
417
|
+
const summary = await runOne(video, plan);
|
|
418
|
+
emit(summary);
|
|
419
|
+
log(`OK ${plan.out} (${summary.frames} frames @ ${summary.fps}, ${summary.elapsedSec} s)`);
|
|
420
|
+
result.ok++;
|
|
421
|
+
}
|
|
422
|
+
catch (e) {
|
|
423
|
+
const message = errorMessage(e);
|
|
424
|
+
log(`ERROR ${base}: ${message}`);
|
|
425
|
+
emit({
|
|
426
|
+
video,
|
|
427
|
+
out: plan.out,
|
|
428
|
+
status: 'error',
|
|
429
|
+
elapsedSec: 0,
|
|
430
|
+
error: message,
|
|
431
|
+
});
|
|
432
|
+
result.failed++;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return result;
|
|
436
|
+
}
|
package/dist/plan.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { MapStyle, RenderConfig } from './config.js';
|
|
2
|
+
import type { Bbox, MercatorPixel } from 'drone-path-core/geo';
|
|
3
|
+
export interface TileCoord {
|
|
4
|
+
z: number;
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
}
|
|
8
|
+
interface OverviewPlanOptions {
|
|
9
|
+
bbox: Bbox;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
maxZoom?: number;
|
|
13
|
+
zoomOut?: number;
|
|
14
|
+
follow?: boolean;
|
|
15
|
+
maxNativeZoom?: number | null;
|
|
16
|
+
zoomOverride?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface OverviewPlan {
|
|
19
|
+
centerPx: MercatorPixel;
|
|
20
|
+
zoom: number;
|
|
21
|
+
tiles: TileCoord[];
|
|
22
|
+
}
|
|
23
|
+
/** The zoom levels the planner renders: the floor and the map style's tile maximum. */
|
|
24
|
+
export declare function zoomLimits(style: MapStyle): {
|
|
25
|
+
min: number;
|
|
26
|
+
max: number;
|
|
27
|
+
};
|
|
28
|
+
export declare function computeOverview({ bbox, width, height, maxZoom, zoomOut, follow, maxNativeZoom, zoomOverride, }: OverviewPlanOptions): OverviewPlan;
|
|
29
|
+
export interface IntroOutroFrames {
|
|
30
|
+
introN: number;
|
|
31
|
+
outroN: number;
|
|
32
|
+
clamped: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare function planView(bbox: Bbox, width: number, height: number, config: Pick<RenderConfig, 'style' | 'view' | 'zoom' | 'zoomOut'>): OverviewPlan;
|
|
35
|
+
export declare function planIntroOutroFrames(config: Pick<RenderConfig, 'introSec' | 'outroSec'>, source: {
|
|
36
|
+
fps: number;
|
|
37
|
+
frames: number;
|
|
38
|
+
}): IntroOutroFrames;
|
|
39
|
+
export declare const PREPARE_STAGE_ORDER: readonly ["probe", "telemetry", "plan"];
|
|
40
|
+
export type PrepareStage = (typeof PREPARE_STAGE_ORDER)[number];
|
|
41
|
+
export interface PrepareProgress {
|
|
42
|
+
stage: PrepareStage;
|
|
43
|
+
done: number;
|
|
44
|
+
total: number;
|
|
45
|
+
}
|
|
46
|
+
export declare const INITIAL_PREPARE_PROGRESS: PrepareProgress;
|
|
47
|
+
export {};
|