drone-path-core 1.1.1 → 1.2.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.
- package/dist/exec-tool.d.ts +2 -1
- package/dist/exec-tool.js +4 -1
- package/dist/geo.d.ts +1 -0
- package/dist/geo.js +5 -1
- package/dist/keyframes.d.ts +3 -0
- package/dist/keyframes.js +9 -2
- package/dist/rounding.d.ts +1 -0
- package/dist/rounding.js +5 -0
- package/dist/sharpness.d.ts +62 -0
- package/dist/sharpness.js +303 -0
- package/dist/shot-segmentation.js +1 -5
- package/package.json +14 -3
package/dist/exec-tool.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { ExecFileOptions } from 'node:child_process';
|
|
1
|
+
import type { ChildProcess, ExecFileOptions, SpawnOptions } from 'node:child_process';
|
|
2
2
|
interface ToolOutput {
|
|
3
3
|
stdout: string;
|
|
4
4
|
stderr: string;
|
|
5
5
|
}
|
|
6
6
|
export declare function runTool(command: string, args: readonly string[], opts?: ExecFileOptions): Promise<ToolOutput>;
|
|
7
7
|
export declare function runToolBinary(command: string, args: readonly string[], opts?: ExecFileOptions): Promise<Buffer>;
|
|
8
|
+
export declare function spawnTool(command: string, args: readonly string[], opts?: SpawnOptions): ChildProcess;
|
|
8
9
|
export {};
|
package/dist/exec-tool.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execFile } from 'node:child_process';
|
|
1
|
+
import { execFile, spawn } from 'node:child_process';
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
3
|
const execFileAsync = promisify(execFile);
|
|
4
4
|
// One child-process seam for src/: command, argv and buffer budget pass
|
|
@@ -16,3 +16,6 @@ export async function runToolBinary(command, args, opts) {
|
|
|
16
16
|
const { stdout } = await execFileAsync(command, args, { windowsHide: true, ...opts, encoding: 'buffer' });
|
|
17
17
|
return stdout;
|
|
18
18
|
}
|
|
19
|
+
export function spawnTool(command, args, opts) {
|
|
20
|
+
return spawn(command, args, { windowsHide: true, ...opts });
|
|
21
|
+
}
|
package/dist/geo.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface MercatorPixel {
|
|
|
15
15
|
export declare const EARTH_RADIUS_M = 6371008.8;
|
|
16
16
|
export declare const DEG_TO_RAD: number;
|
|
17
17
|
export declare const RAD_TO_DEG: number;
|
|
18
|
+
export declare function clampMercatorLatitude(lat: number): number;
|
|
18
19
|
export declare function isGpsFix(lat: number, lon: number): boolean;
|
|
19
20
|
export declare function gpsFixOrNull(lat: number | null, lon: number | null): LatLon | null;
|
|
20
21
|
export declare function haversineM(a: LatLon, b: LatLon): number;
|
package/dist/geo.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export const EARTH_RADIUS_M = 6371008.8;
|
|
2
2
|
export const DEG_TO_RAD = Math.PI / 180;
|
|
3
3
|
export const RAD_TO_DEG = 180 / Math.PI;
|
|
4
|
+
const MAX_MERCATOR_LAT = 85.05112878;
|
|
5
|
+
export function clampMercatorLatitude(lat) {
|
|
6
|
+
return Math.max(-MAX_MERCATOR_LAT, Math.min(MAX_MERCATOR_LAT, lat));
|
|
7
|
+
}
|
|
4
8
|
// (0, 0) is DJI's "no GPS lock" placeholder before the first fix, not a real fix.
|
|
5
9
|
export function isGpsFix(lat, lon) {
|
|
6
10
|
return (Number.isFinite(lat) &&
|
|
@@ -47,7 +51,7 @@ export function circularMeanDeg(degList) {
|
|
|
47
51
|
export function project(lon, lat, zoom) {
|
|
48
52
|
const scale = 256 * 2 ** zoom;
|
|
49
53
|
const x = ((lon + 180) / 360) * scale;
|
|
50
|
-
const sinLat = Math.sin(
|
|
54
|
+
const sinLat = Math.sin(clampMercatorLatitude(lat) * DEG_TO_RAD);
|
|
51
55
|
const y = (0.5 - Math.log((1 + sinLat) / (1 - sinLat)) / (4 * Math.PI)) * scale;
|
|
52
56
|
return { x, y };
|
|
53
57
|
}
|
package/dist/keyframes.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FfmpegToolPaths } from './ffmpeg-tools.js';
|
|
2
|
+
import type { FrameSharpness } from './sharpness.js';
|
|
2
3
|
export type KeyframeRequest = {
|
|
3
4
|
kind: 'time';
|
|
4
5
|
tSec: number;
|
|
@@ -25,11 +26,13 @@ export interface ExtractedKeyframe {
|
|
|
25
26
|
width: number;
|
|
26
27
|
height: number;
|
|
27
28
|
telemetry: TelemetrySnapshot | null;
|
|
29
|
+
sharpness?: FrameSharpness;
|
|
28
30
|
}
|
|
29
31
|
export interface ExtractKeyframesOptions {
|
|
30
32
|
at: readonly KeyframeRequest[];
|
|
31
33
|
maxWidth?: number;
|
|
32
34
|
outDir?: string;
|
|
35
|
+
sharpness?: boolean;
|
|
33
36
|
tools: FfmpegToolPaths;
|
|
34
37
|
signal?: AbortSignal;
|
|
35
38
|
}
|
package/dist/keyframes.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { runTool } from './exec-tool.js';
|
|
4
4
|
import { probeVideo } from './ffmpeg.js';
|
|
5
5
|
import { timeAt } from './frametime.js';
|
|
6
|
+
import { analyzeFrameSharpness } from './sharpness.js';
|
|
6
7
|
import { loadTelemetrySamples } from './telemetry.js';
|
|
7
8
|
import { computeTelemetry } from './telemetry-math.js';
|
|
8
9
|
function parseFrameToken(raw, token) {
|
|
@@ -200,14 +201,20 @@ export async function extractKeyframes(videoPath, options) {
|
|
|
200
201
|
cause: e,
|
|
201
202
|
});
|
|
202
203
|
}
|
|
203
|
-
|
|
204
|
+
const entry = {
|
|
204
205
|
path: outPath,
|
|
205
206
|
tSec,
|
|
206
207
|
frame,
|
|
207
208
|
width,
|
|
208
209
|
height,
|
|
209
210
|
telemetry: snapshotAt(tSec, frame),
|
|
210
|
-
}
|
|
211
|
+
};
|
|
212
|
+
if (options.sharpness) {
|
|
213
|
+
entry.sharpness = await analyzeFrameSharpness(options.tools, videoPath, tSec, {
|
|
214
|
+
signal: options.signal,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
results.push(entry);
|
|
211
218
|
}
|
|
212
219
|
return results;
|
|
213
220
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function roundTo(value: number, decimals: number): number;
|
package/dist/rounding.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { FfmpegToolPaths } from './ffmpeg-tools.js';
|
|
2
|
+
export declare const SHARPNESS_ANALYZER_METHOD = "ffmpeg-blurdetect";
|
|
3
|
+
export declare const SHARPNESS_ANALYZER_VERSION = "1";
|
|
4
|
+
export declare const SHARPNESS_ANALYSIS_WIDTH = 640;
|
|
5
|
+
export declare const DEFAULT_MIN_EDGE_COVERAGE = 0.002;
|
|
6
|
+
export interface SharpnessAnalyzer {
|
|
7
|
+
method: string;
|
|
8
|
+
version: string;
|
|
9
|
+
}
|
|
10
|
+
export interface FrameSharpness {
|
|
11
|
+
sharpnessScore: number | null;
|
|
12
|
+
edgeCoverage: number;
|
|
13
|
+
analyzer: SharpnessAnalyzer;
|
|
14
|
+
}
|
|
15
|
+
export interface RawSharpnessFrame {
|
|
16
|
+
index: number;
|
|
17
|
+
ptsTime: number | null;
|
|
18
|
+
blurWidth: number | null;
|
|
19
|
+
edgeCoverage: number;
|
|
20
|
+
}
|
|
21
|
+
export interface SharpnessFilterGraphOptions {
|
|
22
|
+
analysisWidth?: number;
|
|
23
|
+
stride?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface AnalyzeFrameSharpnessOptions {
|
|
26
|
+
analysisWidth?: number;
|
|
27
|
+
minEdgeCoverage?: number;
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
}
|
|
30
|
+
export type SharpnessAnalysisMode = 'sampled' | 'every-frame';
|
|
31
|
+
export interface ClipSharpnessSample {
|
|
32
|
+
frameIndex: number;
|
|
33
|
+
tSec: number;
|
|
34
|
+
sharpnessScore: number | null;
|
|
35
|
+
edgeCoverage: number;
|
|
36
|
+
}
|
|
37
|
+
export interface ClipSharpnessResult {
|
|
38
|
+
analyzer: SharpnessAnalyzer;
|
|
39
|
+
mode: SharpnessAnalysisMode;
|
|
40
|
+
stride: number;
|
|
41
|
+
analysisWidth: number;
|
|
42
|
+
minEdgeCoverage: number;
|
|
43
|
+
samples: ClipSharpnessSample[];
|
|
44
|
+
}
|
|
45
|
+
export interface AnalyzeClipSharpnessOptions {
|
|
46
|
+
mode?: SharpnessAnalysisMode;
|
|
47
|
+
fps?: number;
|
|
48
|
+
analysisWidth?: number;
|
|
49
|
+
minEdgeCoverage?: number;
|
|
50
|
+
signal?: AbortSignal;
|
|
51
|
+
onSample?: (sample: ClipSharpnessSample) => void;
|
|
52
|
+
}
|
|
53
|
+
/** Build the FFmpeg filtergraph that measures edge blur width and coverage on decoded luminance. */
|
|
54
|
+
export declare function buildSharpnessFilterGraph(options?: SharpnessFilterGraphOptions): string;
|
|
55
|
+
/** Parse per-frame blur width and edge coverage metadata emitted by FFmpeg metadata=mode=print. */
|
|
56
|
+
export declare function parseBlurdetectMetadata(output: string): RawSharpnessFrame[];
|
|
57
|
+
/** Convert raw blur width and edge coverage into a monotonic higher-is-sharper score. */
|
|
58
|
+
export declare function scoreSharpnessSample(blurWidth: number | null, edgeCoverage: number, minEdgeCoverage?: number): FrameSharpness;
|
|
59
|
+
/** Analyze sharpness of a single decoded video frame at the given timestamp. */
|
|
60
|
+
export declare function analyzeFrameSharpness(tools: FfmpegToolPaths, videoPath: string, tSec: number, options?: AnalyzeFrameSharpnessOptions): Promise<FrameSharpness>;
|
|
61
|
+
/** Stream clip-wide sharpness samples from FFmpeg using sampled (1/sec) or every-frame mode. */
|
|
62
|
+
export declare function analyzeClipSharpness(tools: FfmpegToolPaths, videoPath: string, options?: AnalyzeClipSharpnessOptions): Promise<ClipSharpnessResult>;
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
2
|
+
import { runTool, spawnTool } from './exec-tool.js';
|
|
3
|
+
import { probeVideo } from './ffmpeg.js';
|
|
4
|
+
import { timeAt } from './frametime.js';
|
|
5
|
+
import { roundTo } from './rounding.js';
|
|
6
|
+
export const SHARPNESS_ANALYZER_METHOD = 'ffmpeg-blurdetect';
|
|
7
|
+
export const SHARPNESS_ANALYZER_VERSION = '1';
|
|
8
|
+
export const SHARPNESS_ANALYSIS_WIDTH = 640;
|
|
9
|
+
export const DEFAULT_MIN_EDGE_COVERAGE = 0.002;
|
|
10
|
+
function clamp(value, min, max) {
|
|
11
|
+
return Math.min(max, Math.max(min, value));
|
|
12
|
+
}
|
|
13
|
+
function parseFiniteOrNull(raw) {
|
|
14
|
+
const num = Number(raw.trim());
|
|
15
|
+
return Number.isFinite(num) ? num : null;
|
|
16
|
+
}
|
|
17
|
+
/** Build the FFmpeg filtergraph that measures edge blur width and coverage on decoded luminance. */
|
|
18
|
+
export function buildSharpnessFilterGraph(options) {
|
|
19
|
+
const analysisWidth = options?.analysisWidth ?? SHARPNESS_ANALYSIS_WIDTH;
|
|
20
|
+
if (!Number.isInteger(analysisWidth) || analysisWidth < 1) {
|
|
21
|
+
throw new Error('sharpness analysis width must be a positive integer');
|
|
22
|
+
}
|
|
23
|
+
const stride = options?.stride;
|
|
24
|
+
if (stride !== undefined && (!Number.isInteger(stride) || stride < 1)) {
|
|
25
|
+
throw new Error('sharpness stride must be a positive integer');
|
|
26
|
+
}
|
|
27
|
+
const stages = [];
|
|
28
|
+
if (stride !== undefined && stride > 1) {
|
|
29
|
+
stages.push(`select='not(mod(n,${stride}))'`);
|
|
30
|
+
}
|
|
31
|
+
// Normalize to fixed luminance width before blurdetect/edgedetect so scores
|
|
32
|
+
// are comparable across 1080p/4K sources and independent of JPEG encoding.
|
|
33
|
+
stages.push(`scale=${analysisWidth}:-2:flags=area`, 'format=gray', 'blurdetect=high=0.117647:low=0.0588235:radius=50:planes=1', 'edgedetect=low=0.0588235:high=0.117647:mode=wires', 'signalstats', 'metadata=mode=print:file=-');
|
|
34
|
+
return stages.join(',');
|
|
35
|
+
}
|
|
36
|
+
function createBlurdetectParser(onFrame) {
|
|
37
|
+
let current = null;
|
|
38
|
+
const pushLine = (rawLine) => {
|
|
39
|
+
const line = rawLine.trim();
|
|
40
|
+
if (line === '')
|
|
41
|
+
return;
|
|
42
|
+
const header = /^frame:(\d+)\s+pts:\S+\s+pts_time:(\S+)/u.exec(line);
|
|
43
|
+
if (header) {
|
|
44
|
+
if (current)
|
|
45
|
+
onFrame(current);
|
|
46
|
+
current = {
|
|
47
|
+
index: Number(header[1]),
|
|
48
|
+
ptsTime: parseFiniteOrNull(header[2]),
|
|
49
|
+
blurWidth: null,
|
|
50
|
+
edgeCoverage: 0,
|
|
51
|
+
};
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!current)
|
|
55
|
+
return;
|
|
56
|
+
if (line.startsWith('lavfi.blur=')) {
|
|
57
|
+
current.blurWidth = parseFiniteOrNull(line.slice('lavfi.blur='.length));
|
|
58
|
+
}
|
|
59
|
+
else if (line.startsWith('lavfi.signalstats.YAVG=')) {
|
|
60
|
+
const yavg = parseFiniteOrNull(line.slice('lavfi.signalstats.YAVG='.length));
|
|
61
|
+
if (yavg !== null) {
|
|
62
|
+
current.edgeCoverage = clamp(yavg / 255, 0, 1);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const flush = () => {
|
|
67
|
+
if (current) {
|
|
68
|
+
onFrame(current);
|
|
69
|
+
current = null;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
return { pushLine, flush };
|
|
73
|
+
}
|
|
74
|
+
/** Parse per-frame blur width and edge coverage metadata emitted by FFmpeg metadata=mode=print. */
|
|
75
|
+
export function parseBlurdetectMetadata(output) {
|
|
76
|
+
const frames = [];
|
|
77
|
+
const parser = createBlurdetectParser((frame) => frames.push(frame));
|
|
78
|
+
for (const rawLine of output.split(/\r?\n/u)) {
|
|
79
|
+
parser.pushLine(rawLine);
|
|
80
|
+
}
|
|
81
|
+
parser.flush();
|
|
82
|
+
return frames;
|
|
83
|
+
}
|
|
84
|
+
/** Convert raw blur width and edge coverage into a monotonic higher-is-sharper score. */
|
|
85
|
+
export function scoreSharpnessSample(blurWidth, edgeCoverage, minEdgeCoverage = DEFAULT_MIN_EDGE_COVERAGE) {
|
|
86
|
+
const normalizedCoverage = Number.isFinite(edgeCoverage) ? clamp(edgeCoverage, 0, 1) : 0;
|
|
87
|
+
const roundedCoverage = roundTo(normalizedCoverage, 6);
|
|
88
|
+
const analyzer = {
|
|
89
|
+
method: SHARPNESS_ANALYZER_METHOD,
|
|
90
|
+
version: SHARPNESS_ANALYZER_VERSION,
|
|
91
|
+
};
|
|
92
|
+
if (blurWidth === null ||
|
|
93
|
+
!Number.isFinite(blurWidth) ||
|
|
94
|
+
blurWidth <= 0 ||
|
|
95
|
+
normalizedCoverage < minEdgeCoverage) {
|
|
96
|
+
return {
|
|
97
|
+
sharpnessScore: null,
|
|
98
|
+
edgeCoverage: roundedCoverage,
|
|
99
|
+
analyzer,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
sharpnessScore: roundTo(100 / (1 + blurWidth / 4), 2),
|
|
104
|
+
edgeCoverage: roundedCoverage,
|
|
105
|
+
analyzer,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** Analyze sharpness of a single decoded video frame at the given timestamp. */
|
|
109
|
+
export async function analyzeFrameSharpness(tools, videoPath, tSec, options) {
|
|
110
|
+
if (!Number.isFinite(tSec) || tSec < 0) {
|
|
111
|
+
throw new Error(`invalid sharpness timestamp: ${tSec}`);
|
|
112
|
+
}
|
|
113
|
+
const filterGraph = buildSharpnessFilterGraph({ analysisWidth: options?.analysisWidth });
|
|
114
|
+
options?.signal?.throwIfAborted();
|
|
115
|
+
let stdout;
|
|
116
|
+
let stderr;
|
|
117
|
+
try {
|
|
118
|
+
({ stdout, stderr } = await runTool(tools.ffmpeg, [
|
|
119
|
+
'-v', 'error',
|
|
120
|
+
'-ss', tSec.toFixed(6),
|
|
121
|
+
'-i', videoPath,
|
|
122
|
+
'-frames:v', '1',
|
|
123
|
+
'-vf', filterGraph,
|
|
124
|
+
'-f', 'null',
|
|
125
|
+
'-',
|
|
126
|
+
], { signal: options?.signal }));
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
if (options?.signal?.aborted)
|
|
130
|
+
throw e;
|
|
131
|
+
throw new Error(`ffmpeg failed while analyzing frame sharpness at ${tSec.toFixed(3)}s`, {
|
|
132
|
+
cause: e,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const parsedStdout = parseBlurdetectMetadata(stdout);
|
|
136
|
+
const frames = parsedStdout.length > 0 ? parsedStdout : parseBlurdetectMetadata(stderr);
|
|
137
|
+
if (frames.length === 0) {
|
|
138
|
+
throw new Error(`ffmpeg blurdetect produced no frame metadata at ${tSec.toFixed(3)}s`);
|
|
139
|
+
}
|
|
140
|
+
return scoreSharpnessSample(frames[0].blurWidth, frames[0].edgeCoverage, options?.minEdgeCoverage);
|
|
141
|
+
}
|
|
142
|
+
/** Stream clip-wide sharpness samples from FFmpeg using sampled (1/sec) or every-frame mode. */
|
|
143
|
+
export async function analyzeClipSharpness(tools, videoPath, options) {
|
|
144
|
+
const mode = options?.mode ?? 'sampled';
|
|
145
|
+
if (mode !== 'sampled' && mode !== 'every-frame') {
|
|
146
|
+
throw new Error(`invalid sharpness analysis mode: ${String(mode)}`);
|
|
147
|
+
}
|
|
148
|
+
const analysisWidth = options?.analysisWidth ?? SHARPNESS_ANALYSIS_WIDTH;
|
|
149
|
+
const minEdgeCoverage = options?.minEdgeCoverage ?? DEFAULT_MIN_EDGE_COVERAGE;
|
|
150
|
+
if (!Number.isFinite(minEdgeCoverage) || minEdgeCoverage < 0 || minEdgeCoverage > 1) {
|
|
151
|
+
throw new Error(`invalid sharpness min-edge-coverage: ${minEdgeCoverage}`);
|
|
152
|
+
}
|
|
153
|
+
let fps = options?.fps;
|
|
154
|
+
if (fps !== undefined && (!Number.isFinite(fps) || fps <= 0)) {
|
|
155
|
+
throw new Error(`invalid clip fps: ${fps}`);
|
|
156
|
+
}
|
|
157
|
+
options?.signal?.throwIfAborted();
|
|
158
|
+
if (mode === 'sampled' && fps === undefined) {
|
|
159
|
+
const probe = await probeVideo(tools, videoPath, undefined, options?.signal);
|
|
160
|
+
fps = probe.fps.value;
|
|
161
|
+
options?.signal?.throwIfAborted();
|
|
162
|
+
}
|
|
163
|
+
const stride = mode === 'every-frame' ? 1 : Math.max(1, Math.round(fps));
|
|
164
|
+
const filterGraph = buildSharpnessFilterGraph({ analysisWidth, stride });
|
|
165
|
+
const samples = [];
|
|
166
|
+
const toSample = (raw) => {
|
|
167
|
+
const frameIndex = raw.index * stride;
|
|
168
|
+
const tSec = raw.ptsTime ?? (fps !== undefined && fps > 0 ? timeAt(frameIndex, fps) : 0);
|
|
169
|
+
const scored = scoreSharpnessSample(raw.blurWidth, raw.edgeCoverage, minEdgeCoverage);
|
|
170
|
+
return {
|
|
171
|
+
frameIndex,
|
|
172
|
+
tSec,
|
|
173
|
+
sharpnessScore: scored.sharpnessScore,
|
|
174
|
+
edgeCoverage: scored.edgeCoverage,
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
const emitFrame = (raw) => {
|
|
178
|
+
const sample = toSample(raw);
|
|
179
|
+
samples.push(sample);
|
|
180
|
+
options?.onSample?.(sample);
|
|
181
|
+
};
|
|
182
|
+
const stderrText = await new Promise((resolve, reject) => {
|
|
183
|
+
if (options?.signal?.aborted) {
|
|
184
|
+
reject(options.signal.reason ?? new Error('clip sharpness analysis canceled'));
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const child = spawnTool(tools.ffmpeg, [
|
|
188
|
+
'-v', 'error',
|
|
189
|
+
'-i', videoPath,
|
|
190
|
+
'-vf', filterGraph,
|
|
191
|
+
'-f', 'null',
|
|
192
|
+
'-',
|
|
193
|
+
], { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
|
|
194
|
+
const parser = createBlurdetectParser(emitFrame);
|
|
195
|
+
const stdoutDecoder = new StringDecoder('utf8');
|
|
196
|
+
const stderrDecoder = new StringDecoder('utf8');
|
|
197
|
+
let stdoutBuffer = '';
|
|
198
|
+
let stderrBuffer = '';
|
|
199
|
+
let settled = false;
|
|
200
|
+
let terminating = false;
|
|
201
|
+
let pendingError;
|
|
202
|
+
const cleanup = () => {
|
|
203
|
+
options?.signal?.removeEventListener('abort', onAbort);
|
|
204
|
+
};
|
|
205
|
+
const fail = (err) => {
|
|
206
|
+
if (settled)
|
|
207
|
+
return;
|
|
208
|
+
settled = true;
|
|
209
|
+
cleanup();
|
|
210
|
+
reject(err);
|
|
211
|
+
};
|
|
212
|
+
const stopChild = (reason) => {
|
|
213
|
+
if (settled || terminating)
|
|
214
|
+
return;
|
|
215
|
+
terminating = true;
|
|
216
|
+
pendingError = reason;
|
|
217
|
+
child.kill();
|
|
218
|
+
};
|
|
219
|
+
const onAbort = () => {
|
|
220
|
+
stopChild(options?.signal?.reason ?? new Error('clip sharpness analysis canceled'));
|
|
221
|
+
};
|
|
222
|
+
options?.signal?.addEventListener('abort', onAbort, { once: true });
|
|
223
|
+
child.stdout?.on('data', (chunk) => {
|
|
224
|
+
if (settled || terminating)
|
|
225
|
+
return;
|
|
226
|
+
stdoutBuffer += typeof chunk === 'string' ? chunk : stdoutDecoder.write(chunk);
|
|
227
|
+
try {
|
|
228
|
+
let newlineIdx = stdoutBuffer.indexOf('\n');
|
|
229
|
+
while (newlineIdx !== -1) {
|
|
230
|
+
const line = stdoutBuffer.slice(0, newlineIdx);
|
|
231
|
+
stdoutBuffer = stdoutBuffer.slice(newlineIdx + 1);
|
|
232
|
+
parser.pushLine(line);
|
|
233
|
+
newlineIdx = stdoutBuffer.indexOf('\n');
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
stopChild(err);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
child.stderr?.on('data', (chunk) => {
|
|
241
|
+
if (settled || terminating)
|
|
242
|
+
return;
|
|
243
|
+
stderrBuffer += typeof chunk === 'string' ? chunk : stderrDecoder.write(chunk);
|
|
244
|
+
});
|
|
245
|
+
child.once('error', (err) => {
|
|
246
|
+
if (terminating) {
|
|
247
|
+
fail(pendingError);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
fail(new Error('ffmpeg failed while analyzing clip sharpness', { cause: err }));
|
|
251
|
+
});
|
|
252
|
+
child.once('close', (code) => {
|
|
253
|
+
if (settled)
|
|
254
|
+
return;
|
|
255
|
+
if (terminating) {
|
|
256
|
+
fail(pendingError);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
stdoutBuffer += stdoutDecoder.end();
|
|
260
|
+
stderrBuffer += stderrDecoder.end();
|
|
261
|
+
try {
|
|
262
|
+
if (stdoutBuffer.length > 0) {
|
|
263
|
+
for (const line of stdoutBuffer.split(/\r?\n/u)) {
|
|
264
|
+
parser.pushLine(line);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
parser.flush();
|
|
268
|
+
}
|
|
269
|
+
catch (err) {
|
|
270
|
+
fail(err);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (code !== 0) {
|
|
274
|
+
const detail = stderrBuffer.trim();
|
|
275
|
+
const suffix = detail ? `: ${detail}` : '';
|
|
276
|
+
fail(new Error(`ffmpeg failed while analyzing clip sharpness (exit code ${code ?? 'null'})${suffix}`));
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
settled = true;
|
|
280
|
+
cleanup();
|
|
281
|
+
resolve(stderrBuffer);
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
if (samples.length === 0) {
|
|
285
|
+
for (const raw of parseBlurdetectMetadata(stderrText)) {
|
|
286
|
+
emitFrame(raw);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (samples.length === 0) {
|
|
290
|
+
throw new Error('ffmpeg blurdetect produced no frame metadata');
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
analyzer: {
|
|
294
|
+
method: SHARPNESS_ANALYZER_METHOD,
|
|
295
|
+
version: SHARPNESS_ANALYZER_VERSION,
|
|
296
|
+
},
|
|
297
|
+
mode,
|
|
298
|
+
stride,
|
|
299
|
+
analysisWidth,
|
|
300
|
+
minEdgeCoverage,
|
|
301
|
+
samples,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { bearingDeg, gpsFixOrNull, haversineM } from './geo.js';
|
|
2
|
+
import { roundTo } from './rounding.js';
|
|
2
3
|
export const SHOT_TYPES = [
|
|
3
4
|
'takeoff',
|
|
4
5
|
'landing',
|
|
@@ -16,11 +17,6 @@ const EXPOSURE_REL_THRESHOLD = 0.25;
|
|
|
16
17
|
const EXPOSURE_CCT_THRESHOLD_K = 200;
|
|
17
18
|
const SHORT_CLIP_MAX_S = 4;
|
|
18
19
|
const BLIP_MAX_DURATION_S = 2;
|
|
19
|
-
function roundTo(value, decimals) {
|
|
20
|
-
const factor = 10 ** decimals;
|
|
21
|
-
const rounded = Math.round(value * factor) / factor;
|
|
22
|
-
return rounded === 0 ? 0 : rounded;
|
|
23
|
-
}
|
|
24
20
|
function shortestAngleDiffDeg(fromDeg, toDeg) {
|
|
25
21
|
return ((((toDeg - fromDeg + 540) % 360) + 360) % 360) - 180;
|
|
26
22
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drone-path-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Extract drone telemetry from DJI CAM-meta video streams and SRT sidecars.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -18,11 +18,22 @@
|
|
|
18
18
|
"node": ">=24"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "
|
|
22
|
-
"prepack": "
|
|
21
|
+
"build": "tsc -b",
|
|
22
|
+
"prepack": "node ../../scripts/clean-package-dist.mjs && tsc -b"
|
|
23
23
|
},
|
|
24
24
|
"author": "Manuel Warum",
|
|
25
25
|
"license": "MIT",
|
|
26
|
+
"homepage": "https://www.dronepath.dev",
|
|
27
|
+
"keywords": [
|
|
28
|
+
"dji",
|
|
29
|
+
"drone",
|
|
30
|
+
"telemetry",
|
|
31
|
+
"gpx",
|
|
32
|
+
"srt",
|
|
33
|
+
"kml",
|
|
34
|
+
"mcp",
|
|
35
|
+
"davinci-resolve"
|
|
36
|
+
],
|
|
26
37
|
"repository": {
|
|
27
38
|
"type": "git",
|
|
28
39
|
"url": "git+https://github.com/MrManny/drone-path.git",
|