kasaframe 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/NOTICE +146 -0
- package/README.md +77 -2
- package/app/package.json +12 -0
- package/app/server/engine.ts +415 -0
- package/app/server/main.ts +205 -0
- package/app/web/env.d.ts +2 -0
- package/app/web/icons.ts +31 -0
- package/app/web/index.html +21 -0
- package/app/web/main.ts +1013 -0
- package/app/web/style.css +430 -0
- package/bin/hooks.mjs +51 -0
- package/bin/kf.mjs +14 -0
- package/docs/AGENTS.md +238 -0
- package/music/README.md +13 -0
- package/package.json +44 -4
- package/packages/adapters/package.json +36 -0
- package/packages/adapters/src/css.ts +11 -0
- package/packages/adapters/src/gsap.ts +26 -0
- package/packages/adapters/src/index.ts +9 -0
- package/packages/adapters/src/lottie.ts +22 -0
- package/packages/adapters/src/media.ts +59 -0
- package/packages/adapters/src/page.ts +229 -0
- package/packages/adapters/src/project.ts +214 -0
- package/packages/adapters/src/react.ts +36 -0
- package/packages/adapters/src/svelte.ts +22 -0
- package/packages/adapters/src/three.ts +18 -0
- package/packages/adapters/src/vue.ts +27 -0
- package/packages/check/package.json +19 -0
- package/packages/check/src/check.ts +273 -0
- package/packages/check/src/cli.ts +70 -0
- package/packages/check/src/image.ts +146 -0
- package/packages/check/src/index.ts +9 -0
- package/packages/check/src/ocr.swift +37 -0
- package/packages/check/src/probe.ts +328 -0
- package/packages/check/src/report.ts +44 -0
- package/packages/check/src/rules/assets.ts +42 -0
- package/packages/check/src/rules/beats.ts +212 -0
- package/packages/check/src/rules/camera.ts +217 -0
- package/packages/check/src/rules/captions.ts +49 -0
- package/packages/check/src/rules/flash.ts +235 -0
- package/packages/check/src/rules/frames.ts +135 -0
- package/packages/check/src/rules/layout.ts +257 -0
- package/packages/check/src/rules/page.ts +87 -0
- package/packages/check/src/rules/runs.ts +20 -0
- package/packages/check/src/rules/text.ts +326 -0
- package/packages/check/src/scan.ts +240 -0
- package/packages/check/src/serve.ts +67 -0
- package/packages/check/src/types.ts +80 -0
- package/packages/check/src/video.ts +137 -0
- package/packages/cli/package.json +29 -0
- package/packages/cli/src/blur.ts +68 -0
- package/packages/cli/src/browser.ts +203 -0
- package/packages/cli/src/command.ts +44 -0
- package/packages/cli/src/commands/app.ts +25 -0
- package/packages/cli/src/commands/beats.ts +36 -0
- package/packages/cli/src/commands/blender.ts +270 -0
- package/packages/cli/src/commands/check.ts +25 -0
- package/packages/cli/src/commands/doctor.ts +22 -0
- package/packages/cli/src/commands/gen.ts +173 -0
- package/packages/cli/src/commands/look.ts +39 -0
- package/packages/cli/src/commands/lyrics.ts +111 -0
- package/packages/cli/src/commands/make.ts +542 -0
- package/packages/cli/src/commands/new.ts +176 -0
- package/packages/cli/src/commands/preview.ts +43 -0
- package/packages/cli/src/commands/render.ts +216 -0
- package/packages/cli/src/commands/setup.ts +63 -0
- package/packages/cli/src/commands/sheet.ts +114 -0
- package/packages/cli/src/commands/skill.ts +43 -0
- package/packages/cli/src/commands/still.ts +40 -0
- package/packages/cli/src/commands/theme.ts +85 -0
- package/packages/cli/src/commands/transitions.ts +40 -0
- package/packages/cli/src/deps.ts +122 -0
- package/packages/cli/src/ffmpeg.ts +81 -0
- package/packages/cli/src/index.ts +8 -0
- package/packages/cli/src/kf.ts +53 -0
- package/packages/cli/src/lock.ts +72 -0
- package/packages/cli/src/out.ts +13 -0
- package/packages/cli/src/serve.ts +124 -0
- package/packages/clock/package.json +14 -0
- package/packages/clock/src/index.ts +25 -0
- package/packages/clock/src/install.ts +351 -0
- package/packages/clock/src/types.ts +45 -0
- package/packages/core/package.json +9 -0
- package/packages/core/src/beats.ts +283 -0
- package/packages/core/src/ease.ts +87 -0
- package/packages/core/src/frame.ts +99 -0
- package/packages/core/src/index.ts +27 -0
- package/packages/core/src/project.ts +146 -0
- package/packages/core/src/rand.ts +56 -0
- package/packages/core/src/spring.ts +52 -0
- package/packages/core/src/style.ts +100 -0
- package/packages/core/src/time.ts +88 -0
- package/packages/gen/PROVIDERS.md +55 -0
- package/packages/gen/package.json +9 -0
- package/packages/gen/src/generate.ts +204 -0
- package/packages/gen/src/image/og.ts +133 -0
- package/packages/gen/src/index.ts +18 -0
- package/packages/gen/src/keys.ts +60 -0
- package/packages/gen/src/media.ts +150 -0
- package/packages/gen/src/plan.ts +106 -0
- package/packages/gen/src/registry.ts +51 -0
- package/packages/gen/src/seam.ts +103 -0
- package/packages/gen/src/types.ts +86 -0
- package/packages/gen/src/video/fal.ts +140 -0
- package/packages/gen/src/video/h3.ts +107 -0
- package/packages/gen/src/video/http.ts +44 -0
- package/packages/gen/src/video/ltx.ts +60 -0
- package/packages/gen/src/video/minimax.ts +55 -0
- package/packages/gen/src/video/veo.ts +71 -0
- package/packages/jizura/package.json +16 -0
- package/packages/jizura/src/deny.ts +73 -0
- package/packages/jizura/src/index.ts +7 -0
- package/packages/jizura/src/install.ts +226 -0
- package/packages/jizura/src/layer.ts +282 -0
- package/packages/jizura/src/lyrics.ts +81 -0
- package/packages/jizura/src/pin.ts +5 -0
- package/packages/jizura/src/vite.ts +36 -0
- package/packages/motion/README.md +142 -0
- package/packages/motion/package.json +29 -0
- package/packages/motion/src/camera.ts +97 -0
- package/packages/motion/src/captions.ts +479 -0
- package/packages/motion/src/enter.ts +128 -0
- package/packages/motion/src/hangul.ts +129 -0
- package/packages/motion/src/impact.ts +100 -0
- package/packages/motion/src/index.ts +17 -0
- package/packages/motion/src/moves/brushWipe.ts +90 -0
- package/packages/motion/src/moves/cloneArray.ts +111 -0
- package/packages/motion/src/moves/curtains.ts +81 -0
- package/packages/motion/src/moves/echoStack.ts +70 -0
- package/packages/motion/src/moves/fit.ts +34 -0
- package/packages/motion/src/moves/flood.ts +61 -0
- package/packages/motion/src/moves/ghostStack.ts +79 -0
- package/packages/motion/src/moves/gridFloor.ts +100 -0
- package/packages/motion/src/moves/imageSwarm.ts +109 -0
- package/packages/motion/src/moves/index.ts +19 -0
- package/packages/motion/src/moves/irisBlades.ts +113 -0
- package/packages/motion/src/moves/karaokeLine.ts +94 -0
- package/packages/motion/src/moves/ledBoard.ts +94 -0
- package/packages/motion/src/moves/liquidTab.ts +72 -0
- package/packages/motion/src/moves/markerWrite.ts +63 -0
- package/packages/motion/src/moves/morphBox.ts +96 -0
- package/packages/motion/src/moves/neonSign.ts +77 -0
- package/packages/motion/src/moves/panelPop.ts +78 -0
- package/packages/motion/src/moves/paperTear.ts +75 -0
- package/packages/motion/src/moves/path.ts +64 -0
- package/packages/motion/src/moves/pathText.ts +107 -0
- package/packages/motion/src/moves/pointSphere.ts +109 -0
- package/packages/motion/src/moves/ransomLetters.ts +73 -0
- package/packages/motion/src/moves/shapeMorph.ts +143 -0
- package/packages/motion/src/moves/slamWords.ts +89 -0
- package/packages/motion/src/moves/sparkTrail.ts +114 -0
- package/packages/motion/src/moves/speedLines.ts +91 -0
- package/packages/motion/src/moves/splitFlap.ts +147 -0
- package/packages/motion/src/moves/stepWords.ts +117 -0
- package/packages/motion/src/moves/strikeOut.ts +98 -0
- package/packages/motion/src/moves/sunburst.ts +58 -0
- package/packages/motion/src/moves/tickerRows.ts +87 -0
- package/packages/motion/src/moves/tokenPicker.ts +114 -0
- package/packages/motion/src/moves/truchet.ts +85 -0
- package/packages/motion/src/moves/wordWall.ts +76 -0
- package/packages/motion/src/moves/worldRoll.ts +31 -0
- package/packages/motion/src/particles.ts +102 -0
- package/packages/motion/src/react/index.tsx +21 -0
- package/packages/motion/src/react/parts.tsx +431 -0
- package/packages/motion/src/react/time.tsx +97 -0
- package/packages/motion/src/text.ts +103 -0
- package/packages/motion/src/transition.ts +82 -0
- package/packages/motion/src/transition3d/cards.ts +65 -0
- package/packages/motion/src/transition3d/chain.ts +84 -0
- package/packages/motion/src/transition3d/dive.ts +181 -0
- package/packages/motion/src/transition3d/fold.ts +110 -0
- package/packages/motion/src/transition3d/gl.ts +219 -0
- package/packages/motion/src/transition3d/index.ts +228 -0
- package/packages/motion/src/transition3d/live.ts +70 -0
- package/packages/motion/src/transition3d/portal.ts +115 -0
- package/packages/motion/src/transition3d/react.tsx +29 -0
- package/packages/motion/src/transition3d/rig.ts +502 -0
- package/packages/motion/src/transition3d/shatter.ts +101 -0
- package/packages/motion/src/transition3d/whip.ts +65 -0
- package/packages/motion/src/transition3d/world.ts +683 -0
- package/packages/motion/src/transition3d/zoomOut.ts +114 -0
- package/packages/motion/src/transitions2d/catalog.ts +127 -0
- package/packages/motion/src/transitions2d/css.d.ts +2 -0
- package/packages/motion/src/transitions2d/cult-ui/LICENSE.md +9 -0
- package/packages/motion/src/transitions2d/cult-ui/RollingNumber.tsx +43 -0
- package/packages/motion/src/transitions2d/gl-transitions/LICENSE +25 -0
- package/packages/motion/src/transitions2d/gl-transitions/shaders.ts +1931 -0
- package/packages/motion/src/transitions2d/index.ts +2 -0
- package/packages/motion/src/transitions2d/kokonutui/LICENSE +21 -0
- package/packages/motion/src/transitions2d/kokonutui/MatrixText.css +16 -0
- package/packages/motion/src/transitions2d/kokonutui/MatrixText.tsx +94 -0
- package/packages/motion/src/transitions2d/magicui/HyperText.css +15 -0
- package/packages/motion/src/transitions2d/magicui/HyperText.tsx +115 -0
- package/packages/motion/src/transitions2d/magicui/LICENSE.md +21 -0
- package/packages/motion/src/transitions2d/magicui/MorphingText.css +25 -0
- package/packages/motion/src/transitions2d/magicui/MorphingText.tsx +130 -0
- package/packages/motion/src/transitions2d/magicui/WordRotate.tsx +42 -0
- package/packages/motion/src/transitions2d/react.ts +13 -0
- package/packages/motion/src/transitions2d/skiper-ui/ClipDiv.css +39 -0
- package/packages/motion/src/transitions2d/skiper-ui/ClipDiv.tsx +32 -0
- package/packages/motion/src/transitions2d/smoothui/LICENSE +21 -0
- package/packages/motion/src/transitions2d/smoothui/SharedAxisY.tsx +50 -0
- package/packages/motion/src/transitions2d/smoothui/TextMorph.tsx +90 -0
- package/packages/motion/src/transitions2d/smoothui/shaders.ts +223 -0
- package/packages/motion/src/transitions2d/unlumen/LICENSE +21 -0
- package/packages/motion/src/transitions2d/unlumen/ScrambleText.tsx +114 -0
- package/packages/motion/src/transitions2d/vengeance-ui/LICENSE +21 -0
- package/packages/motion/src/transitions2d/vengeance-ui/MorphText.css +69 -0
- package/packages/motion/src/transitions2d/vengeance-ui/MorphText.tsx +45 -0
- package/packages/motion/src/type.ts +131 -0
- package/packages/motion/src/ui.ts +172 -0
- package/packages/plan/package.json +15 -0
- package/packages/plan/src/brief.ts +254 -0
- package/packages/plan/src/captions.ts +75 -0
- package/packages/plan/src/detect.ts +93 -0
- package/packages/plan/src/index.ts +23 -0
- package/packages/plan/src/layout.ts +176 -0
- package/packages/plan/src/llm.ts +110 -0
- package/packages/plan/src/look.ts +220 -0
- package/packages/plan/src/plan.ts +125 -0
- package/packages/plan/src/request.ts +55 -0
- package/packages/plan/src/studio.ts +53 -0
- package/packages/plan/src/templates.ts +42 -0
- package/packages/plan/src/themes.ts +48 -0
- package/packages/plan/src/types.ts +106 -0
- package/packages/studio/package.json +12 -0
- package/packages/studio/src/index.ts +1 -0
- package/packages/studio/src/plugin.ts +236 -0
- package/packages/studio/src/ui/main.ts +503 -0
- package/packages/studio/src/ui/studio.css +165 -0
- package/packages/studio/src/ui/timeline.ts +317 -0
- package/packages/themes/kit/THEME-MAKE.md +68 -0
- package/packages/themes/kit/THEME.md +30 -0
- package/packages/themes/kit/briefs/og-intro-15s/brief.json +16 -0
- package/packages/themes/kit/briefs/og-intro-15s/facts.ts +29 -0
- package/packages/themes/kit/briefs/og-intro-15s/logo.svg +12 -0
- package/packages/themes/kit/effects.ts +5 -0
- package/packages/themes/kit/sample/index.html +11 -0
- package/packages/themes/kit/sample/main.ts +9 -0
- package/packages/themes/kit/sample/scenes/scene.ts +15 -0
- package/packages/themes/package.json +16 -0
- package/packages/themes/src/factory.ts +296 -0
- package/packages/themes/src/fx.ts +14 -0
- package/packages/themes/src/index.ts +105 -0
- package/packages/themes/src/stage3d.ts +177 -0
- package/packages/themes/src/types.ts +58 -0
- package/presets/kawaii-pastel.json +94 -0
- package/presets/neutral-dark.json +82 -0
- package/presets/og.json +98 -0
- package/skills/kasaframe/SKILL.md +32 -0
- package/templates/_shared/project/index.html +11 -0
- package/templates/_shared/project/lib/react.ts +22 -0
- package/templates/_shared/project/lib/stage.ts +272 -0
- package/templates/_shared/project/main.ts +9 -0
- package/templates/_shared/scenes/default.ts +18 -0
- package/templates/_shared/scenes/drop.ts +30 -0
- package/templates/_shared/scenes/end.ts +23 -0
- package/templates/_shared/scenes/hook.ts +16 -0
- package/templates/_shared/scenes/seam.ts +41 -0
- package/templates/_shared/scenes/step.ts +40 -0
- package/templates/ad/preview.png +0 -0
- package/templates/ad/template.json +132 -0
- package/templates/demo/preview.png +0 -0
- package/templates/demo/template.json +130 -0
- package/templates/explainer/preview.png +0 -0
- package/templates/explainer/template.json +142 -0
- package/templates/launch/preview.png +0 -0
- package/templates/launch/template.json +130 -0
- package/templates/mv/preview.png +0 -0
- package/templates/mv/scenes/default.ts +95 -0
- package/templates/mv/template.json +176 -0
- package/templates/promo/preview.png +0 -0
- package/templates/promo/template.json +144 -0
- package/templates/shorts/preview.png +0 -0
- package/templates/shorts/scenes/hook.ts +34 -0
- package/templates/shorts/template.json +127 -0
- package/templates/square/preview.png +0 -0
- package/templates/square/template.json +113 -0
- package/themes/debug-hud/THEME.md +39 -0
- package/themes/debug-hud/effects.ts +389 -0
- package/themes/debug-hud/sample/assets/og/logo.svg +12 -0
- package/themes/debug-hud/sample/beats.json +1 -0
- package/themes/debug-hud/sample/index.html +11 -0
- package/themes/debug-hud/sample/kf.json +59 -0
- package/themes/debug-hud/sample/lib/hudkit.ts +49 -0
- package/themes/debug-hud/sample/lib/og.ts +29 -0
- package/themes/debug-hud/sample/main.ts +9 -0
- package/themes/debug-hud/sample/scenes/end.ts +62 -0
- package/themes/debug-hud/sample/scenes/gather.ts +67 -0
- package/themes/debug-hud/sample/scenes/models.ts +70 -0
- package/themes/debug-hud/sample/scenes/price.ts +79 -0
- package/themes/debug-hud/sample/style.json +91 -0
- package/themes/debug-hud/still.png +0 -0
- package/themes/debug-hud/style.json +91 -0
- package/themes/debug-hud/theme.json +68 -0
- package/themes/og-measure/THEME.md +47 -0
- package/themes/og-measure/effects.ts +432 -0
- package/themes/og-measure/sample/assets/brand/og-logo-full.svg +12 -0
- package/themes/og-measure/sample/assets/brand/og-logo.svg +12 -0
- package/themes/og-measure/sample/assets/data/measure.json +353 -0
- package/themes/og-measure/sample/beats.json +1 -0
- package/themes/og-measure/sample/index.html +11 -0
- package/themes/og-measure/sample/kf.json +66 -0
- package/themes/og-measure/sample/lib/data.ts +62 -0
- package/themes/og-measure/sample/main.ts +9 -0
- package/themes/og-measure/sample/measure.ts +78 -0
- package/themes/og-measure/sample/scenes/end.ts +47 -0
- package/themes/og-measure/sample/scenes/gather.ts +51 -0
- package/themes/og-measure/sample/scenes/models.ts +34 -0
- package/themes/og-measure/sample/scenes/one.ts +39 -0
- package/themes/og-measure/sample/scenes/price.ts +56 -0
- package/themes/og-measure/sample/style.json +97 -0
- package/themes/og-measure/still.png +0 -0
- package/themes/og-measure/style.json +97 -0
- package/themes/og-measure/theme.json +79 -0
- package/themes/riso-zine/THEME.md +43 -0
- package/themes/riso-zine/effects.ts +321 -0
- package/themes/riso-zine/sample/assets/og/logo.svg +12 -0
- package/themes/riso-zine/sample/beats.json +1 -0
- package/themes/riso-zine/sample/index.html +11 -0
- package/themes/riso-zine/sample/kf.json +59 -0
- package/themes/riso-zine/sample/lib/og.ts +29 -0
- package/themes/riso-zine/sample/lib/shot.ts +86 -0
- package/themes/riso-zine/sample/lib/zine.ts +42 -0
- package/themes/riso-zine/sample/main.ts +9 -0
- package/themes/riso-zine/sample/scenes/end.ts +61 -0
- package/themes/riso-zine/sample/scenes/gather.ts +62 -0
- package/themes/riso-zine/sample/scenes/models.ts +52 -0
- package/themes/riso-zine/sample/scenes/price.ts +82 -0
- package/themes/riso-zine/sample/style.json +99 -0
- package/themes/riso-zine/still.png +0 -0
- package/themes/riso-zine/style.json +99 -0
- package/themes/riso-zine/theme.json +75 -0
- package/tools/beats/beats.py +372 -0
- package/tools/beats/requirements.txt +3 -0
- package/tools/lyrics/align.py +164 -0
- package/tools/lyrics/requirements.txt +9 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import type { Browser, CDPSession, Page } from "playwright";
|
|
2
|
+
import { launch } from "@kasaframe/cli";
|
|
3
|
+
import { probe, legacyShim } from "./probe.ts";
|
|
4
|
+
import { colorThumb, decodePng, inkContrast, luma, meanAbsDiff, type Rgba, type Thumb } from "./image.ts";
|
|
5
|
+
import type { FrameText, Marker, MotionEvent, TextHit } from "./types.ts";
|
|
6
|
+
import type { CamSample } from "./rules/camera.ts";
|
|
7
|
+
|
|
8
|
+
export interface ScanOptions {
|
|
9
|
+
url: string;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
// 옛 페이지처럼 meta 를 안 주는 곳에서만 쓴다
|
|
13
|
+
fps?: number;
|
|
14
|
+
duration?: number;
|
|
15
|
+
from?: number;
|
|
16
|
+
to?: number;
|
|
17
|
+
tabs: number;
|
|
18
|
+
thumbFps: number;
|
|
19
|
+
shotFps: number;
|
|
20
|
+
clock?: string;
|
|
21
|
+
log?: (s: string) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ContrastSample {
|
|
25
|
+
t: number;
|
|
26
|
+
text: string;
|
|
27
|
+
ratio: number;
|
|
28
|
+
sizePx: number;
|
|
29
|
+
box: { x0: number; y0: number; x1: number; y1: number };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface RepeatSample {
|
|
33
|
+
t: number;
|
|
34
|
+
diff: number;
|
|
35
|
+
textSame: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ScanResult {
|
|
39
|
+
meta: { fps: number; width: number; height: number; duration: number };
|
|
40
|
+
mode: "seek" | "step";
|
|
41
|
+
legacy: boolean;
|
|
42
|
+
markers: Marker[];
|
|
43
|
+
events: MotionEvent[];
|
|
44
|
+
texts: FrameText[];
|
|
45
|
+
thumbs: Thumb[];
|
|
46
|
+
thumbFps: number;
|
|
47
|
+
contrast: ContrastSample[];
|
|
48
|
+
errors: { t: number; text: string }[];
|
|
49
|
+
repeat: RepeatSample[];
|
|
50
|
+
glyphs: Record<string, string>;
|
|
51
|
+
// 썸네일 시각마다 카메라 층 transform·주인공 상자
|
|
52
|
+
cams: CamSample[];
|
|
53
|
+
frames: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface Opened {
|
|
57
|
+
page: Page;
|
|
58
|
+
cdp: CDPSession;
|
|
59
|
+
meta: ScanResult["meta"];
|
|
60
|
+
mode: "seek" | "step";
|
|
61
|
+
legacy: boolean;
|
|
62
|
+
markers: Marker[];
|
|
63
|
+
errors: { t: number; text: string }[];
|
|
64
|
+
cur: { t: number };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const THUMB_W = 160;
|
|
68
|
+
|
|
69
|
+
async function open(browser: Browser, o: ScanOptions): Promise<Opened> {
|
|
70
|
+
const page = await browser.newPage({ viewport: { width: o.width, height: o.height }, deviceScaleFactor: 1 });
|
|
71
|
+
const cur = { t: -1 };
|
|
72
|
+
const errors: Opened["errors"] = [];
|
|
73
|
+
page.on("pageerror", (e) => errors.push({ t: cur.t, text: `pageerror: ${e.message}` }));
|
|
74
|
+
page.on("console", (m) => {
|
|
75
|
+
if (m.type() === "error") errors.push({ t: cur.t, text: m.text() });
|
|
76
|
+
});
|
|
77
|
+
await page.addInitScript(probe);
|
|
78
|
+
if (o.clock) await page.addInitScript({ content: o.clock });
|
|
79
|
+
await page.goto(o.url, { waitUntil: "load" });
|
|
80
|
+
// main.ts 가 모듈 스크립트라 load 뒤에도 __kf 가 늦게 설 수 있다.
|
|
81
|
+
let kind = "none";
|
|
82
|
+
for (let i = 0; i < 150 && kind === "none"; i++) {
|
|
83
|
+
kind = await page.evaluate(legacyShim, { fps: o.fps ?? 60, duration: o.duration ?? 0 });
|
|
84
|
+
if (kind === "none") await page.waitForTimeout(100);
|
|
85
|
+
}
|
|
86
|
+
if (kind === "none") throw new Error(`페이지에 window.__kf 도 window.seek(t) 도 없다: ${o.url}`);
|
|
87
|
+
await page.evaluate(() => (window as any).__kf.ready());
|
|
88
|
+
const info = await page.evaluate(() => {
|
|
89
|
+
const k = (window as any).__kf;
|
|
90
|
+
return { meta: k.meta, mode: k.mode, markers: k.markers ?? [] };
|
|
91
|
+
});
|
|
92
|
+
const meta = { ...info.meta };
|
|
93
|
+
if (o.fps) meta.fps = o.fps;
|
|
94
|
+
if (o.duration) meta.duration = o.duration;
|
|
95
|
+
if (!(meta.duration > 0)) throw new Error("영상 길이를 모른다 — __kf.meta.duration 을 두거나 --duration 을 준다");
|
|
96
|
+
if (meta.width !== o.width || meta.height !== o.height) {
|
|
97
|
+
await page.setViewportSize({ width: meta.width, height: meta.height });
|
|
98
|
+
}
|
|
99
|
+
const cdp = await page.context().newCDPSession(page);
|
|
100
|
+
await page.evaluate(() => (window as any).__kfCheck.clear());
|
|
101
|
+
return { page, cdp, meta, mode: info.mode === "step" ? "step" : "seek", legacy: kind === "legacy", markers: info.markers, errors, cur };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function capture(cdp: CDPSession, w: number, h: number, scale: number): Promise<Rgba> {
|
|
105
|
+
const r = await cdp.send("Page.captureScreenshot", {
|
|
106
|
+
format: "png",
|
|
107
|
+
clip: { x: 0, y: 0, width: w, height: h, scale },
|
|
108
|
+
optimizeForSpeed: true,
|
|
109
|
+
});
|
|
110
|
+
return decodePng(Buffer.from(r.data, "base64"));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function seekTake(p: Opened, t: number): Promise<TextHit[]>;
|
|
114
|
+
async function seekTake(p: Opened, t: number, cam: true): Promise<{ hits: TextHit[]; cam: Omit<CamSample, "t"> }>;
|
|
115
|
+
async function seekTake(p: Opened, t: number, cam = false): Promise<any> {
|
|
116
|
+
p.cur.t = t;
|
|
117
|
+
return p.page.evaluate(
|
|
118
|
+
async ([tt, withCam]) => {
|
|
119
|
+
const w = window as any;
|
|
120
|
+
await w.__kf.seek(tt);
|
|
121
|
+
const hits = w.__kfCheck.take();
|
|
122
|
+
return withCam ? { hits, cam: w.__kfCheck.camera() } : hits;
|
|
123
|
+
},
|
|
124
|
+
[t, cam] as const,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function contrastOf(img: Rgba, t: number, hits: TextHit[]): ContrastSample[] {
|
|
129
|
+
const out: ContrastSample[] = [];
|
|
130
|
+
for (const h of hits) {
|
|
131
|
+
// 「·」 같은 문장부호 하나는 대비를 따질 글이 아니다.
|
|
132
|
+
if (!h.box || h.alpha < 0.6 || h.sizePx < 6 || !/[\p{L}\p{N}]/u.test(h.text)) continue;
|
|
133
|
+
const { x0, y0, x1, y1 } = h.box;
|
|
134
|
+
if (x1 <= 0 || y1 <= 0 || x0 >= img.width || y0 >= img.height) continue;
|
|
135
|
+
const ratio = inkContrast(img, h.box);
|
|
136
|
+
if (ratio === null) continue;
|
|
137
|
+
out.push({ t, text: h.text.slice(0, 60), ratio: Math.round(ratio * 100) / 100, sizePx: Math.round(h.sizePx), box: h.box });
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export async function scanPage(o: ScanOptions): Promise<ScanResult> {
|
|
143
|
+
const log = o.log ?? (() => {});
|
|
144
|
+
// 엔진과 같은 실행 플래그여야 「같은 프레임 두 번 찍기」가 렌더와 같은 조건이 된다.
|
|
145
|
+
const browser = await launch();
|
|
146
|
+
try {
|
|
147
|
+
const first = await open(browser, o);
|
|
148
|
+
const { meta } = first;
|
|
149
|
+
const tabs = first.mode === "step" ? 1 : Math.max(1, Math.min(3, o.tabs));
|
|
150
|
+
const opened = [first];
|
|
151
|
+
for (let i = 1; i < tabs; i++) opened.push(await open(browser, o));
|
|
152
|
+
|
|
153
|
+
const fps = meta.fps;
|
|
154
|
+
const total = Math.round(meta.duration * fps);
|
|
155
|
+
const i0 = Math.max(0, Math.floor((o.from ?? 0) * fps));
|
|
156
|
+
const i1 = Math.min(total, Math.ceil((o.to ?? meta.duration) * fps));
|
|
157
|
+
const thumbStep = Math.max(1, Math.round(fps / o.thumbFps));
|
|
158
|
+
const shotStep = Math.max(1, Math.round(fps / o.shotFps));
|
|
159
|
+
const per = Math.ceil((i1 - i0) / tabs);
|
|
160
|
+
const scale = THUMB_W / meta.width;
|
|
161
|
+
log(`훑기: ${(i0 / fps).toFixed(2)}–${(i1 / fps).toFixed(2)}초 ${i1 - i0}프레임 · 탭 ${tabs} · ${first.mode}${first.legacy ? "(옛 seek)" : ""}`);
|
|
162
|
+
|
|
163
|
+
const parts = await Promise.all(
|
|
164
|
+
opened.map(async (p, k) => {
|
|
165
|
+
const a = i0 + k * per;
|
|
166
|
+
const b = Math.min(i1, a + per);
|
|
167
|
+
const texts: FrameText[] = [];
|
|
168
|
+
const thumbs: Thumb[] = [];
|
|
169
|
+
const contrast: ContrastSample[] = [];
|
|
170
|
+
const cams: CamSample[] = [];
|
|
171
|
+
let next = 0.1;
|
|
172
|
+
for (let i = a; i < b; i++) {
|
|
173
|
+
const t = i / fps;
|
|
174
|
+
const onThumb = i % thumbStep === 0;
|
|
175
|
+
const got = onThumb ? await seekTake(p, t, true) : { hits: await seekTake(p, t), cam: null };
|
|
176
|
+
const hits = got.hits;
|
|
177
|
+
if (got.cam) cams.push({ t, ...got.cam });
|
|
178
|
+
if (hits.length) texts.push({ t, hits });
|
|
179
|
+
if (onThumb) thumbs.push(colorThumb(t, await capture(p.cdp, meta.width, meta.height, scale)));
|
|
180
|
+
if (i % shotStep === 0 && hits.length) contrast.push(...contrastOf(await capture(p.cdp, meta.width, meta.height, 1), t, hits));
|
|
181
|
+
if ((i - a) / (b - a) >= next) {
|
|
182
|
+
log(` 탭 ${k + 1}: ${Math.round(next * 100)}%`);
|
|
183
|
+
next += 0.25;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const repeat: RepeatSample[] = [];
|
|
187
|
+
if (p.mode === "seek" && b - a > 10) {
|
|
188
|
+
for (const f of [0.2, 0.5, 0.8]) {
|
|
189
|
+
const t = Math.round(a + (b - a) * f) / fps;
|
|
190
|
+
const hA = await seekTake(p, t);
|
|
191
|
+
const A = luma(await capture(p.cdp, meta.width, meta.height, 0.25));
|
|
192
|
+
await seekTake(p, Math.max(0, t - 0.5));
|
|
193
|
+
const hB = await seekTake(p, t);
|
|
194
|
+
const B = luma(await capture(p.cdp, meta.width, meta.height, 0.25));
|
|
195
|
+
const key = (h: TextHit[]) => h.map((x) => x.text).join("\u0001");
|
|
196
|
+
repeat.push({ t, diff: Math.round(meanAbsDiff(A, B) * 1000) / 1000, textSame: key(hA) === key(hB) });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const events: MotionEvent[] = await p.page.evaluate(() => (window as any).__kf.events ?? []);
|
|
200
|
+
return { texts, thumbs, contrast, repeat, events, cams };
|
|
201
|
+
}),
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
const texts = parts.flatMap((x) => x.texts).sort((a, b) => a.t - b.t);
|
|
205
|
+
const pairs = new Set<string>();
|
|
206
|
+
for (const f of texts) for (const h of f.hits) for (const ch of new Set(h.text)) if (ch.trim()) pairs.add(h.font + "\u0000" + ch);
|
|
207
|
+
const list = [...pairs].slice(0, 6000).map((k) => k.split("\u0000") as [string, string]);
|
|
208
|
+
const glyphs: Record<string, string> = list.length ? await first.page.evaluate((ps) => (window as any).__kfCheck.glyphs(ps), list) : {};
|
|
209
|
+
|
|
210
|
+
const seen = new Set<string>();
|
|
211
|
+
const events = parts
|
|
212
|
+
.flatMap((x) => x.events)
|
|
213
|
+
.filter((e) => {
|
|
214
|
+
const key = `${e.t}|${e.kind}|${e.source}|${e.scene ?? ""}`;
|
|
215
|
+
if (seen.has(key)) return false;
|
|
216
|
+
seen.add(key);
|
|
217
|
+
return true;
|
|
218
|
+
})
|
|
219
|
+
.sort((a, b) => a.t - b.t);
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
meta,
|
|
223
|
+
mode: first.mode,
|
|
224
|
+
legacy: first.legacy,
|
|
225
|
+
markers: first.markers,
|
|
226
|
+
events,
|
|
227
|
+
texts,
|
|
228
|
+
thumbs: parts.flatMap((x) => x.thumbs).sort((a, b) => a.t - b.t),
|
|
229
|
+
thumbFps: fps / thumbStep,
|
|
230
|
+
contrast: parts.flatMap((x) => x.contrast),
|
|
231
|
+
errors: opened.flatMap((p) => p.errors).sort((a, b) => a.t - b.t),
|
|
232
|
+
repeat: parts.flatMap((x) => x.repeat),
|
|
233
|
+
glyphs,
|
|
234
|
+
cams: parts.flatMap((x) => x.cams).sort((a, b) => a.t - b.t),
|
|
235
|
+
frames: i1 - i0,
|
|
236
|
+
};
|
|
237
|
+
} finally {
|
|
238
|
+
await browser.close();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createServer, type Server } from "node:http";
|
|
2
|
+
import { createReadStream, statSync } from "node:fs";
|
|
3
|
+
import { extname, join, normalize, resolve, sep } from "node:path";
|
|
4
|
+
|
|
5
|
+
const MIME: Record<string, string> = {
|
|
6
|
+
".html": "text/html; charset=utf-8",
|
|
7
|
+
".js": "text/javascript; charset=utf-8",
|
|
8
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
9
|
+
".css": "text/css; charset=utf-8",
|
|
10
|
+
".json": "application/json; charset=utf-8",
|
|
11
|
+
".svg": "image/svg+xml",
|
|
12
|
+
".png": "image/png",
|
|
13
|
+
".jpg": "image/jpeg",
|
|
14
|
+
".jpeg": "image/jpeg",
|
|
15
|
+
".webp": "image/webp",
|
|
16
|
+
".gif": "image/gif",
|
|
17
|
+
".ttf": "font/ttf",
|
|
18
|
+
".otf": "font/otf",
|
|
19
|
+
".woff": "font/woff",
|
|
20
|
+
".woff2": "font/woff2",
|
|
21
|
+
".mp3": "audio/mpeg",
|
|
22
|
+
".wav": "audio/wav",
|
|
23
|
+
".mp4": "video/mp4",
|
|
24
|
+
".webm": "video/webm",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// 빌드가 필요 없는 페이지(옛 방식·바닐라 html)를 띄우는 정적 서버.
|
|
28
|
+
// kf 프로젝트는 엔진의 openProject(Vite)로 연다.
|
|
29
|
+
export async function serveStatic(dir: string): Promise<{ url: string; close(): Promise<void> }> {
|
|
30
|
+
const root = resolve(dir);
|
|
31
|
+
const server = createServer((req, res) => {
|
|
32
|
+
const path = decodeURIComponent((req.url || "/").split("?")[0]);
|
|
33
|
+
let file = normalize(join(root, path));
|
|
34
|
+
if (file !== root && !file.startsWith(root + sep)) {
|
|
35
|
+
res.writeHead(403).end();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
if (statSync(file).isDirectory()) file = join(file, "index.html");
|
|
40
|
+
const st = statSync(file);
|
|
41
|
+
res.writeHead(200, { "content-type": MIME[extname(file).toLowerCase()] || "application/octet-stream", "content-length": st.size });
|
|
42
|
+
createReadStream(file).pipe(res);
|
|
43
|
+
} catch {
|
|
44
|
+
res.writeHead(404).end();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
const port = await listen(server);
|
|
48
|
+
return {
|
|
49
|
+
url: `http://127.0.0.1:${port}/`,
|
|
50
|
+
close: () => new Promise((r) => server.close(() => r())),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// TEAM.md 가 검사 담당에 준 포트 5130–5139 를 먼저 쓰고, 다 차면 아무 빈 포트.
|
|
55
|
+
async function listen(server: Server): Promise<number> {
|
|
56
|
+
for (const port of [5130, 5131, 5132, 5133, 5134, 5135, 5136, 5137, 5138, 5139, 0]) {
|
|
57
|
+
const ok = await new Promise<boolean>((r) => {
|
|
58
|
+
server.once("error", () => r(false));
|
|
59
|
+
server.listen(port, "127.0.0.1", () => r(true));
|
|
60
|
+
});
|
|
61
|
+
if (ok) {
|
|
62
|
+
const a = server.address();
|
|
63
|
+
return typeof a === "object" && a ? a.port : port;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throw new Error("빈 포트가 없다");
|
|
67
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { KfMotionEvent, MotionRules as CoreMotionRules, SafeArea } from "@kasaframe/core";
|
|
2
|
+
|
|
3
|
+
export type Severity = "error" | "warn";
|
|
4
|
+
|
|
5
|
+
export interface Finding {
|
|
6
|
+
rule: string;
|
|
7
|
+
severity: Severity;
|
|
8
|
+
from: number;
|
|
9
|
+
to: number;
|
|
10
|
+
message: string;
|
|
11
|
+
// 고치는 쪽(사람이든 모델이든)이 곧장 손댈 자리를 찾도록 원자료를 붙인다.
|
|
12
|
+
detail?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface Report {
|
|
16
|
+
target: string;
|
|
17
|
+
kind: "page" | "video";
|
|
18
|
+
// 페이지만 — step 이면 「같은 프레임 두 번」을 못 본다
|
|
19
|
+
mode?: "seek" | "step";
|
|
20
|
+
ok: boolean;
|
|
21
|
+
meta: { fps: number; width: number; height: number; duration: number };
|
|
22
|
+
sampled: { frames: number; textFrames: number; thumbFps: number };
|
|
23
|
+
counts: { error: number; warn: number };
|
|
24
|
+
findings: Finding[];
|
|
25
|
+
skipped: string[];
|
|
26
|
+
elapsedSec: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface Box {
|
|
30
|
+
x0: number;
|
|
31
|
+
y0: number;
|
|
32
|
+
x1: number;
|
|
33
|
+
y1: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface TextHit {
|
|
37
|
+
text: string;
|
|
38
|
+
// canvas 는 fillText·strokeText, DOM 은 text node
|
|
39
|
+
// caption — 엔진이 장면 위에 얹은 자막 판(data-kf-captions). 장면 글과 한 줄로 잇지 않는다
|
|
40
|
+
via: "canvas" | "dom" | "caption";
|
|
41
|
+
// 가사 층(data-kf-lyrics — JIZURA 같은 키네틱 가사) 안의 글. 띠로 흘리는 마퀴·배경 큰 글자처럼 일부러 화면 끝을 넘겨 그린다
|
|
42
|
+
lyrics?: boolean;
|
|
43
|
+
// fillText 에 문자열이 아닌 값(undefined·숫자·객체)이 들어왔을 때 그 typeof
|
|
44
|
+
argType?: string;
|
|
45
|
+
font: string;
|
|
46
|
+
sizePx: number;
|
|
47
|
+
alpha: number;
|
|
48
|
+
// 화면(뷰포트) 좌표. 화면에 붙지 않은 오프스크린 canvas 면 없다.
|
|
49
|
+
box?: Box;
|
|
50
|
+
where?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface FrameText {
|
|
54
|
+
t: number;
|
|
55
|
+
hits: TextHit[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type MotionEvent = KfMotionEvent;
|
|
59
|
+
|
|
60
|
+
export interface Marker {
|
|
61
|
+
t: number;
|
|
62
|
+
label: string;
|
|
63
|
+
kind: "scene" | "beat" | "drop" | "section";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface Beats {
|
|
67
|
+
duration?: number;
|
|
68
|
+
bpm?: number;
|
|
69
|
+
beats: number[];
|
|
70
|
+
downbeats?: number[];
|
|
71
|
+
bars?: number[];
|
|
72
|
+
phrases?: number[];
|
|
73
|
+
sections?: { t: number; kind: string; strength?: number }[];
|
|
74
|
+
drops?: number[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// style.json 은 손으로 고치는 파일이라 빠진 칸이 있어도 검사는 돈다.
|
|
78
|
+
export type MotionRules = Partial<CoreMotionRules>;
|
|
79
|
+
|
|
80
|
+
export type { SafeArea };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { spawn, execFileSync } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync } from "node:fs";
|
|
4
|
+
import { homedir, tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { colorThumb, type Thumb } from "./image.ts";
|
|
8
|
+
import type { FrameText, TextHit } from "./types.ts";
|
|
9
|
+
|
|
10
|
+
export interface VideoInfo {
|
|
11
|
+
fps: number;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
duration: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function probeVideo(file: string): VideoInfo {
|
|
18
|
+
const out = execFileSync("ffprobe", ["-v", "error", "-select_streams", "v:0", "-show_entries", "stream=width,height,r_frame_rate:format=duration", "-of", "json", file], {
|
|
19
|
+
encoding: "utf8",
|
|
20
|
+
});
|
|
21
|
+
const j = JSON.parse(out);
|
|
22
|
+
const s = j.streams?.[0];
|
|
23
|
+
if (!s) throw new Error(`영상 스트림이 없다: ${file}`);
|
|
24
|
+
const [n, d] = String(s.r_frame_rate).split("/").map(Number);
|
|
25
|
+
return { fps: d ? n / d : n, width: s.width, height: s.height, duration: Number(j.format.duration) };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const TW = 160;
|
|
29
|
+
|
|
30
|
+
// 모든 프레임을 160×90 회색조로 받아 멈춤·빈 화면·컷을 잰다. 60초 60fps 면 52MB 남짓.
|
|
31
|
+
export async function videoThumbs(file: string, info: VideoInfo, from = 0, to = info.duration): Promise<Thumb[]> {
|
|
32
|
+
// 페이지 검사의 썸네일처럼 화면비를 지킨다 — 160×90 으로 누르면 세로 영상의 안전 영역이 뒤집혀 layout.fill 이 늘 0% 였다
|
|
33
|
+
const TH = Math.max(2, Math.round((TW * info.height) / info.width));
|
|
34
|
+
// 색을 받아 섬광 검사의 빨강도 본다 — 밝기는 페이지 검사와 같은 식으로 여기서 만든다
|
|
35
|
+
const args = ["-v", "error", "-ss", String(from), "-t", String(to - from), "-i", file, "-vf", `scale=${TW}:${TH}:flags=area,format=rgb24`, "-f", "rawvideo", "-"];
|
|
36
|
+
const proc = spawn("ffmpeg", args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
37
|
+
const size = TW * TH * 3;
|
|
38
|
+
const thumbs: Thumb[] = [];
|
|
39
|
+
let buf = Buffer.alloc(0);
|
|
40
|
+
let err = "";
|
|
41
|
+
proc.stderr.on("data", (d) => (err += d));
|
|
42
|
+
for await (const chunk of proc.stdout) {
|
|
43
|
+
buf = buf.length ? Buffer.concat([buf, chunk]) : chunk;
|
|
44
|
+
while (buf.length >= size) {
|
|
45
|
+
const data = new Uint8Array(TW * TH * 4);
|
|
46
|
+
for (let i = 0, j = 0; i < size; i += 3, j += 4) {
|
|
47
|
+
data[j] = buf[i];
|
|
48
|
+
data[j + 1] = buf[i + 1];
|
|
49
|
+
data[j + 2] = buf[i + 2];
|
|
50
|
+
}
|
|
51
|
+
thumbs.push(colorThumb(from + thumbs.length / info.fps, { width: TW, height: TH, data }));
|
|
52
|
+
buf = buf.subarray(size);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const code = await new Promise<number>((r) => proc.on("close", r));
|
|
56
|
+
if (code !== 0) throw new Error(`ffmpeg 실패: ${err.slice(0, 300)}`);
|
|
57
|
+
return thumbs;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function ocrBinary(): string | null {
|
|
61
|
+
if (process.platform !== "darwin") return null;
|
|
62
|
+
const src = fileURLToPath(new URL("./ocr.swift", import.meta.url));
|
|
63
|
+
const hash = createHash("sha1").update(readFileSync(src)).digest("hex").slice(0, 10);
|
|
64
|
+
const dir = join(homedir(), ".cache", "kasaframe");
|
|
65
|
+
const bin = join(dir, `kf-ocr-${hash}`);
|
|
66
|
+
if (existsSync(bin)) return bin;
|
|
67
|
+
mkdirSync(dir, { recursive: true });
|
|
68
|
+
try {
|
|
69
|
+
const tmp = `${bin}.${process.pid}`;
|
|
70
|
+
execFileSync("swiftc", ["-O", src, "-o", tmp], { stdio: "ignore" });
|
|
71
|
+
renameSync(tmp, bin);
|
|
72
|
+
return bin;
|
|
73
|
+
} catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function runOcr(bin: string, dir: string): Promise<{ file: string; items: { s: string; c: number; x0: number; y0: number; x1: number; y1: number }[] }[]> {
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
const p = spawn(bin, [dir], { stdio: ["ignore", "pipe", "pipe"] });
|
|
81
|
+
let out = "";
|
|
82
|
+
p.stdout.on("data", (d) => (out += d));
|
|
83
|
+
p.on("close", (code) =>
|
|
84
|
+
code === 0
|
|
85
|
+
? resolve(
|
|
86
|
+
out
|
|
87
|
+
.split("\n")
|
|
88
|
+
.filter(Boolean)
|
|
89
|
+
.map((l) => JSON.parse(l)),
|
|
90
|
+
)
|
|
91
|
+
: reject(new Error(`OCR 실패 (${code})`)),
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// mp4 에는 글자 정보가 없다. macOS Vision 으로 읽어 페이지 검사와 같은 꼴(FrameText)로 돌려준다.
|
|
97
|
+
// 다른 OS 거나 swiftc 가 없으면 null — 그때 글 검사는 건너뛰었다고 보고서에 적는다.
|
|
98
|
+
export async function videoText(file: string, info: VideoInfo, o: { fps: number; from?: number; to?: number; workers?: number }): Promise<FrameText[] | null> {
|
|
99
|
+
const bin = ocrBinary();
|
|
100
|
+
if (!bin) return null;
|
|
101
|
+
const from = o.from ?? 0;
|
|
102
|
+
const to = o.to ?? info.duration;
|
|
103
|
+
const root = mkdtempSync(join(tmpdir(), "kf-check-"));
|
|
104
|
+
try {
|
|
105
|
+
execFileSync("ffmpeg", ["-v", "error", "-ss", String(from), "-t", String(to - from), "-i", file, "-vf", `fps=${o.fps}`, join(root, "%06d.png")]);
|
|
106
|
+
const files = readdirSync(root).filter((f) => f.endsWith(".png")).sort();
|
|
107
|
+
const workers = Math.max(1, Math.min(o.workers ?? 4, files.length));
|
|
108
|
+
const dirs = Array.from({ length: workers }, (_, i) => {
|
|
109
|
+
const d = join(root, `w${i}`);
|
|
110
|
+
mkdirSync(d);
|
|
111
|
+
return d;
|
|
112
|
+
});
|
|
113
|
+
files.forEach((f, i) => renameSync(join(root, f), join(dirs[i % workers], f)));
|
|
114
|
+
const parts = await Promise.all(dirs.map((d) => runOcr(bin, d)));
|
|
115
|
+
const frames: FrameText[] = [];
|
|
116
|
+
for (const r of parts.flat()) {
|
|
117
|
+
const idx = Number(r.file.replace(/\D/g, "")) - 1;
|
|
118
|
+
const t = from + idx / o.fps;
|
|
119
|
+
const hits: TextHit[] = r.items.map((it) => {
|
|
120
|
+
const h = (it.y1 - it.y0) * info.height;
|
|
121
|
+
return {
|
|
122
|
+
text: it.s,
|
|
123
|
+
via: "dom",
|
|
124
|
+
font: "ocr",
|
|
125
|
+
sizePx: h * 0.8,
|
|
126
|
+
alpha: 1,
|
|
127
|
+
box: { x0: it.x0 * info.width, y0: it.y0 * info.height, x1: it.x1 * info.width, y1: it.y1 * info.height },
|
|
128
|
+
where: `ocr ${Math.round(it.c * 100)}%`,
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
if (hits.length) frames.push({ t, hits });
|
|
132
|
+
}
|
|
133
|
+
return frames.sort((a, b) => a.t - b.t);
|
|
134
|
+
} finally {
|
|
135
|
+
rmSync(root, { recursive: true, force: true });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kasaframe/cli",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"kf": "./src/kf.ts"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./src/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@kasaframe/adapters": "^0.0.0",
|
|
14
|
+
"@kasaframe/clock": "^0.0.0",
|
|
15
|
+
"esbuild": "^0.28.2",
|
|
16
|
+
"playwright": "^1.64.0",
|
|
17
|
+
"vite": "^8.3.3",
|
|
18
|
+
"@kasaframe/motion": "0.0.0",
|
|
19
|
+
"pngjs": "^7.0.0",
|
|
20
|
+
"@kasaframe/jizura": "^0.0.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
24
|
+
"gsap": "^3.15.0",
|
|
25
|
+
"lottie-web": "^5.13.0",
|
|
26
|
+
"three": "^0.186.1",
|
|
27
|
+
"@types/pngjs": "^6.0.5"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { PNG } from "pngjs";
|
|
2
|
+
import type { PageInfo, Tab } from "./browser.ts";
|
|
3
|
+
|
|
4
|
+
export interface BlurOpts {
|
|
5
|
+
/** 하위 프레임 수 — 2 이상이면 켠다 */
|
|
6
|
+
count: number;
|
|
7
|
+
/** 셔터 각도(도). 180 이면 프레임 간격의 절반 동안 열려 있다 */
|
|
8
|
+
shutter: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function blurOpts(opts: Record<string, string | boolean | undefined>): BlurOpts | null {
|
|
12
|
+
const count = Math.round(Number(opts["motion-blur"] ?? 0));
|
|
13
|
+
if (!(count > 1)) return null;
|
|
14
|
+
const shutter = Number(opts.shutter ?? 180);
|
|
15
|
+
return { count, shutter: Number.isFinite(shutter) ? Math.min(360, Math.max(1, shutter)) : 180 };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 하위 프레임은 그 프레임이 속한 장면 안에서만 — 셔터가 컷을 넘으면 두 장면이 겹쳐 찍힌다
|
|
19
|
+
function sceneSpan(info: PageInfo, t: number): [number, number] {
|
|
20
|
+
const starts = info.markers.filter((m) => m.kind === "scene").map((m) => m.t).sort((a, b) => a - b);
|
|
21
|
+
let a = 0;
|
|
22
|
+
let b = info.meta.duration;
|
|
23
|
+
for (const s of starts) {
|
|
24
|
+
if (s <= t + 1e-9) a = s;
|
|
25
|
+
else {
|
|
26
|
+
b = s;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return [a, b];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 프레임 시각 t 둘레(가운데 맞춤 셔터)의 하위 시각들 */
|
|
34
|
+
export function subTimes(info: PageInfo, t: number, o: BlurOpts): number[] {
|
|
35
|
+
const [a, b] = sceneSpan(info, t);
|
|
36
|
+
const open = o.shutter / 360 / info.meta.fps;
|
|
37
|
+
const last = b - 1 / (info.meta.fps * 1000);
|
|
38
|
+
return Array.from({ length: o.count }, (_, i) => Math.min(last, Math.max(a, t + ((i + 0.5) / o.count - 0.5) * open)));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 한 프레임을 하위 프레임 count 장으로 찍어 평균한 RGBA. 빨리 움직이는 것만 번지고 서 있는 것은 그대로다.
|
|
43
|
+
* 하위 프레임 번호를 페이지에 넘겨, 3D 전환이 같은 평균으로 피사계 심도를 얻는다. 같은 t 면 같은 그림
|
|
44
|
+
*/
|
|
45
|
+
export async function captureBlurred(tab: Tab, info: PageInfo, t: number, o: BlurOpts): Promise<{ data: Buffer; width: number; height: number }> {
|
|
46
|
+
let acc: Uint32Array | null = null;
|
|
47
|
+
let width = 0;
|
|
48
|
+
let height = 0;
|
|
49
|
+
const times = subTimes(info, t, o);
|
|
50
|
+
for (const [index, ts] of times.entries()) {
|
|
51
|
+
await tab.seek(ts, { index, count: o.count });
|
|
52
|
+
const img = PNG.sync.read(await tab.capture());
|
|
53
|
+
width = img.width;
|
|
54
|
+
height = img.height;
|
|
55
|
+
acc ??= new Uint32Array(img.data.length);
|
|
56
|
+
for (let j = 0; j < img.data.length; j++) acc[j] += img.data[j];
|
|
57
|
+
}
|
|
58
|
+
const n = times.length;
|
|
59
|
+
const data = Buffer.alloc(acc!.length);
|
|
60
|
+
for (let j = 0; j < acc!.length; j++) data[j] = Math.round(acc![j] / n);
|
|
61
|
+
return { data, width, height };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function rgbaToPng(img: { data: Buffer; width: number; height: number }): Buffer {
|
|
65
|
+
const png = new PNG({ width: img.width, height: img.height });
|
|
66
|
+
img.data.copy(png.data);
|
|
67
|
+
return PNG.sync.write(png, { deflateLevel: 1 });
|
|
68
|
+
}
|