@lunagerm-studio/video-cut-skill 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/README.md +13 -2
- package/package.json +12 -4
- package/skills/ai-video-opening/SKILL.md +62 -0
- package/skills/ai-video-opening/references/export-and-validation.md +9 -0
- package/skills/ai-video-opening/references/motion-and-layout.md +7 -0
- package/skills/ai-video-opening/references/series-cases.md +7 -0
- package/skills/blue-white-ui-motion/SKILL.md +30 -0
- package/skills/blue-white-ui-motion/agents/openai.yaml +2 -0
- package/skills/blue-white-ui-motion/references/review.md +25 -0
- package/skills/chengfeng-videocut-skills/LICENSE +201 -0
- package/skills/chengfeng-videocut-skills/NOTICE.md +27 -0
- package/skills/chengfeng-videocut-skills/README.md +265 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/SKILL.md +37 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/agents/openai.yaml +2 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/cut_video.sh +182 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/detect_en_stutter.js +49 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/generate_review.js +1484 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/generate_srt_for_video.sh +75 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/generate_subtitles.js +141 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/review_server.js +381 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/volcengine_transcribe.sh +224 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255/scripts/watch_cut_done.js +86 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/1-/346/240/270/345/277/203/345/216/237/345/210/231.md +56 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/10-/345/210/240/351/231/244/351/243/216/351/231/251/345/210/206/345/261/202.md +44 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/11-/345/217/243/346/222/255/347/250/277/345/257/271/351/275/220.md +40 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/2-/350/257/255/346/260/224/350/257/215/346/243/200/346/265/213.md +30 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/3-/351/235/231/351/237/263/346/256/265/345/244/204/347/220/206.md +56 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/4-/351/207/215/345/244/215/346/243/200/346/265/213.md +77 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/5-/345/215/241/351/241/277/350/257/215.md +48 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/7-/350/277/236/347/273/255/350/257/255/346/260/224/350/257/215.md +32 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/9-/346/256/213/345/217/245/346/243/200/346/265/213.md +79 -0
- package/skills/chengfeng-videocut-skills//345/211/252/345/217/243/346/222/255//347/224/250/346/210/267/344/271/240/346/203/257/README.md +35 -0
- package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/SKILL.md +32 -0
- package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/agents/openai.yaml +2 -0
- package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/references/artifact-contracts.md +168 -0
- package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/scripts/animation_style.cjs +53 -0
- package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/scripts/export_final_video.cjs +200 -0
- package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/scripts/serve_range_preview.cjs +128 -0
- package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/scripts/user_config.cjs +80 -0
- package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207/scripts/write_render_mode.cjs +149 -0
- package/skills/chengfeng-videocut-skills//345/217/243/346/222/255/346/210/220/347/211/207//347/224/250/346/210/267/351/205/215/347/275/256/default.json +4 -0
- package/skills/chengfeng-videocut-skills//350/207/252/350/277/233/345/214/226/README.md +23 -0
- package/skills/chengfeng-videocut-skills//350/207/252/350/277/233/345/214/226/SKILL.md +126 -0
- package/skills/continuous-collage-motion/SKILL.md +30 -0
- package/skills/continuous-collage-motion/agents/openai.yaml +4 -0
- package/skills/continuous-collage-motion/references/reference-motion.md +32 -0
- package/skills/continuous-collage-motion/references/shot-plan.md +31 -0
- package/skills/continuous-collage-motion/references/style-check.md +17 -0
- package/skills/table-video/LICENSES/ATTRIBUTION.md +31 -0
- package/skills/table-video/LICENSES/CC-BY-4.0.txt +396 -0
- package/skills/table-video/LICENSES/MIT.txt +21 -0
- package/skills/table-video/SKILL.md +32 -0
- package/skills/table-video/SOURCES.md +61 -0
- package/skills/table-video/agents/openai.yaml +2 -0
- package/skills/table-video/references/complete-motion.md +97 -0
- package/skills/table-video/references/examples/01_/344/270/244/346/256/265/346/274/224/347/244/272.md +73 -0
- package/skills/table-video/references/examples/02_/347/224/237/345/233/276/347/224/237/350/247/206/351/242/221/346/217/220/347/244/272/350/257/215/347/244/272/344/276/213.md +50 -0
- package/skills/table-video/references/examples/03_DESIGN/345/241/253/345/206/231/347/244/272/344/276/213.md +333 -0
- package/skills/table-video/references/examples/04_/350/277/236/347/273/255MG/346/255/243/345/217/215/350/277/207/347/250/213.md +101 -0
- package/skills/table-video/references/examples/05_/345/256/214/346/225/264/350/277/207/347/250/213/346/272/220/347/240/201.md +55 -0
- package/skills/table-video/references/examples/05_/346/205/242/351/225/234/345/244/264/344/270/216/345/220/214/346/236/204/345/233/276/345/233/236/345/275/222.md +35 -0
- package/skills/table-video/references/experience//345/255/227/345/271/225/344/270/216/345/260/201/351/235/242.md +30 -0
- package/skills/table-video/references/experience//345/275/225/345/261/217/345/211/252/350/276/221.md +31 -0
- package/skills/table-video/references/experience//346/211/213/345/212/250/347/224/237/345/233/276/347/224/237/350/247/206/351/242/221.md +53 -0
- package/skills/table-video/references/experience//350/247/206/350/247/211/345/217/231/344/272/213/344/270/216/350/277/236/347/273/255MG.md +102 -0
- package/skills/table-video/references/experience//351/225/234/345/244/264/346/216/250/350/277/233/344/270/216/350/275/254/345/234/272.md +178 -0
- package/skills/table-video/references/intake.md +84 -0
- package/skills/table-video/references/library.md +26 -0
- package/skills/table-video/references/motion-check-method.md +147 -0
- package/skills/table-video/references/planning.md +62 -0
- package/skills/table-video/references/production.md +70 -0
- package/skills/table-video/references/project-rules.md +26 -0
- package/skills/table-video/references/review-and-repair.md +64 -0
- package/skills/table-video/references/self-diagnosis.md +46 -0
- package/skills/table-video/references/sop/01_/345/277/253/351/200/237/345/274/200/345/247/213.md +55 -0
- package/skills/table-video/references/sop/02_/345/210/266/344/275/234SOP.md +77 -0
- package/skills/table-video/references/sop/03_/347/233/256/345/275/225/344/270/216/345/271/266/350/241/214/345/215/217/344/275/234.md +72 -0
- package/skills/table-video/references/sop/04_/351/252/214/346/224/266/344/270/216/350/277/224/344/277/256.md +146 -0
- package/skills/table-video/references/sop/05_/346/226/207/346/241/210/346/243/200/346/237/245_/345/217/257/351/200/211.md +55 -0
- package/skills/table-video/references/sop/06_/351/237/263/346/225/210/344/270/216/351/205/215/344/271/220_/345/217/257/351/200/211.md +138 -0
- package/skills/table-video/references/sop/07_/345/267/245/345/205/267/344/270/216/347/216/257/345/242/203.md +52 -0
- package/skills/table-video/references/sop/08_/346/235/245/346/272/220/344/270/216/350/256/270/345/217/257.md +36 -0
- package/skills/table-video/references/sop/09_DESIGN/345/273/272/347/253/213/344/270/216/346/240/241/351/252/214.md +52 -0
- package/skills/table-video/references/state-contract.md +267 -0
- package/skills/table-video/references/style-and-motion.md +163 -0
- package/skills/table-video/schemas/request.schema.json +44 -0
- package/skills/table-video/schemas/state.schema.json +140 -0
- package/skills/table-video/scripts/cli.mjs +35 -0
- package/skills/table-video/scripts/core.mjs +977 -0
- package/skills/table-video/scripts/gain-proof.mjs +48 -0
- package/skills/table-video/scripts/init-project.mjs +7 -0
- package/skills/table-video/scripts/motion-audit.mjs +589 -0
- package/skills/table-video/scripts/motion-check.mjs +345 -0
- package/skills/table-video/scripts/motion-gates.mjs +997 -0
- package/skills/table-video/scripts/motion-observation.cjs +204 -0
- package/skills/table-video/scripts/preflight.mjs +24 -0
- package/skills/table-video/scripts/process-locate.mjs +57 -0
- package/skills/table-video/scripts/render-motion-example.mjs +143 -0
- package/skills/table-video/scripts/save-reference-image.mjs +249 -0
- package/skills/table-video/scripts/schema.mjs +71 -0
- package/skills/table-video/scripts/stillness.mjs +386 -0
- package/skills/table-video/scripts/storage.mjs +328 -0
- package/skills/table-video/scripts/workflow.mjs +24 -0
- package/skills/talking-head-motion-workflow/SKILL.md +36 -0
- package/skills/talking-head-motion-workflow/agents/openai.yaml +4 -0
- package/skills/talking-head-motion-workflow/references/cinematic-motion-and-sync.md +72 -0
- package/skills/talking-head-motion-workflow/references/classic-ui.md +11 -0
- package/skills/talking-head-motion-workflow/references/history-coverage.md +50 -0
- package/skills/talking-head-motion-workflow/references/layered-assets-and-characters.md +39 -0
- package/skills/talking-head-motion-workflow/references/layout-references.md +41 -0
- package/skills/talking-head-motion-workflow/references/lens-shot-selection.md +138 -0
- package/skills/talking-head-motion-workflow/references/live-interface-motion.md +69 -0
- package/skills/talking-head-motion-workflow/references/motion-recipes.md +40 -0
- package/skills/talking-head-motion-workflow/references/mouse-meter2-case.md +113 -0
- package/skills/talking-head-motion-workflow/references/pop-collage.md +61 -0
- package/skills/talking-head-motion-workflow/references/portable-production.md +32 -0
- package/skills/talking-head-motion-workflow/references/production-requirements.md +85 -0
- package/skills/talking-head-motion-workflow/references/reference-library.md +41 -0
- package/skills/talking-head-motion-workflow/references/safe-areas-and-sound.md +47 -0
- package/skills/talking-head-motion-workflow/references/scene-illustrations.md +19 -0
- package/skills/talking-head-motion-workflow/references/sfx-presets.md +57 -0
- package/skills/talking-head-motion-workflow/references/style-13-github-production.md +33 -0
- package/skills/talking-head-motion-workflow/references/style-13-scene-performance.md +76 -0
- package/skills/talking-head-motion-workflow/references/style-presets.md +111 -0
- package/skills/talking-head-motion-workflow/references/table-video-spatial-mg.md +36 -0
- package/skills/talking-head-motion-workflow/scripts/extract_docx.py +19 -0
- package/skills/talking-head-motion-workflow/scripts/generate_foley.py +93 -0
- package/skills/talking-head-motion-workflow/scripts/render_sfx.py +135 -0
- package/skills/video-production-review/SKILL.md +30 -0
- package/skills/video-production-review/agents/openai.yaml +2 -0
- package/skills/video-production-review/references/episode-review-desk.md +30 -0
- package/skills/video-production-review/references/motion-adjustment-review.md +21 -0
- package/skills/video-production-workflow/SKILL.md +76 -0
- package/skills/video-production-workflow/agents/openai.yaml +2 -0
- package/skills/video-production-workflow/references/table-video-ep09.md +17 -0
- package/skills/video-production-workflow/scripts/check_motion_project.py +83 -0
- package/skills/video-reference-analysis/SKILL.md +32 -0
- package/skills/video-reference-analysis/agents/openai.yaml +2 -0
- package/skills/video-reference-analysis/references/case-format.md +95 -0
- package/skills/video-reference-analysis/references/production-method.md +21 -0
- package/skills/video-reference-analysis/scripts/library.py +371 -0
- package/skills/video-resource-access/SKILL.md +35 -0
- package/skills/video-resource-access/online.enabled +1 -0
- package/skills/video-resource-access/scripts/asset_client.py +159 -0
- package/skills/video-resource-access/scripts/remote_library.py +50 -0
- package//345/256/211/350/243/205/350/257/264/346/230/216.txt +5 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// 运动量条:一次检查量三件事。任何渲染器输出的 MP4 都能检查,不需要适配器。
|
|
4
|
+
// 1. 逐帧静止:按 30fps 取样,统计每一帧相对上一帧有多少比例的像素明显变化;变化像素少于 0.5% 的帧记为“几乎不动”。
|
|
5
|
+
// 2. 构图多久没变:按 10fps 取样,缩到 32×18 灰度;从一段的第一帧算起,变化超过 8/255 的格子不到 3%,就算构图还没变。
|
|
6
|
+
// 粒子闪烁、细线生长、小令牌移动在 32×18 下会被平均掉,“一张图加小动作”过不了这一项。
|
|
7
|
+
// 3. 一帧换场:某一帧突然大变(变化像素至少 5%,又是前后各 4 帧中位数的 4 倍以上),就把它和上一帧缩到 240×136 灰度比轮廓;
|
|
8
|
+
// 上一帧的轮廓留到这一帧不到 30%,说明整个画面一帧之内换掉了,也就是硬切或一下清场。
|
|
9
|
+
// 同一章里连着讲的内容要连着做;只有章与章之间或用户确认的断点能用 --cut 登记。
|
|
10
|
+
//
|
|
11
|
+
// 判断线按用户认可片标定(2026-11-08):
|
|
12
|
+
// 逐帧静止(480×270 灰度,像素差 >6/255):第08期认可的 8 段几乎不动 18–43%,最长连续 1.1–1.8 秒;
|
|
13
|
+
// 被否的单对象测试(2026-11-07)60%,最长连续 3.27 秒。
|
|
14
|
+
// 构图:第08期各段和第五期标杆共 7 段,构图 2 秒以上没变的时间占 0–11%,单次最长 1.0–2.9 秒;
|
|
15
|
+
// 2026-11-07 被否的两版 28–35%;2026-11-08 中途停止的两次测试 81–100%(单次 4.5 秒、7.5 秒)。
|
|
16
|
+
// 一帧换场(2026-11-10):被否的第 03 题 Codex 版有 3 处整场换场,上一帧的轮廓只留下 2–13%;
|
|
17
|
+
// 认可片里的一帧大变(窗口里换内容、录屏放大、插片自带的动作)都留下 60% 以上;
|
|
18
|
+
// 第08期 D02–D07 和满意的第 01、02 题都没有整场换场。第08期开场接欢迎卡那一切只留下 8%,属于章节交界,要登记。
|
|
19
|
+
// 旧的 freezedetect −55dB 只能发现完全冻结;粒子微闪、装饰细动就能让它判“通过”,所以不再作为门禁。
|
|
20
|
+
import fs from 'node:fs';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
import {spawnSync} from 'node:child_process';
|
|
23
|
+
import {fileURLToPath} from 'node:url';
|
|
24
|
+
|
|
25
|
+
export const STILLNESS_DEFAULTS = Object.freeze({
|
|
26
|
+
sampleFps: 30,
|
|
27
|
+
width: 480,
|
|
28
|
+
height: 270,
|
|
29
|
+
pixelDelta: 6, // 灰度差超过 6/255 才算这个像素在变
|
|
30
|
+
stillAreaPct: 0.5, // 变化像素少于画面 0.5%:这一帧几乎不动
|
|
31
|
+
ratioMax: 0.5, // 读字窗口之外,几乎不动的帧超过一半:未通过
|
|
32
|
+
segmentMaxSec: 2.0, // 读字窗口之外,连续几乎不动超过 2 秒:未通过
|
|
33
|
+
reviewSegmentSec: 1.5, // 连续几乎不动超过 1.5 秒:要查(第08期“主对象 1.5 秒没变化就要查”)
|
|
34
|
+
compFps: 10, // 构图取样帧率
|
|
35
|
+
compWidth: 32, // 构图取样的格子数(横)
|
|
36
|
+
compHeight: 18, // 构图取样的格子数(竖)
|
|
37
|
+
compCellDelta: 8, // 一格灰度差超过 8/255 才算这一格变了
|
|
38
|
+
compCellFrac: 0.03, // 变了的格子达到 3%:构图变了,从这一帧重新计时
|
|
39
|
+
compHoldSec: 2.0, // 构图超过 2 秒没变,记一次“长时间没变”
|
|
40
|
+
compShareMax: 0.2, // 读字窗口之外,长时间没变的时间超过两成:未通过
|
|
41
|
+
compSegmentMaxSec: 4.0, // 读字窗口之外,单次构图超过 4 秒没变:未通过
|
|
42
|
+
cutChangePct: 5, // 一帧换场的候选:这一帧变化像素至少 5%
|
|
43
|
+
cutSpikeRatio: 4, // 而且是前后各 4 帧变化中位数(加 0.5%)的 4 倍以上
|
|
44
|
+
cutMaxCandidates: 60, // 候选太多时只比变化最大的 60 帧
|
|
45
|
+
cutWidth: 240, // 比轮廓时缩到 240×136 灰度
|
|
46
|
+
cutHeight: 136,
|
|
47
|
+
cutEdgeDelta: 16, // 相邻像素灰度差超过 16/255 记为轮廓
|
|
48
|
+
cutBottomBand: 0.15, // 底部 15% 是字幕区,不比轮廓
|
|
49
|
+
cutKeptMax: 0.3, // 上一帧的轮廓留到这一帧不到 30%:整个画面一帧之内换掉了,未通过(登记过的切点除外)
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const round = (n, d = 3) => Math.round(n * 10 ** d) / 10 ** d;
|
|
53
|
+
|
|
54
|
+
// 原片帧率。低于取样帧率时按原片帧率取样,避免补出的重复帧被当成“几乎不动”。
|
|
55
|
+
function sourceFps(video, ffmpeg) {
|
|
56
|
+
const r = spawnSync(ffmpeg, ['-hide_banner', '-i', video], {encoding: 'utf8', maxBuffer: 4 * 1024 * 1024});
|
|
57
|
+
const m = String(r.stderr || '').match(/Stream #\d+:\d+[^\n]*Video:[^\n]*?([\d.]+) fps/);
|
|
58
|
+
return m ? Number(m[1]) : null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const ffmpegError = r => {
|
|
62
|
+
if (r.error) return new Error(`无法运行 FFmpeg:${r.error.message}`);
|
|
63
|
+
return new Error(`FFmpeg 退出码 ${r.status}:${String(r.stderr).split(/\r?\n/).filter(Boolean).slice(-3).join(' | ')}`);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// 构图取样:按 10fps 取帧,缩到 32×18 灰度,每帧 576 个格子。
|
|
67
|
+
export function measureComposition(video, {ffmpeg = 'ffmpeg', gates = STILLNESS_DEFAULTS} = {}) {
|
|
68
|
+
const g = {...STILLNESS_DEFAULTS, ...gates};
|
|
69
|
+
const vf = `fps=${g.compFps},scale=${g.compWidth}:${g.compHeight}:flags=area,format=gray`;
|
|
70
|
+
const r = spawnSync(ffmpeg, ['-hide_banner', '-nostats', '-v', 'error', '-i', video, '-map', '0:v:0', '-an', '-vf', vf, '-f', 'rawvideo', 'pipe:1'],
|
|
71
|
+
{maxBuffer: 64 * 1024 * 1024});
|
|
72
|
+
if (r.error || r.status !== 0) throw ffmpegError(r);
|
|
73
|
+
const n = g.compWidth * g.compHeight, frames = [];
|
|
74
|
+
for (let o = 0; o + n <= r.stdout.length; o += n) frames.push(r.stdout.subarray(o, o + n));
|
|
75
|
+
if (!frames.length) throw new Error('没有取到构图数据。');
|
|
76
|
+
return {fps: g.compFps, width: g.compWidth, height: g.compHeight, frames};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 用 FFmpeg 滤镜链完成:相邻帧求差 → 二值化 → 求平均。返回 area[i] 为第 i 帧相对 i−1 帧的变化像素百分比,area[0]=0;
|
|
80
|
+
// comp 为构图取样,两项一起交给 scoreStillness。
|
|
81
|
+
export function measureStillness(video, {ffmpeg = 'ffmpeg', gates = STILLNESS_DEFAULTS} = {}) {
|
|
82
|
+
const g = {...STILLNESS_DEFAULTS, ...gates};
|
|
83
|
+
const native = sourceFps(video, ffmpeg);
|
|
84
|
+
const fps = native && native > 0 ? Math.min(g.sampleFps, native) : g.sampleFps;
|
|
85
|
+
const vf = [
|
|
86
|
+
`fps=${fps}`, `scale=${g.width}:${g.height}:flags=area`, 'format=gray',
|
|
87
|
+
'tblend=all_mode=difference', `lut=y='if(gt(val\\,${g.pixelDelta})\\,255\\,0)'`,
|
|
88
|
+
'signalstats', 'metadata=print:key=lavfi.signalstats.YAVG:file=-',
|
|
89
|
+
].join(',');
|
|
90
|
+
const r = spawnSync(ffmpeg, ['-hide_banner', '-nostats', '-i', video, '-map', '0:v:0', '-an', '-vf', vf, '-f', 'null', '-'],
|
|
91
|
+
{encoding: 'utf8', maxBuffer: 64 * 1024 * 1024});
|
|
92
|
+
if (r.error || r.status !== 0) throw ffmpegError(r);
|
|
93
|
+
const values = [...String(r.stdout).matchAll(/lavfi\.signalstats\.YAVG=([0-9.]+)/g)].map(m => Number(m[1]) / 255 * 100);
|
|
94
|
+
if (!values.length) throw new Error('没有取到逐帧变化数据。');
|
|
95
|
+
const area = [0, ...values];
|
|
96
|
+
const comp = measureComposition(video, {ffmpeg, gates: g});
|
|
97
|
+
const cuts = measureCuts(video, {area, fps, ffmpeg, gates: g});
|
|
98
|
+
return {fps, area, comp, cuts, duration: area.length / fps, method: {...g, sampleFps: fps, sourceFps: native}};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const median = a => {
|
|
102
|
+
if (!a.length) return 0;
|
|
103
|
+
const s = [...a].sort((x, y) => x - y), m = s.length >> 1;
|
|
104
|
+
return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// 一帧换场的候选:这一帧的变化面积比前后各 4 帧都大很多。持续的快速运动(甩镜、推拉)前后也在大变,不会成为候选。
|
|
108
|
+
export function cutCandidates(area, gates = STILLNESS_DEFAULTS) {
|
|
109
|
+
const g = {...STILLNESS_DEFAULTS, ...gates}, out = [];
|
|
110
|
+
for (let i = 1; i < area.length; i++) {
|
|
111
|
+
const near = [...area.slice(Math.max(1, i - 4), i), ...area.slice(i + 1, i + 5)];
|
|
112
|
+
if (area[i] >= g.cutChangePct && area[i] >= g.cutSpikeRatio * (median(near) + 0.5)) out.push(i);
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 上一帧的轮廓有多少留到这一帧(允许 1 像素偏移),不看底部字幕带。上一帧几乎没有轮廓时记为全部留下:没有东西可丢。
|
|
118
|
+
export function keptStructure(prev, next, {width, height, edgeDelta = STILLNESS_DEFAULTS.cutEdgeDelta, bottomBand = STILLNESS_DEFAULTS.cutBottomBand}) {
|
|
119
|
+
const rows = Math.max(2, Math.floor(height * (1 - bottomBand)));
|
|
120
|
+
const edges = f => {
|
|
121
|
+
const e = new Uint8Array(width * rows);
|
|
122
|
+
for (let y = 0; y < rows; y++) for (let x = 0; x < width; x++) {
|
|
123
|
+
const o = y * width + x, v = f[o];
|
|
124
|
+
if ((x + 1 < width && Math.abs(f[o + 1] - v) > edgeDelta) || (y + 1 < rows && Math.abs(f[o + width] - v) > edgeDelta)) e[o] = 1;
|
|
125
|
+
}
|
|
126
|
+
return e;
|
|
127
|
+
};
|
|
128
|
+
const a = edges(prev), b = edges(next);
|
|
129
|
+
let total = 0, kept = 0;
|
|
130
|
+
for (let y = 0; y < rows; y++) for (let x = 0; x < width; x++) {
|
|
131
|
+
const o = y * width + x;
|
|
132
|
+
if (!a[o]) continue;
|
|
133
|
+
total++;
|
|
134
|
+
if (b[o] || (x > 0 && b[o - 1]) || (x + 1 < width && b[o + 1]) || (y > 0 && b[o - width]) || (y + 1 < rows && b[o + width])) kept++;
|
|
135
|
+
}
|
|
136
|
+
return total < width * rows * 0.002 ? 1 : kept / total;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 一帧换场:只取候选帧和它们的上一帧(同样按 fps 取样),比轮廓留下多少。
|
|
140
|
+
export function measureCuts(video, {area, fps, ffmpeg = 'ffmpeg', gates = STILLNESS_DEFAULTS}) {
|
|
141
|
+
const g = {...STILLNESS_DEFAULTS, ...gates};
|
|
142
|
+
const picked = cutCandidates(area, g).sort((a, b) => area[b] - area[a]).slice(0, g.cutMaxCandidates).sort((a, b) => a - b);
|
|
143
|
+
if (!picked.length) return [];
|
|
144
|
+
const want = [...new Set(picked.flatMap(i => [i - 1, i]))].sort((a, b) => a - b);
|
|
145
|
+
const vf = `fps=${fps},scale=${g.cutWidth}:${g.cutHeight}:flags=area,format=gray,select='${want.map(n => `eq(n\\,${n})`).join('+')}'`;
|
|
146
|
+
const run = sync => spawnSync(ffmpeg, ['-hide_banner', '-nostats', '-v', 'error', '-i', video, '-map', '0:v:0', '-an', '-vf', vf, ...sync, '-f', 'rawvideo', 'pipe:1'],
|
|
147
|
+
{maxBuffer: 64 * 1024 * 1024});
|
|
148
|
+
let r = run(['-fps_mode', 'passthrough']);
|
|
149
|
+
if (r.status !== 0 && /fps_mode/.test(String(r.stderr))) r = run(['-vsync', 'passthrough']); // 旧版 FFmpeg
|
|
150
|
+
if (r.error || r.status !== 0) throw ffmpegError(r);
|
|
151
|
+
const n = g.cutWidth * g.cutHeight, frames = new Map();
|
|
152
|
+
want.forEach((idx, k) => { if ((k + 1) * n <= r.stdout.length) frames.set(idx, r.stdout.subarray(k * n, (k + 1) * n)); });
|
|
153
|
+
return picked.filter(i => frames.has(i - 1) && frames.has(i)).map(i => ({
|
|
154
|
+
t: round(i / fps), changedPct: round(area[i], 1),
|
|
155
|
+
keptPct: Math.round(100 * keptStructure(frames.get(i - 1), frames.get(i), {width: g.cutWidth, height: g.cutHeight, edgeDelta: g.cutEdgeDelta, bottomBand: g.cutBottomBand})),
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// 只保留轮廓留下不到 cutKeptMax 的候选,并标出哪些已登记为章节切点(允许差 2 帧)。
|
|
160
|
+
function scoreCuts(cuts, allowedCuts, fps, g) {
|
|
161
|
+
const list = cuts.filter(c => c.keptPct < g.cutKeptMax * 100)
|
|
162
|
+
.map(c => ({...c, registered: allowedCuts.some(t => Math.abs(t - c.t) <= 2 / fps + 1e-9)}));
|
|
163
|
+
const reasons = list.filter(c => !c.registered).map(c => `${c.t} 秒一帧换场:上一帧的画面只留下 ${c.keptPct}%。同一章里连着讲的内容要连着做,用镜头移动或物体变化过渡,前面的东西留下来当后面的起点;只有章与章之间或用户确认的断点才登记为切点。`);
|
|
164
|
+
return {list, reasons};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// 构图分段:从一段的第一帧算起,变了的格子达到 compCellFrac 就结束这一段,从这一帧重新计时。
|
|
168
|
+
// 读字窗口和登记的例外里的帧不计,并把前后分成两段。
|
|
169
|
+
function compositionRuns({frames, fps}, exempt, g) {
|
|
170
|
+
const runs = [];
|
|
171
|
+
let anchor = null, start = -1, counted = 0;
|
|
172
|
+
const close = i => { if (start >= 0) runs.push({start: round(start / fps), end: round(i / fps), duration: round((i - start) / fps)}); start = -1; anchor = null; };
|
|
173
|
+
for (let i = 0; i < frames.length; i++) {
|
|
174
|
+
if (exempt(i / fps)) { close(i); continue; }
|
|
175
|
+
counted++;
|
|
176
|
+
const f = frames[i];
|
|
177
|
+
if (anchor) {
|
|
178
|
+
let changed = 0;
|
|
179
|
+
for (let k = 0; k < f.length; k++) if (Math.abs(f[k] - anchor[k]) > g.compCellDelta) changed++;
|
|
180
|
+
if (changed < g.compCellFrac * f.length) continue;
|
|
181
|
+
close(i);
|
|
182
|
+
}
|
|
183
|
+
anchor = f;
|
|
184
|
+
start = i;
|
|
185
|
+
}
|
|
186
|
+
close(frames.length);
|
|
187
|
+
return {runs, countedSec: counted / fps};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function scoreComposition(comp, exempt, g) {
|
|
191
|
+
const {runs, countedSec} = compositionRuns(comp, exempt, g);
|
|
192
|
+
const holds = runs.filter(r => r.duration > g.compHoldSec + 1e-9);
|
|
193
|
+
const share = countedSec ? holds.reduce((s, r) => s + r.duration, 0) / countedSec : 0;
|
|
194
|
+
const reasons = [], review = [];
|
|
195
|
+
if (share > g.compShareMax + 1e-9) reasons.push(`读字窗口之外,构图 ${g.compHoldSec} 秒以上没变的时间占 ${(share * 100).toFixed(1)}%,超过 ${(g.compShareMax * 100).toFixed(0)}%:这是一张图在放小动作,回到看点和事件改,补小动作过不了这一项。`);
|
|
196
|
+
for (const r of holds) {
|
|
197
|
+
if (r.duration > g.compSegmentMaxSec + 1e-9) reasons.push(`${r.start}–${r.end} 秒构图 ${r.duration} 秒没变,超过 ${g.compSegmentMaxSec} 秒,而且不在读字窗口里。`);
|
|
198
|
+
else review.push(`${r.start}–${r.end} 秒构图 ${r.duration} 秒没变:不是读字就换构图或取景。`);
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
reasons, review,
|
|
202
|
+
measured: {
|
|
203
|
+
holdShare: round(share, 4), longestHoldSec: round(runs.reduce((m, r) => Math.max(m, r.duration), 0)), holds, countedSec: round(countedSec),
|
|
204
|
+
method: `${comp.fps}fps 取样,${comp.width ?? g.compWidth}×${comp.height ?? g.compHeight} 灰度;从一段的第一帧算起,变化 >${g.compCellDelta}/255 的格子不到 ${g.compCellFrac * 100}% 记为构图没变`,
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// readings / exceptions:[{t0, t1}]。读字窗口和经用户确认登记的例外不计入静止和构图统计,但不豁免一帧换场。
|
|
210
|
+
// cuts:measureCuts 的结果;allowedCuts:登记的章节切点秒数。comp、cuts 缺省时不判这两项(单元测试用);实际检查由 measureStillness 一并取样。
|
|
211
|
+
export function scoreStillness({area, fps = 30, comp = null, cuts = null, allowedCuts = [], readings = [], exceptions = [], gates = STILLNESS_DEFAULTS}) {
|
|
212
|
+
const g = {...STILLNESS_DEFAULTS, ...gates};
|
|
213
|
+
if (!Array.isArray(area) || area.length < 2) return {status: '无法测量', reasons: ['没有逐帧变化数据。'], review: [], measured: {}};
|
|
214
|
+
const windows = [...readings, ...exceptions].filter(w => w && Number.isFinite(w.t0) && Number.isFinite(w.t1) && w.t1 > w.t0 && w.valid !== false);
|
|
215
|
+
const exempt = t => windows.some(w => t > w.t0 + 1e-9 && t <= w.t1 + 1e-9);
|
|
216
|
+
let counted = 0, still = 0, run = 0, runStart = 0;
|
|
217
|
+
const runs = [];
|
|
218
|
+
const close = i => { if (run) runs.push({start: round(runStart / fps), end: round(i / fps), duration: round(run / fps)}); run = 0; };
|
|
219
|
+
for (let i = 1; i < area.length; i++) {
|
|
220
|
+
const t = i / fps;
|
|
221
|
+
if (exempt(t)) { close(i - 1); continue; }
|
|
222
|
+
counted++;
|
|
223
|
+
if (area[i] < g.stillAreaPct) { still++; if (!run) runStart = i - 1; run++; }
|
|
224
|
+
else close(i - 1);
|
|
225
|
+
}
|
|
226
|
+
close(area.length - 1);
|
|
227
|
+
const ratio = counted ? still / counted : 0;
|
|
228
|
+
const longest = runs.reduce((m, r) => Math.max(m, r.duration), 0);
|
|
229
|
+
const reasons = [];
|
|
230
|
+
if (ratio > g.ratioMax + 1e-9) reasons.push(`读字窗口之外,几乎不动的帧占 ${(ratio * 100).toFixed(1)}%,超过 ${(g.ratioMax * 100).toFixed(0)}%。`);
|
|
231
|
+
for (const r of runs.filter(r => r.duration > g.segmentMaxSec + 1e-9)) reasons.push(`${r.start}–${r.end} 秒连续 ${r.duration} 秒几乎不动,超过 ${g.segmentMaxSec} 秒,而且不在读字窗口里。`);
|
|
232
|
+
const review = runs.filter(r => r.duration > g.reviewSegmentSec + 1e-9 && r.duration <= g.segmentMaxSec + 1e-9)
|
|
233
|
+
.map(r => `${r.start}–${r.end} 秒连续 ${r.duration} 秒几乎不动:确认这里主对象确实不需要变化。`);
|
|
234
|
+
const composition = comp?.frames?.length ? scoreComposition(comp, exempt, g) : null;
|
|
235
|
+
if (composition) { reasons.push(...composition.reasons); review.push(...composition.review); }
|
|
236
|
+
const cutScore = Array.isArray(cuts) ? scoreCuts(cuts, allowedCuts, fps, g) : null;
|
|
237
|
+
if (cutScore) reasons.push(...cutScore.reasons);
|
|
238
|
+
return {
|
|
239
|
+
status: reasons.length ? '未通过' : '通过',
|
|
240
|
+
judgment: 'hard-gate',
|
|
241
|
+
reasons,
|
|
242
|
+
review,
|
|
243
|
+
measured: {
|
|
244
|
+
ratio: round(ratio, 4), longestSec: round(longest), countedFrames: counted, exemptFrames: area.length - 1 - counted,
|
|
245
|
+
stillRuns: runs.filter(r => r.duration >= 0.5), exemptWindows: windows.map(w => ({t0: w.t0, t1: w.t1})),
|
|
246
|
+
method: `${fps}fps 取样,${g.width}×${g.height} 灰度,像素差 >${g.pixelDelta}/255,变化面积 <${g.stillAreaPct}% 记为几乎不动`,
|
|
247
|
+
composition: composition ? composition.measured : null,
|
|
248
|
+
cuts: cutScore ? cutScore.list : null,
|
|
249
|
+
cutMethod: cutScore ? `变化像素 ≥${g.cutChangePct}% 且是前后各 4 帧中位数的 ${g.cutSpikeRatio} 倍以上的帧,缩到 ${g.cutWidth}×${g.cutHeight} 灰度比轮廓(相邻差 >${g.cutEdgeDelta}/255,不看底部 ${g.cutBottomBand * 100}%);上一帧轮廓留下不到 ${g.cutKeptMax * 100}% 记为一帧换场` : null,
|
|
250
|
+
registeredCuts: allowedCuts,
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const compText = c => c ? `;构图 2 秒以上没变 ${(c.holdShare * 100).toFixed(0)}%,最长 ${c.longestHoldSec} 秒` : '';
|
|
256
|
+
const cutText = cuts => Array.isArray(cuts) ? `;一帧换场 ${cuts.length} 处${cuts.some(c => c.registered) ? `(登记过的 ${cuts.filter(c => c.registered).length} 处)` : ''}` : '';
|
|
257
|
+
|
|
258
|
+
// 运动量条:每一帧变化面积画成一根柱子,紫线标出构图 2 秒以上没变的时段。可同时画一段对标片做对照。
|
|
259
|
+
export function stillnessSvg({area, fps = 30, comp = null, cuts = null, allowedCuts = [], readings = [], title = '本片', benchmark = null, gates = STILLNESS_DEFAULTS}) {
|
|
260
|
+
const g = {...STILLNESS_DEFAULTS, ...gates};
|
|
261
|
+
const rows = [{title, area, comp, readings, cuts, allowedCuts}];
|
|
262
|
+
if (benchmark?.area?.length) rows.push({title: benchmark.title || '对标片', area: benchmark.area.slice(0, area.length), readings: [], composition: benchmark.composition});
|
|
263
|
+
const seconds = (area.length - 1) / fps, W = 1200, rowH = 150, pad = 46, cap = 12;
|
|
264
|
+
const x = t => pad + (W - pad - 20) * Math.min(t, seconds) / Math.max(seconds, 1e-6);
|
|
265
|
+
const esc = s => String(s).replace(/[&<>"]/g, c => ({'&': '&', '<': '<', '>': '>', '"': '"'}[c]));
|
|
266
|
+
let body = '';
|
|
267
|
+
rows.forEach((row, k) => {
|
|
268
|
+
const y0 = 30 + k * (rowH + 50), h = rowH;
|
|
269
|
+
const scored = scoreStillness({area: row.area, fps, comp: row.comp, cuts: row.cuts ?? null, allowedCuts: row.allowedCuts ?? [], readings: row.readings, gates: g});
|
|
270
|
+
const c = row.comp ? scored.measured.composition : row.composition;
|
|
271
|
+
body += `<text x="${pad}" y="${y0 - 8}" font-size="15" fill="#222">${esc(row.title)}:几乎不动 ${(scored.measured.ratio * 100).toFixed(0)}%,最长连续 ${scored.measured.longestSec} 秒${compText(c)}${cutText(scored.measured.cuts)}</text>`;
|
|
272
|
+
body += `<rect x="${pad}" y="${y0}" width="${W - pad - 20}" height="${h}" fill="#fafafa" stroke="#ccc"/>`;
|
|
273
|
+
for (const w of row.readings) body += `<rect x="${x(w.t0)}" y="${y0}" width="${Math.max(1, x(w.t1) - x(w.t0))}" height="${h}" fill="#e8f2e8"/>`;
|
|
274
|
+
const bw = Math.max(1, (W - pad - 20) / Math.max(1, row.area.length - 1));
|
|
275
|
+
for (let i = 1; i < row.area.length; i++) {
|
|
276
|
+
const v = Math.min(row.area[i], cap) / cap, still = row.area[i] < g.stillAreaPct;
|
|
277
|
+
body += `<rect x="${x((i - 1) / fps).toFixed(1)}" y="${(y0 + h - v * h).toFixed(1)}" width="${bw.toFixed(2)}" height="${(v * h).toFixed(1)}" fill="${k ? '#c8742c' : '#3a6fbe'}"/>`;
|
|
278
|
+
if (still) body += `<rect x="${x((i - 1) / fps).toFixed(1)}" y="${y0 + h + 2}" width="${bw.toFixed(2)}" height="4" fill="#d33"/>`;
|
|
279
|
+
}
|
|
280
|
+
for (const hold of (c?.holds ?? []).filter(h => h.start < seconds)) body += `<rect x="${x(hold.start).toFixed(1)}" y="${y0 + h + 8}" width="${Math.max(1, x(hold.end) - x(hold.start)).toFixed(1)}" height="4" fill="#8a4fbf"/>`;
|
|
281
|
+
for (const cut of scored.measured.cuts ?? []) body += `<rect x="${(x(cut.t) - 1).toFixed(1)}" y="${y0}" width="2" height="${h}" fill="${cut.registered ? '#999' : '#111'}"/>`;
|
|
282
|
+
for (let s = 0; s <= Math.floor(seconds); s++) body += `<text x="${x(s) - 4}" y="${y0 + h + 24}" font-size="11" fill="#666">${s}s</text>`;
|
|
283
|
+
});
|
|
284
|
+
const H = 30 + rows.length * (rowH + 50) + 10;
|
|
285
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}" font-family="Microsoft YaHei, sans-serif">`
|
|
286
|
+
+ `<rect width="${W}" height="${H}" fill="#fff"/>${body}`
|
|
287
|
+
+ `<text x="${pad}" y="${H - 4}" font-size="11" fill="#666">柱高=这一帧画面在变的比例(封顶 ${cap}%);红线=几乎不动的帧;紫线=构图 2 秒以上没变;黑竖线=一帧换场(灰=登记过的章节切点);浅绿底=登记的读字窗口</text></svg>`;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// 同一张运动量条的 PNG 版(不依赖额外库,用 FFmpeg 编码),方便只能看位图的执行者自查。
|
|
291
|
+
// 蓝柱=本片,橙柱=对标片,红线=几乎不动的帧,紫线=构图 2 秒以上没变,黑竖线=一帧换场(灰=登记过的章节切点),浅绿底=读字窗口,灰线=每秒刻度。
|
|
292
|
+
export function stillnessPng({area, fps = 30, comp = null, cuts = null, allowedCuts = [], readings = [], benchmark = null, file, ffmpeg = 'ffmpeg', gates = STILLNESS_DEFAULTS}) {
|
|
293
|
+
const g = {...STILLNESS_DEFAULTS, ...gates};
|
|
294
|
+
const ownScore = scoreStillness({area, fps, comp, cuts, allowedCuts, readings, gates: g}).measured;
|
|
295
|
+
const own = comp?.frames?.length ? ownScore.composition : null;
|
|
296
|
+
const rows = [{area, readings, holds: own?.holds ?? [], cuts: ownScore.cuts ?? [], color: [58, 111, 190]}];
|
|
297
|
+
if (benchmark?.area?.length) rows.push({area: benchmark.area.slice(0, area.length), readings: [], holds: benchmark.composition?.holds ?? [], cuts: [], color: [200, 116, 44]});
|
|
298
|
+
const W = 1200, rowH = 150, gap = 24, H = rows.length * (rowH + gap) + gap, buf = Buffer.alloc(W * H * 3, 255);
|
|
299
|
+
const put = (x, y, [r, gg, b]) => { if (x < 0 || y < 0 || x >= W || y >= H) return; const o = (y * W + x) * 3; buf[o] = r; buf[o + 1] = gg; buf[o + 2] = b; };
|
|
300
|
+
const fill = (x0, y0, x1, y1, c) => { for (let y = Math.max(0, y0 | 0); y < Math.min(H, y1 | 0); y++) for (let x = Math.max(0, x0 | 0); x < Math.min(W, x1 | 0); x++) put(x, y, c); };
|
|
301
|
+
const seconds = Math.max((area.length - 1) / fps, 1e-6), x = t => 10 + (W - 20) * Math.min(t, seconds) / seconds, cap = 12;
|
|
302
|
+
rows.forEach((row, k) => {
|
|
303
|
+
const y0 = gap + k * (rowH + gap);
|
|
304
|
+
fill(10, y0, W - 10, y0 + rowH, [248, 248, 248]);
|
|
305
|
+
for (const w of row.readings) fill(x(w.t0), y0, x(w.t1) + 1, y0 + rowH, [226, 241, 226]);
|
|
306
|
+
for (let s = 0; s <= Math.floor(seconds); s++) fill(x(s), y0, x(s) + 1, y0 + rowH, [215, 215, 215]);
|
|
307
|
+
for (let i = 1; i < row.area.length; i++) {
|
|
308
|
+
const v = Math.min(row.area[i], cap) / cap, xa = x((i - 1) / fps), xb = Math.max(xa + 1, x(i / fps));
|
|
309
|
+
fill(xa, y0 + rowH - v * rowH, xb, y0 + rowH, row.color);
|
|
310
|
+
if (row.area[i] < g.stillAreaPct) fill(xa, y0 + rowH + 3, xb, y0 + rowH + 9, [210, 40, 40]);
|
|
311
|
+
}
|
|
312
|
+
for (const hold of row.holds.filter(h => h.start < seconds)) fill(x(hold.start), y0 + rowH + 11, Math.max(x(hold.start) + 1, x(hold.end)), y0 + rowH + 17, [138, 79, 191]);
|
|
313
|
+
for (const cut of row.cuts) fill(x(cut.t) - 1, y0, x(cut.t) + 2, y0 + rowH, cut.registered ? [150, 150, 150] : [20, 20, 20]);
|
|
314
|
+
});
|
|
315
|
+
const r = spawnSync(ffmpeg, ['-v', 'error', '-y', '-f', 'rawvideo', '-pix_fmt', 'rgb24', '-s', `${W}x${H}`, '-i', '-', '-frames:v', '1', file], {input: buf});
|
|
316
|
+
if (r.status !== 0) throw new Error(`运动量条 PNG 编码失败:${String(r.stderr).slice(0, 200)}`);
|
|
317
|
+
return file;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function parseWindows(text) {
|
|
321
|
+
if (!text) return [];
|
|
322
|
+
return String(text).split(',').filter(Boolean).map(part => {
|
|
323
|
+
const [a, b] = part.split(':').map(Number);
|
|
324
|
+
if (!Number.isFinite(a) || !Number.isFinite(b) || b <= a) throw new Error(`读字窗口格式应为 起秒:止秒,收到 ${part}`);
|
|
325
|
+
return {t0: a, t1: b};
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function parseTimes(text) {
|
|
330
|
+
if (!text) return [];
|
|
331
|
+
return String(text).split(',').filter(Boolean).map(part => {
|
|
332
|
+
const t = Number(part);
|
|
333
|
+
if (!Number.isFinite(t) || t < 0) throw new Error(`切点格式应为 秒,秒,收到 ${part}`);
|
|
334
|
+
return t;
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export function loadBenchmark(name, root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')) {
|
|
339
|
+
if (!name) return null;
|
|
340
|
+
const file = fs.existsSync(name) ? name : path.join(root, 'assets', 'motion', 'benchmarks', 'stillness-profiles.json');
|
|
341
|
+
const data = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
342
|
+
if (Array.isArray(data.area)) return data;
|
|
343
|
+
const hit = (data.profiles || []).find(p => p.id === name);
|
|
344
|
+
if (!hit) throw new Error(`没有名为 ${name} 的对标曲线;可选:${(data.profiles || []).map(p => p.id).join('、')}`);
|
|
345
|
+
return hit;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const HELP = `node scripts/stillness.mjs --video <preview.mp4> --out <新的输出目录> [--reading 起秒:止秒,…] [--cut 秒,…] [--benchmark ep08-d07-v04|ep05-d03-b-v4|<曲线.json>] [--ffmpeg ffmpeg]
|
|
349
|
+
同时量逐帧静止、构图多久没变和一帧换场。输出 stillness.json,以及运动量条 stillness.png/stillness.svg(加 --benchmark 时同图对照)。退出码:0 通过;2 未通过;1 无法测量或参数错误。
|
|
350
|
+
读字窗口只登记画面上真有字要读的时段,每秒约 5 个字、至少 1 秒;“方便比较”不算读字。构图项未通过时回到看点和事件改,补小动作过不了。
|
|
351
|
+
--cut 只登记章与章之间或用户确认的断点;同一章里的一帧换场要改成连续过渡,不能靠登记放行。`;
|
|
352
|
+
|
|
353
|
+
export function main(argv = process.argv.slice(2)) {
|
|
354
|
+
const args = {};
|
|
355
|
+
for (let i = 0; i < argv.length; i++) {
|
|
356
|
+
const k = argv[i];
|
|
357
|
+
if (k === '--help' || k === '-h') { console.log(HELP); return 0; }
|
|
358
|
+
if (!k.startsWith('--')) throw new Error(`无法识别参数 ${k}\n${HELP}`);
|
|
359
|
+
args[k.slice(2)] = argv[++i];
|
|
360
|
+
}
|
|
361
|
+
if (!args.video || !args.out) { console.error(HELP); return 1; }
|
|
362
|
+
if (fs.existsSync(args.out) && fs.readdirSync(args.out).length) { console.error(`输出目录已存在且不为空,拒绝覆盖:${args.out}`); return 1; }
|
|
363
|
+
let measured;
|
|
364
|
+
try { measured = measureStillness(args.video, {ffmpeg: args.ffmpeg || 'ffmpeg'}); }
|
|
365
|
+
catch (err) { console.error(String(err.message || err)); return 1; }
|
|
366
|
+
const readings = parseWindows(args.reading);
|
|
367
|
+
const allowedCuts = parseTimes(args.cut);
|
|
368
|
+
const result = scoreStillness({area: measured.area, fps: measured.fps, comp: measured.comp, cuts: measured.cuts, allowedCuts, readings});
|
|
369
|
+
const benchmark = loadBenchmark(args.benchmark);
|
|
370
|
+
fs.mkdirSync(args.out, {recursive: true});
|
|
371
|
+
const report = {
|
|
372
|
+
video: path.resolve(args.video), duration: round(measured.duration), ...result,
|
|
373
|
+
benchmark: benchmark ? {id: benchmark.id, title: benchmark.title, ratio: benchmark.stats?.ratio, longestSec: benchmark.stats?.longestSec,
|
|
374
|
+
compositionHoldShare: benchmark.composition?.holdShare ?? null, compositionLongestHoldSec: benchmark.composition?.longestHoldSec ?? null} : null,
|
|
375
|
+
area: measured.area.map(v => round(v, 3)),
|
|
376
|
+
};
|
|
377
|
+
fs.writeFileSync(path.join(args.out, 'stillness.json'), JSON.stringify(report, null, 2));
|
|
378
|
+
fs.writeFileSync(path.join(args.out, 'stillness.svg'), stillnessSvg({area: measured.area, fps: measured.fps, comp: measured.comp, cuts: measured.cuts, allowedCuts, readings, title: path.basename(args.video), benchmark}));
|
|
379
|
+
stillnessPng({area: measured.area, fps: measured.fps, comp: measured.comp, cuts: measured.cuts, allowedCuts, readings, benchmark, file: path.join(args.out, 'stillness.png'), ffmpeg: args.ffmpeg || 'ffmpeg'});
|
|
380
|
+
console.log(`${result.status}:几乎不动 ${(result.measured.ratio * 100).toFixed(1)}%,最长连续 ${result.measured.longestSec} 秒${compText(result.measured.composition)}${cutText(result.measured.cuts)}。${[...result.reasons, ...result.review].join(' ')}`);
|
|
381
|
+
return result.status === '通过' ? 0 : result.status === '未通过' ? 2 : 1;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
385
|
+
try { process.exitCode = main(); } catch (err) { console.error(String(err.message || err)); process.exitCode = 1; }
|
|
386
|
+
}
|