@lumy-pack/scene-sieve 0.0.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.
@@ -0,0 +1,20 @@
1
+ export declare const APP_NAME = "scene-sieve";
2
+ export declare const DEFAULT_COUNT = 5;
3
+ export declare const DEFAULT_FPS = 5;
4
+ export declare const DEFAULT_SCALE = 720;
5
+ export declare const DEFAULT_QUALITY = 80;
6
+ export declare const WORKSPACE_PREFIX = "scene-sieve-";
7
+ export declare const TEMP_BASE_DIR: string;
8
+ export declare const SUPPORTED_VIDEO_EXTENSIONS: string[];
9
+ export declare const SUPPORTED_GIF_EXTENSIONS: string[];
10
+ export declare const FRAME_OUTPUT_EXTENSION = ".jpg";
11
+ export declare const FRAME_FILENAME_PATTERN = "frame_%06d.jpg";
12
+ export declare const OPENCV_BATCH_SIZE = 10;
13
+ export declare const MIN_IFRAME_COUNT = 3;
14
+ export declare const DBSCAN_ALPHA = 0.03;
15
+ export declare const DBSCAN_MIN_PTS = 4;
16
+ export declare const IOU_THRESHOLD = 0.9;
17
+ export declare const DECAY_LAMBDA = 0.95;
18
+ export declare const ANIMATION_FRAME_THRESHOLD = 5;
19
+ export declare const MATCH_DISTANCE_THRESHOLD = 0.75;
20
+ export declare function getTempWorkspaceDir(sessionId: string): string;
@@ -0,0 +1,29 @@
1
+ import type { BoundingBox, ProcessContext, ScoreEdge } from '../types/index.js';
2
+ import type { Point2D } from './dbscan.js';
3
+ export declare function preprocessFrame(framePath: string, scale: number): Promise<{
4
+ data: Uint8Array;
5
+ width: number;
6
+ height: number;
7
+ }>;
8
+ export declare function computeIoU(a: BoundingBox, b: BoundingBox): number;
9
+ export declare class IoUTracker {
10
+ private regions;
11
+ update(boxes: BoundingBox[], pairIndex: number): Set<number>;
12
+ getAnimationWeight(boxIndex: number, boxes: BoundingBox[]): number;
13
+ }
14
+ export interface AKAZEResult {
15
+ sNew: Point2D[];
16
+ sLoss: Point2D[];
17
+ }
18
+ export declare function computeInformationGain(clusters: BoundingBox[], clusterPoints: number[], imageArea: number, animationIndices: Set<number>, animationWeights: number[]): number;
19
+ /**
20
+ * Analyze adjacent frame pairs to compute information gain scores (G(t)).
21
+ * Processes frames in batches for memory efficiency.
22
+ *
23
+ * Pipeline:
24
+ * 1. AKAZE Feature Set Difference
25
+ * 2. DBSCAN Spatial Clustering
26
+ * 3. Spatio-temporal IoU Tracking
27
+ * 4. G(t) Information Gain Scoring
28
+ */
29
+ export declare function analyzeFrames(ctx: ProcessContext): Promise<ScoreEdge[]>;
@@ -0,0 +1,10 @@
1
+ import type { DBSCANResult } from '../types/index.js';
2
+ export interface Point2D {
3
+ x: number;
4
+ y: number;
5
+ }
6
+ /**
7
+ * DBSCAN clustering with resolution-independent eps.
8
+ * eps = alpha * sqrt(width^2 + height^2)
9
+ */
10
+ export declare function dbscan(points: Point2D[], imageWidth: number, imageHeight: number, alpha?: number, minPts?: number): DBSCANResult;
@@ -0,0 +1,7 @@
1
+ import type { FrameNode, ProcessContext } from '../types/index.js';
2
+ /**
3
+ * Extract frames from video/GIF using FFmpeg.
4
+ * Attempts I-Frame extraction first; falls back to fixed FPS if insufficient.
5
+ * GIF inputs always use FPS fallback.
6
+ */
7
+ export declare function extractFrames(ctx: ProcessContext): Promise<FrameNode[]>;
@@ -0,0 +1,8 @@
1
+ export { runPipeline } from './orchestrator.js';
2
+ export { analyzeFrames, computeIoU, computeInformationGain } from './analyzer.js';
3
+ export { extractFrames } from './extractor.js';
4
+ export { pruneTo, pruneByThreshold, pruneByThresholdWithCap } from './pruner.js';
5
+ export { dbscan } from './dbscan.js';
6
+ export type { Point2D } from './dbscan.js';
7
+ export { resolveInput, resolveOptions } from './input-resolver.js';
8
+ export { createWorkspace, cleanupWorkspace, finalizeOutput, readFramesAsBuffers, writeInputBuffer, writeInputFrames, } from './workspace.js';
@@ -0,0 +1,13 @@
1
+ import type { FrameNode, SieveOptions, ResolvedOptions } from '../types/index.js';
2
+ export declare function resolveOptions(options: SieveOptions): ResolvedOptions;
3
+ /**
4
+ * Resolve the input source to a list of FrameNode[].
5
+ *
6
+ * - 'file' mode: validate file exists and delegate to extractor (caller's responsibility)
7
+ * - 'buffer' mode: write buffer as temp video file, return path via FrameNode trick (empty list)
8
+ * - 'frames' mode: write frame buffers as JPGs, return FrameNode[]
9
+ */
10
+ export declare function resolveInput(options: SieveOptions, workspacePath: string): Promise<{
11
+ frames: FrameNode[];
12
+ resolvedInputPath?: string;
13
+ }>;
@@ -0,0 +1,2 @@
1
+ import type { SieveOptions, SieveResult } from '../types/index.js';
2
+ export declare function runPipeline(options: SieveOptions): Promise<SieveResult>;
@@ -0,0 +1,42 @@
1
+ import type { FrameNode, ScoreEdge } from '../types/index.js';
2
+ /**
3
+ * Edge-aware greedy merge with re-linking — O(N log N).
4
+ *
5
+ * 1. Build a doubly-linked list of frames
6
+ * 2. Insert all edges into a min-heap
7
+ * 3. Pop the lowest-score edge (most similar pair)
8
+ * 4. Remove the later frame (tgtId), re-link neighbors
9
+ * 5. Push synthetic edge with score = max(left, right)
10
+ * 6. Repeat until surviving count === targetCount
11
+ * 7. First and last frames are never removed (boundary preservation)
12
+ *
13
+ * Stale heap entries (involving removed frames) are lazily skipped on pop.
14
+ */
15
+ export declare function pruneTo(graph: ScoreEdge[], frames: FrameNode[], targetCount: number): Set<number>;
16
+ /**
17
+ * Threshold-based pruning — O(N).
18
+ *
19
+ * Scores are normalized to [0, 1] via max-normalization.
20
+ * threshold=0.5 means "keep frames where the change is at least 50%
21
+ * of the maximum change observed in this sequence".
22
+ *
23
+ * First and last frames are always preserved (boundary protection).
24
+ *
25
+ * Unlike pruneTo (which targets an exact count via greedy merge),
26
+ * this function has no count limit — every significant scene transition
27
+ * above the threshold is preserved.
28
+ */
29
+ export declare function pruneByThreshold(graph: ScoreEdge[], frames: FrameNode[], threshold: number): Set<number>;
30
+ /**
31
+ * Combined threshold + count pruning -- 2-stage pipeline.
32
+ *
33
+ * Stage 1: pruneByThreshold -- keep all frames with normalized score >= threshold
34
+ * Stage 2: if result exceeds maxCount, rebuild subgraph with synthetic edges
35
+ * (min-score over each gap) and apply pruneTo on the surviving subset
36
+ *
37
+ * Edge reconstruction: for consecutive survivors A, B with removed frames
38
+ * [x1, x2, ...] between them, the synthetic edge score is:
39
+ * min(score(A->x1), score(x1->x2), ..., score(xN->B))
40
+ * This preserves the "weakest link" semantics.
41
+ */
42
+ export declare function pruneByThresholdWithCap(graph: ScoreEdge[], frames: FrameNode[], threshold: number, maxCount: number): Set<number>;
@@ -0,0 +1,19 @@
1
+ import type { FrameNode, ProcessContext } from '../types/index.js';
2
+ export declare function createWorkspace(sessionId: string): Promise<string>;
3
+ export declare function finalizeOutput(ctx: ProcessContext, selectedFrames: FrameNode[]): Promise<string[]>;
4
+ export declare function cleanupWorkspace(workspacePath: string): Promise<void>;
5
+ /**
6
+ * Write a video buffer to a temp file in the workspace and return the path.
7
+ * Used by 'buffer' input mode.
8
+ */
9
+ export declare function writeInputBuffer(buffer: Buffer, workspacePath: string): Promise<string>;
10
+ /**
11
+ * Write an array of frame Buffers as JPG files and return FrameNode[].
12
+ * Used by 'frames' input mode.
13
+ */
14
+ export declare function writeInputFrames(frames: Buffer[], workspacePath: string): Promise<FrameNode[]>;
15
+ /**
16
+ * Read selected FrameNode files as Buffers with JPEG compression.
17
+ * Used to return output buffers in 'buffer' and 'frames' modes.
18
+ */
19
+ export declare function readFramesAsBuffers(frameNodes: FrameNode[], quality: number): Promise<Buffer[]>;