Skip to content

Reverse-engineer any video, shot by shot: filmed, AI-generated or coded, and how to remake it. Breakdowns in the open VIDEO.md format. 逆向一切视频,逐个镜头看是拍的、AI 生成的还是代码做的,再告诉你怎么复刻;拆解结果按 VIDEO.md 格式输出。

切点检测识别跳剪、推近切和几帧的短镜头,闪光和枪口火光不算切点;复刻时生成片段整段变速对齐原镜头;评测集加逐帧标注的切点真值

juneda4ecbcdfa9b
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..daa7f72
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,37 @@
+# 更新记录
+
+## 切点检测
+
+剪辑节奏复刻靠切点。切点漏了,镜头时长、卡点、复刻时间轴都会跟着偏。这一版重写了切点判断,复刻时生成片段按整段变速对齐原镜头。
+
+**切点**
+- 跳剪 / 推近切:同机位、同背景,人物位置或景别在一帧内跳变,变化面积小,以前抓不到。现在看这一帧的变化是否远高于前后几帧,并确认前后都平稳、画面没有回到切之前。口播和手持开箱里大量这种切点。
+- 闪光、枪口火光、频闪:一两帧内变亮又恢复原样,不算切点。闪白转场褪去后露出新画面,仍算切点。
+- 挨得很近的几处边界(闪光紧挨着真切点、一帧残影、甩镜)只保留最强的一处,不再只认第一处。
+- 两刀干净硬切之间画面稳定的短镜头,最短保留 0.12 秒(快剪里的插入镜头、开头封面帧),以前不到 0.35 秒都会被并掉。
+- 短镜头里只出现一帧重复,不再当作 24fps 转制的证据,短实拍镜头不会因此被判成 AI。
+
+**复刻**
+- `assemble` 把生成片段整段变速塞进原镜头时长(最多快 3 倍、慢 1.25 倍,超出部分再裁)。生成模型有最短时长,以前只截前几秒,动作做一半就切走,节奏偏慢。
+
+**评测**
+- `eval/koubo.yaml`、`daihuo.yaml`、`film.yaml`、`articles.yaml` 给 9 条片子加了逐帧人工标注的切点真值(`cuts`),看不准的位置放在 `cuts_uncertain`,检测到也不算错。评测输出新增切点汇总(找到 / 漏掉 / 误报)。
+
+| 评测集 | 切点召回 | 切点精确率 |
+|---|---|---|
+| 口播(2 条) | 71% → 91% | 89% → 90% |
+| 带货(2 条) | 44% → 94% | 79% → 87% |
+| 影视混剪(4 条) | 93% → 98% | 93% → 98% |
+| 手机实拍带货(1 条) | 83% → 92% | 100% → 100% |
+| 合计 | 79% → 95% | 91% → 94% |
+
+制作方式准确率:labels / holdout / holdout2 为 100% → 99.2% / 99.5% → 99.7% / 100% → 100%。
+
+**速度和消耗**
+- 切点判断本身几乎不变:13 分钟视频多 0.1 秒。
+- 拆解时间随镜头数增加,每多一个镜头约多 1.5–2 秒(逐镜 OCR、采样、特征)。评测集整体镜头数多了 14%。以前漏切少的片子基本不变(166 秒口播:224 → 229 秒);跳剪密集、以前大量漏切的片子变化最大(72 秒开箱:镜头 29 → 68,100 → 173 秒)。
+- 开 VLM 时每个镜头调用一次,调用次数随镜头数增加,每条视频最多 60 个镜头。
+
+**已知局限**
+- 手机录屏里的界面滑动、翻页动画仍会被当成切点。
+- 切得更细后,暗光口播叠截图、3D 毛绒角色的短镜头有时会判错制作方式。
diff --git a/eval/articles.yaml b/eval/articles.yaml
index 14e0801..004e7c5 100644
--- a/eval/articles.yaml
+++ b/eval/articles.yaml
@@ -3,6 +3,7 @@
# 视频文件不进仓库:放在 eval/media/articles/v01.mp4 … v13.mp4(编号对照见同目录 mapping.tsv)
# 真值 = 文章作者对制作方式的说明 + 人工看画面;v02、v05、v06 真值不确定,不列入
# 注意:v0.3 的转码/3D 规则是看过这批视频后加的,属于开发集,不是留出集
+# cuts:逐个看候选切点前后帧标出的切点真值(含跳剪、推近切、几帧的短镜头;闪光、火光、局部叠图不算);cuts_uncertain 是看不准的位置,检测到也不算错
videos:
- id: art_v01_oiioii_remake # a1 复刻成片:视频模型 + Harness
path: eval/media/articles/v01.mp4
@@ -28,6 +29,8 @@ videos:
- id: art_v11_tiktok_original # a2 TikTok 带货原片:手机实拍(真实厨房、真手、男声口播)
aspects: {format: {format: product}} # 目测 2026-10-30:第一视角手持,手拿食材放进榨汁杯,无人脸
path: eval/media/articles/v11.mp4
+ cuts: [0.73, 1.50, 2.20, 4.03, 5.77, 6.53, 7.23, 8.73, 12.97, 14.60, 18.67, 19.03]
+ cuts_uncertain: [3.27, 20.67]
label: live_action
real_material: true
- id: art_v12_juicer_remake # a2 OiiOii 榨汁杯复刻(带 AIGC 隐式标识)
diff --git a/eval/daihuo.yaml b/eval/daihuo.yaml
index 9d1c856..65131cb 100644
--- a/eval/daihuo.yaml
+++ b/eval/daihuo.yaml
@@ -1,9 +1,12 @@
# 带货评测集:实拍开箱 + 「真人出镜画面做参考的 AI 带货」教程片,抖音转码(HEVC 1080x1920 30fps)
# 视频不入库(eval/media/ 已 gitignore):用 TikHub douyin_app_v3_fetch_one_video 按 aweme_id 取 bit_rate[0] 的 1080p 地址下载到 eval/media/daihuo/
# 真值来源:人工逐镜目测(2026-11-04,按 decompose 切出的镜头逐个看联系表)+ 视频作者自述的制作流程;没有生产记录,属于目测真值。
+# cuts:逐个看候选切点前后帧标出的切点真值(含跳剪、推近切、几帧的短镜头;闪光、火光、局部叠图不算);cuts_uncertain 是看不准的位置,检测到也不算错
videos:
- id: daihuo_ai_tutorial
path: eval/media/daihuo/chenxi_ai_daihuo.mp4
+ cuts: [1.93, 4.70, 6.63, 10.07, 11.93, 16.47, 31.57, 32.93, 39.13, 44.40, 49.13, 51.50, 53.07, 54.90]
+ cuts_uncertain: [10.37]
source: 抖音 晨曦的好物铺子《AI带货新玩法,真人日用品带货视频,制作流程分享》aweme 7643393488632974633;作者口述:豆包写提示词 → 即梦 Seedance 2.0 用「提前录好的出镜画面」做主体 + 两张水杯图生成
# 1.93–6.63 和 49.13–57.67 是同一段即梦成片(右下角「即梦 @知遇」水印,礼盒英文乱码);7.93–11.93 是口播上叠商品照片的画中画版式;11.93–49.13 是相机拍真实手机屏幕(不是录屏)
segments:
@@ -19,6 +22,7 @@ videos:
- id: daihuo_unboxing
path: eval/media/daihuo/ami_unboxing.mp4
+ cuts: [0.63, 1.23, 1.83, 2.37, 3.10, 3.87, 4.53, 5.17, 5.97, 6.57, 7.30, 8.23, 10.23, 11.70, 12.47, 13.27, 14.13, 14.97, 15.63, 17.03, 17.80, 18.53, 20.57, 21.90, 22.90, 23.57, 24.33, 24.90, 25.67, 26.37, 27.13, 28.10, 28.93, 30.00, 31.20, 32.50, 33.37, 34.50, 35.10, 36.17, 36.80, 38.70, 39.93, 43.03, 44.00, 44.90, 45.47, 46.33, 47.00, 47.67, 48.63, 49.87, 50.50, 51.00, 51.60, 52.60, 53.57, 54.33, 55.23, 56.47, 57.17, 58.73, 59.43, 60.13, 61.03, 62.13, 64.07, 64.67, 66.73, 67.47, 68.87, 69.90]
source: 抖音 阿咪🍓《开箱vlog:)爽拆可爱貌美家居好物~》aweme 7696830364081218747;头顶俯拍支架 + 手机,沉浸式拆包无口播
label: live_action
real_material: true
diff --git a/eval/film.yaml b/eval/film.yaml
index 256a02a..8cdf930 100644
--- a/eval/film.yaml
+++ b/eval/film.yaml
@@ -4,15 +4,18 @@
# 真值来源:人工看联系表目测 + 视频标题和画面上的片名;没有生产记录,属于目测真值。
# 影视片段在像素上就是摄影机拍的画面,工具只给线索(黑边版式、24/25fps 源)、不下结论,
# 所以只开工具时这一组的准确率预期很低,要看「标出待确认」的比例和看图复核后的准确率。
+# cuts:逐个看候选切点前后帧标出的切点真值(含跳剪、推近切、几帧的短镜头;闪光、火光、局部叠图不算);cuts_uncertain 是看不准的位置,检测到也不算错
videos:
- id: film_hk_kungfu_beat
path: eval/media/film/hk_kungfu_beat.mp4
+ cuts: [2.07, 4.20, 5.17, 6.03, 7.07, 7.87, 8.33, 8.83, 9.27, 10.17, 11.07, 12.33, 12.73, 13.23, 15.17, 16.37, 17.70, 18.70, 19.53, 20.40, 22.20, 24.00, 24.83, 25.83, 26.77, 28.70, 29.40, 30.50, 32.00, 33.20, 34.17, 35.07, 35.93, 37.27, 37.70, 38.60, 39.57, 40.43, 40.90, 41.37, 41.77, 42.27, 42.67, 43.17, 43.90, 44.90, 45.73, 46.23, 46.77, 48.70, 49.07, 50.33, 51.83, 53.93, 54.77, 55.57, 56.60, 57.43, 58.37, 59.27, 60.07]
source: 抖音 武术指导《以武为舞,便是最好的节奏!》aweme 7615916888199007514;港片功夫打斗踩点混剪,横屏 720p 30fps
label: film_footage
real_material: true
- id: film_gunshot_beat
path: eval/media/film/gunshot_beat.mp4
+ cuts: [2.53, 3.50, 4.07, 4.30, 4.83, 5.83, 7.03, 7.70, 8.87, 9.57, 9.90, 10.40, 11.03, 12.37, 13.13, 13.53, 14.07, 15.07, 16.27, 16.97, 18.03, 19.37, 20.37, 21.73, 22.30, 22.73, 23.70, 24.40, 25.00, 25.73, 26.33, 27.37, 27.43, 29.13, 29.87, 31.13, 31.77, 32.47, 33.90, 34.47, 35.03, 36.20, 36.57, 37.10, 37.73, 39.17]
source: 抖音 可乐丶《听着很暖和,看着有点爽。数一下多少颗子弹?》aweme 7549583051311926568;欧美枪战电影枪声卡点混剪
label: film_footage
real_material: true
@@ -27,6 +30,7 @@ videos:
- id: film_tvdrama_scenes
path: eval/media/film/tvdrama_scenes.mp4
+ cuts: [2.64, 3.16, 4.16, 6.04, 7.04, 7.88, 8.92, 9.88, 10.80, 11.76, 13.04, 14.32, 14.60, 15.60, 16.84, 17.24, 18.48, 18.92, 19.64, 20.56, 21.28, 21.88, 22.92, 23.72, 24.48, 25.16, 26.04, 27.12, 27.40, 27.92, 28.92, 29.64, 30.68, 31.44, 32.28, 33.32, 34.32, 35.48, 36.16, 36.68, 37.72, 38.52, 39.32, 40.32, 41.12, 41.96, 42.68, 43.60, 44.96, 45.80, 46.40, 47.04, 47.88, 48.52, 49.00, 49.88, 51.08, 52.24, 53.40, 53.92, 54.76, 56.20, 57.36, 58.64, 59.20, 59.68, 60.40, 61.60, 62.04, 62.76, 64.12, 64.68, 65.40, 65.92, 66.72, 67.52, 68.56, 69.20, 69.88, 70.48, 71.08, 71.88, 73.00, 74.04, 76.16, 77.72, 78.88, 79.56, 80.32, 81.44, 82.24, 83.12, 83.80, 84.48, 85.52, 86.04, 86.96, 87.56, 88.20, 89.40, 90.64, 91.76, 92.52, 93.60, 95.72, 96.60, 97.08, 97.64, 98.16, 99.24, 101.20, 102.72, 103.12, 104.20]
source: 抖音 月下栖梧楼《盘点影视剧中为爱退让的名场面》aweme 7699064909601967414;国产古装/现代剧名场面合集,每段左上角标「年份 ·《剧名》」,25fps;开头 2.6 秒是黑底文字卡,中间的白闪是转场
segments:
- [0.000, 2.600, [code_render, static_hold]]
@@ -56,6 +60,7 @@ videos:
- id: film_shortdrama_recap
path: eval/media/film/shortdrama_recap.mp4
+ cuts: [1.10, 3.17, 5.27, 6.94, 8.34, 9.68, 11.78, 13.88, 15.25, 19.49, 20.82, 22.36, 24.46, 26.33, 28.06, 31.56, 32.50, 34.07, 34.90, 35.80, 36.90, 37.67, 39.51, 41.34, 43.08, 44.98, 46.75, 47.98, 49.25, 51.12, 53.89, 54.99, 59.19, 60.89, 62.26, 63.10, 64.73, 66.93, 70.40, 72.97]
source: 抖音 秋刀鱼(短剧解说)aweme 7619686582341895311;真人竖屏短剧(剧组拍摄)的解说剪辑,29.97fps
label: film_footage
real_material: true
diff --git a/eval/koubo.yaml b/eval/koubo.yaml
index 99035f0..3daf736 100644
--- a/eval/koubo.yaml
+++ b/eval/koubo.yaml
@@ -4,9 +4,12 @@
# 真值来源:人工逐镜目测(2026-10-30,按 decompose 切出的镜头逐个看首尾帧)。
# 叠了大块截图的人物镜头底层仍是实拍,截图类标签也接受;黑底文字卡是代码渲染。
# aspects:拍法/打光真值 {维度: {字段: 可接受值}},也是目测(存疑处没有标;夜景那条没标机位,因为支架拍和手持自拍都有)。
+# cuts:逐个看候选切点前后帧标出的切点真值(含跳剪、推近切、几帧的短镜头;闪光、火光、局部叠图不算);cuts_uncertain 是看不准的位置,检测到也不算错
videos:
- id: koubo_night_street
path: eval/media/chenpangyi_koubo.mp4
+ cuts: [0.13, 1.27, 4.07, 11.17, 13.10, 14.93, 17.00, 17.50, 18.03, 18.40, 19.10, 19.57, 22.23, 23.03, 24.30, 25.77, 26.87, 28.07, 30.17, 30.67, 31.10, 31.23, 33.17, 34.27, 37.33, 37.87, 40.27, 42.63, 45.27, 46.10, 47.73, 48.00, 50.10, 51.53, 59.70, 63.27, 68.30, 78.00, 78.87, 82.07, 84.13, 87.73, 89.27, 89.77, 91.23, 93.47, 96.23, 100.70, 103.97, 106.03, 107.10, 109.43, 111.20, 121.13, 129.47, 132.00, 134.57, 135.40, 136.13, 137.07, 137.77, 138.67, 140.43, 145.43, 148.47, 155.97, 156.17, 163.77, 166.07]
+ cuts_uncertain: [76.20, 79.10, 94.60, 99.57, 157.57]
source: 抖音 陈胖一《新号做出100万+播放的公式邪修!》https://v.douyin.com/U0tc1sxj1q8/ ;夜晚公交站边喝酒边讲,路灯环境光
segments:
- [0.00, 1.27, live_action]
@@ -40,6 +43,8 @@ videos:
- id: koubo_indoor_closeup
path: eval/media/chenpangyi_indoor.mp4
+ cuts: [0.13, 2.67, 4.53, 7.23, 9.03, 14.03, 18.47, 26.57, 30.53, 36.97, 43.47, 45.37, 51.17, 55.10, 71.53, 77.93, 86.03, 88.17, 92.73, 97.77, 101.97, 106.30, 109.30, 111.00, 114.07, 117.67, 122.70, 128.60, 134.20, 145.23, 152.53, 163.73, 165.03]
+ cuts_uncertain: [16.97, 69.90, 121.53, 169.43]
source: 抖音 陈胖一《改命邪修!写《人生简历》投递给AI!》https://v.douyin.com/G4wyC9YPCV8/ ;室内贴脸口播,暖色墙,大面积柔光
segments:
- [0.00, 16.20, live_action]
diff --git a/rea_video/classify.py b/rea_video/classify.py
index 176b68b..9c9bfd4 100644
--- a/rea_video/classify.py
+++ b/rea_video/classify.py
@@ -76,6 +76,12 @@ def _sig(x: float) -> float:
return 1.0 / (1.0 + math.exp(-x))
+def no_repeats(f: dict) -> bool:
+ """No duplicate frames of a 24/25 fps source: under 2% of frame pairs, or a single repeated frame in a
+ short shot (a 24 -> 30 fps pull-up repeats every fifth frame, one repeat alone says nothing)."""
+ return f.get("dup_ratio", 1) < 0.02 or f.get("dup_count", 99) <= 1
+
+
def _norm(d: dict[str, float]) -> dict[str, float]:
s = sum(max(v, 0.0) for v in d.values()) or 1.0
return {k: max(v, 0.0) / s for k, v in d.items()}
@@ -160,7 +166,7 @@ def video_context(shots: list[dict], provenance: dict | None, fps: float | None)
continue # rendered graphics or frozen frames say nothing about camera cadence
d = float(r.get("duration", 0))
photo_dur += d
- if f.get("dup_ratio", 1) < 0.02 and f.get("sharp_period_ac", 0) < 0.45:
+ if no_repeats(f) and f.get("sharp_period_ac", 0) < 0.45:
native_dur += d
native30 = bool(fps and 29 <= fps <= 31 and photo_dur >= 3 and native_dur / photo_dur >= 0.7)
# photographic time carrying a film / TV hint (letterbox): a film recap or compilation looks like this
@@ -343,7 +349,7 @@ def deterministic(f: dict, overlay: dict | None = None, text: dict | None = None
# this shot's own cadence: a 30 fps file whose frames never repeat was captured at 30 fps (phones) rather than
# generated at 24 and pulled up. Per shot, unlike ctx["native30"], so a mixed edit (AI opener + phone footage)
# keeps the signature on the filmed shots. Platform re-encodes add a GOP sharpness rhythm, so that cue is skipped there.
- facts["native_cadence"] = bool(fps and 29 <= fps <= 31 and dup < 0.02 and not pulldown
+ facts["native_cadence"] = bool(fps and 29 <= fps <= 31 and no_repeats(f) and not pulldown
and (ctx.get("transcoded") or f.get("sharp_period_ac", 0) < 0.45))
if dup_pd:
ev.append(T("重复帧呈 {pd} 规律({dup:.0%},周期 {per}):原始素材为 24/25fps 后转码,常见于 AI 生成视频、3D/动画渲染或电影素材",
@@ -379,7 +385,7 @@ def deterministic(f: dict, overlay: dict | None = None, text: dict | None = None
if cam_tags:
live_hint += 1.0
ev.append(T("容器元数据含拍摄设备信息(make/model/location)", "Container metadata carries capture-device tags (make/model/location)"))
- if ctx.get("native30") and dup < 0.02 and not pulldown:
+ if ctx.get("native30") and no_repeats(f) and not pulldown:
live_hint += 0.9
ev.append(T("整片是原生 30fps、实拍类镜头没有 24fps 源的重复帧({share:.0%} 时长):手机直出常见,生成模型多输出 24fps",
"The whole file is native 30fps and photographic shots carry no 24fps-source duplicate frames ({share:.0%} of the duration): typical of straight-from-phone footage, generators mostly output 24fps",
diff --git a/rea_video/evaluate.py b/rea_video/evaluate.py
index 6b3188b..af9a649 100644
--- a/rea_video/evaluate.py
+++ b/rea_video/evaluate.py
@@ -167,19 +167,22 @@ def packaging_check(truth_path: str | Path, pack: dict, sfx: list[dict] | None =
return out
-def boundary_f1(pred: list[float], gt: list[float], tol: float = 0.1) -> dict:
+def boundary_f1(pred: list[float], gt: list[float], tol: float = 0.1, ignore: list[float] | None = None) -> dict:
+ """Cut precision / recall. `ignore`: boundaries the labeller could not decide; a predicted cut there is
+ neither right nor wrong."""
used = set()
- tp = 0
+ tp = fp = 0
for p in pred:
- for i, g in enumerate(gt):
- if i not in used and abs(p - g) <= tol:
- used.add(i)
- tp += 1
- break
- prec = tp / len(pred) if pred else 1.0
+ hit = next((i for i, g in enumerate(gt) if i not in used and abs(p - g) <= tol), None)
+ if hit is not None:
+ used.add(hit)
+ tp += 1
+ elif not any(abs(p - u) <= tol for u in ignore or []):
+ fp += 1
+ prec = tp / (tp + fp) if tp + fp else 1.0
rec = tp / len(gt) if gt else 1.0
f1 = 2 * prec * rec / (prec + rec) if prec + rec else 0.0
- return {"precision": round(prec, 3), "recall": round(rec, 3), "f1": round(f1, 3)}
+ return {"precision": round(prec, 3), "recall": round(rec, 3), "f1": round(f1, 3), "tp": tp, "fp": fp, "fn": len(gt) - tp}
def evaluate(labels_path: Path, out: Path, use_vlm: bool = False, ocr: bool = True, reuse: bool = True, only: set[str] | None = None,
@@ -283,7 +286,8 @@ def evaluate(labels_path: Path, out: Path, use_vlm: bool = False, ocr: bool = Tr
sfx_truth = read_json(Path(_expand(entry["sfx_truth"]))) if entry.get("sfx_truth") else None
row["packaging"] = packaging_check(entry["packaging_truth"], b["packaging"], (b.get("audio_plan") or {}).get("sfx_merged", []), sfx_truth)
if "cuts" in entry:
- row["cut_f1"] = boundary_f1([s["start"] for s in b["shots"][1:]], entry["cuts"], tol=float(entry.get("cut_tolerance", 0.1)))
+ row["cut_f1"] = boundary_f1([s["start"] for s in b["shots"][1:]], entry["cuts"], tol=float(entry.get("cut_tolerance", 0.1)),
+ ignore=entry.get("cuts_uncertain"))
if entry.get("image_source"):
srcs = {s["base"].get("image_source") for s in b["shots"]}
row["image_source_ok"] = entry["image_source"] in srcs
@@ -321,6 +325,10 @@ def evaluate(labels_path: Path, out: Path, use_vlm: bool = False, ocr: bool = Tr
cuts = [r["cut_f1"]["f1"] for r in rows if "cut_f1" in r]
if cuts:
summary["cut_f1_mean"] = round(sum(cuts) / len(cuts), 3)
+ tp, fp, fn = (sum(r["cut_f1"][k] for r in rows if "cut_f1" in r) for k in ("tp", "fp", "fn"))
+ summary["cuts"] = {"truth": tp + fn, "found": tp, "false": fp,
+ "recall": round(tp / (tp + fn), 3) if tp + fn else None,
+ "precision": round(tp / (tp + fp), 3) if tp + fp else None}
result = {"summary": summary, "rows": rows,
"confusion_seconds": {g: {p: round(v, 1) for p, v in ps.items() if v} for g, ps in confusion.items() if any(ps.values())}}
write_json(out / "eval_result.json", result)
diff --git a/rea_video/features.py b/rea_video/features.py
index 69e6c57..cbe1d00 100644
--- a/rea_video/features.py
+++ b/rea_video/features.py
@@ -328,6 +328,8 @@ def shot_features(samples: ShotSamples, fps: float) -> dict:
dup = mad < 0.15
moving_pairs = mad > 0.6
per = _periodicity(dup.tolist())
+ if samples.pair_mad:
+ agg["dup_count"] = int(dup.sum()) # absent for a single-frame shot: nothing to count
agg.update({
"pair_mad_median": float(np.median(mad)),
"pair_mad_p90": float(np.percentile(mad, 90)),
diff --git a/rea_video/remake.py b/rea_video/remake.py
index 956b0a0..970cfd1 100644
--- a/rea_video/remake.py
+++ b/rea_video/remake.py
@@ -54,9 +54,32 @@ def render_still_motion(image: Path, out: Path, duration: float, size: tuple[int
return out
+MAX_SPEEDUP = 3.0 # a generated clip is retimed to the original shot length, up to this much faster
+MAX_SLOWDOWN = 1.25 # and up to this much slower; past that the remainder is trimmed / held
+
+
+def fit_speed(clip_s: float, duration: float) -> float:
+ """Playback speed that fits a generated clip into the original shot. Models have a minimum length
+ (often 4-5 s), so a 1.2 s shot comes back as 4 s of the same action: playing only its first 1.2 s
+ cuts the action off and slows the edit, so the whole clip is sped up instead (within limits)."""
+ if clip_s <= 0 or duration <= 0:
+ return 1.0
+ return max(1 / MAX_SLOWDOWN, min(MAX_SPEEDUP, clip_s / duration))
+
+
+def _clip_seconds(src: Path) -> float:
+ try:
+ r = subprocess.run(["ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0", str(src)],
+ capture_output=True, text=True, check=True)
+ return float(r.stdout.strip() or 0)
+ except (subprocess.CalledProcessError, ValueError, FileNotFoundError):
+ return 0.0
+
+
def _fit_clip(src: Path, out: Path, duration: float, size: tuple[int, int], fps: float) -> Path:
w, h = size
- vf = (f"scale={w}:{h}:force_original_aspect_ratio=increase,crop={w}:{h},fps={fps},"
+ speed = fit_speed(_clip_seconds(src), duration)
+ vf = (f"setpts=PTS/{speed:.4f},scale={w}:{h}:force_original_aspect_ratio=increase,crop={w}:{h},fps={fps},"
f"tpad=stop_mode=clone:stop_duration={duration:.3f},trim=duration={duration:.3f},setpts=PTS-STARTPTS")
_ff(["-i", str(src), "-an", "-vf", vf, "-c:v", "libx264", "-pix_fmt", "yuv420p", "-crf", "18", str(out)])
return out
diff --git a/rea_video/shots.py b/rea_video/shots.py
index 3da6218..7f6a905 100644
--- a/rea_video/shots.py
+++ b/rea_video/shots.py
@@ -13,6 +13,10 @@ import numpy as np
from .media import VideoInfo, frame_times, iter_frames
THUMB_W = 96
+# jump cuts (same camera, subject jumps): share of the frame that changes, how far above the frames on both
+# sides, frames on each side that must stay quiet, and how little the picture may drift back (see _returns)
+JUMP_MIN_CHANGED, JUMP_RATIO, JUMP_QUIET, JUMP_MIN_RETURN = 0.17, 2.5, 2, 0.7
+SHORT_SHOT_S = 0.12 # shortest shot kept between two clean hard cuts (4 frames at 30 fps)
@dataclass
@@ -139,7 +143,11 @@ def detect_shots(track: FrameTrack, min_shot_s: float = 0.35, cut_threshold: flo
# frames; a filmed screen whose content changes keeps sensor noise, 0.002-0.03, and is not a cut)
still_swap = (s > cut_threshold and track.hist_dist[i] > 0.25 and chg[i] > 0.18 and chg_base[i] < 0.01
and s > base[i] * 5 + 0.1 and i >= 3 and float(track.pix_diff[i - 3:i].max()) < 1e-3)
- if strong or relative or still_swap:
+ if strong or relative or still_swap or _jump_cut(track, i):
+ # a muzzle flash / strobe, or the frame where a one- or two-frame flash or glitch ends: the picture
+ # is back to what it was, so nothing was cut
+ if _brief_flash(track, i) or _back_to_before(track.thumbs, i):
+ continue
boundaries[i] = ("cut", float(max(s, chg[i])))
# 2) fades through black / white: luma dips to an extreme and comes back
@@ -193,19 +201,28 @@ def detect_shots(track: FrameTrack, min_shot_s: float = 0.35, cut_threshold: flo
beat_marks = [b for b, _ in _mg_beats(track, boundaries, fps)]
- # assemble shots, enforce minimum length (merge short ones into previous)
+ # assemble shots, enforce minimum length. Boundaries closer than that are one transition (a flash, a
+ # blended frame, a whip) or a flash next to a cut: keep the strongest, not just the first, so a flash a few
+ # frames before a cut does not swallow it. A very short shot survives when both of its cuts are clean
+ # hard cuts (a 4-frame insert in a fast edit, a cover frame before the first shot).
min_len = max(1, int(round(min_shot_s * fps)))
- cuts = sorted(boundaries)
+ short_len = max(1, int(round(SHORT_SHOT_S * fps)))
+ kept: list[int] = []
+ for b in sorted(boundaries):
+ prev = kept[-1] if kept else 0
+ gap = b - prev
+ if gap >= min_len or (gap >= short_len and _clean_cut(boundaries, b) and (not kept or _clean_cut(boundaries, prev))
+ and float(track.changed[prev + 1:b].max()) < 0.3): # a held insert, not transition frames
+ kept.append(b)
+ elif kept and boundaries[b][1] > boundaries[prev][1] and b - (kept[-2] if len(kept) > 1 else 0) >= short_len:
+ kept[-1] = b
+ if kept and n - kept[-1] < min_len:
+ kept.pop() # a short tail joins the last shot
shots: list[Shot] = []
start, trans, bscore = 0, "start", 0.0
- for b in cuts + [n]:
- if b - start < min_len and b != n:
- continue
- if b == n and shots and b - start < min_len:
- shots[-1].end_frame = n
- break
+ for b in kept + [n]:
shots.append(Shot(index=len(shots) + 1, start_frame=start, end_frame=b, fps=fps, transition_in=trans, boundary_score=bscore,
- times=track.times))
+ times=track.times))
if b < n:
trans, bscore = boundaries[b]
start = b
@@ -218,6 +235,73 @@ def detect_shots(track: FrameTrack, min_shot_s: float = 0.35, cut_threshold: flo
return shots
+def _clean_cut(boundaries: dict[int, tuple[str, float]], b: int) -> bool:
+ kind, strength = boundaries[b]
+ return kind == "cut" and strength >= 0.35
+
+
+def _brief_flash(track: FrameTrack, i: int) -> bool:
+ """A muzzle flash / strobe / light flicker: the frame is brighter than just before, the brightness is
+ mostly gone two frames later, and the picture comes back. A flash transition into a new shot decays
+ more slowly and reveals a different picture, so it stays a cut."""
+ pre = float(track.luma[max(0, i - 3):i].min())
+ rise = float(track.luma[i]) - pre
+ if rise <= 5.0 or i + 2 >= track.n:
+ return False
+ return float(track.luma[i + 2]) - pre < 0.5 * rise and _returns(track.thumbs, i) < 0.6
+
+
+def _back_to_before(thumbs: list[np.ndarray], i: int) -> bool:
+ """Frame i looks like the picture two or three frames earlier again: the end of a flash or glitch
+ of one or two frames, not a cut."""
+ if i < 3:
+ return False
+ cur = thumbs[i].astype(np.float32)
+ first = float(np.abs(cur - thumbs[i - 1].astype(np.float32)).mean()) + 1e-6
+ return min(float(np.abs(cur - thumbs[j].astype(np.float32)).mean()) for j in (i - 3, i - 2)) < 0.3 * first
+
+
+def _returns(thumbs: list[np.ndarray], i: int, span: int = 4) -> float:
+ """How far the picture stays away after frame i, relative to the jump into frame i: ~1 for a cut
+ (the new shot never looks like the old one), well below 1 when a flash or strobe fades back. The
+ reference is any of the three frames before i, so the second frame of a two-frame flash also counts."""
+ n = len(thumbs)
+ if i < 1 or i + 1 >= n:
+ return 1.0
+ cur = thumbs[i].astype(np.float32)
+ first = float(np.abs(cur - thumbs[i - 1].astype(np.float32)).mean()) + 1e-6
+ best = float("inf")
+ for j in range(max(0, i - 3), i):
+ a = thumbs[j].astype(np.float32)
+ jump = float(np.abs(cur - a).mean()) + 1e-6
+ if jump < 0.2 * first:
+ continue # frame j already looks like frame i: not a reference for "before"
+ later = min(float(np.abs(thumbs[k].astype(np.float32) - a).mean()) for k in range(i + 1, min(n, i + 1 + span)))
+ best = min(best, later / jump)
+ return best if best != float("inf") else 1.0
+
+
+def _jump_cut(track: FrameTrack, i: int) -> bool:
+ """Same camera, same background, the subject's position jumps: a talking-head jump cut or a punch-in.
+ Too little of the frame changes for the cut rules above, but the change happens in one frame while the
+ frames on both sides are steady, and nothing similar happens just before or after (frame-skipped
+ 'staccato' motion jumps every second frame)."""
+ n = track.n
+ if i < 4 or i + 4 > n:
+ return False
+ c, d = track.changed, track.pix_diff
+ if c[i] < JUMP_MIN_CHANGED:
+ return False
+ side_c = max(float(np.median(c[max(0, i - 6):i])), float(np.median(c[i + 1:i + 7])))
+ side_d = max(float(np.median(d[max(0, i - 6):i])), float(np.median(d[i + 1:i + 7])))
+ if c[i] < JUMP_RATIO * (side_c + 0.02) or d[i] < 2.0 * (side_d + 0.004):
+ return False
+ near = np.concatenate([c[i - JUMP_QUIET:i], c[i + 1:i + 1 + JUMP_QUIET]])
+ if float(near.max()) > 0.5 * float(c[i]):
+ return False
+ return _returns(track.thumbs, i) >= JUMP_MIN_RETURN
+
+
def _flash(luma: np.ndarray, start: int, end: int, fps: float) -> float:
"""A cut that opens on a bright flash decaying into the new shot (a common motion-graphics transition):
seconds until the brightness settles, or 0."""
diff --git a/skills/rea-video/references/remake.md b/skills/rea-video/references/remake.md
index a6bb952..d550cd9 100644
--- a/skills/rea-video/references/remake.md
+++ b/skills/rea-video/references/remake.md
@@ -12,7 +12,7 @@
1. 按分镜表(`report.md` 的镜头号和时长)把素材对应到镜头。一条长素材覆盖多个镜头时,先用 ffmpeg 按动作切开;拿不准对应关系时给用户看截图确认。
2. 写一个 `results.json`:`{"results": {"<镜头号>": {"video": "<素材绝对路径>"}, ...}}`。手动生成的「生成单元」视频覆盖多个镜头时,同样先按单元提示词里的「镜头i(a–b s)」时间切开再填。
-3. `rea-video assemble out/ref/breakdown.json <results.json 路径>`:每段素材裁到原镜头时长,没填的镜头暂时用原片占位,声音沿用原片;输出 `remake.mp4` 和左右对比的 `compare.mp4`。告诉用户哪些镜头还是原片占位、声音还要换。
+3. `rea-video assemble out/ref/breakdown.json <results.json 路径>`:每段生成素材整段变速塞进原镜头时长(最多快 3 倍、慢 1.25 倍,超出部分再裁),切点和原片对齐,没填的镜头暂时用原片占位,声音沿用原片;输出 `remake.mp4` 和左右对比的 `compare.mp4`。告诉用户哪些镜头还是原片占位、声音还要换。
**自动生成的限制**:`remake-plan` 和 capsule-cinema 目前还是一个镜头调一次模型;报告里「生成单元」的多镜头提示词要用户手动贴到支持多镜头的模型(如即梦 / Seedance 2.5)上用。向用户说明这一点,并给出两种做法的调用次数。
diff --git a/skills/rea-video/references/taxonomy.md b/skills/rea-video/references/taxonomy.md
index 89cecdf..16793dd 100644
--- a/skills/rea-video/references/taxonomy.md
+++ b/skills/rea-video/references/taxonomy.md
@@ -122,6 +122,9 @@
## 切镜
- 硬切:直方图距离与像素差的尖峰,且变化面积超过 25%。元素弹出不算切镜。
+- 跳剪 / 推近切:同机位同背景,人物位置或景别在一帧内跳变。变化面积只有 17% 以上,但比前后几帧的变化高出 2.5 倍以上,前后两帧都平稳,画面也不会回到切之前。
+- 闪光、枪口火光、频闪:画面一两帧内变亮又恢复原样,不算切镜;闪白转场褪去后露出新画面,仍算切镜。
+- 短镜头:两刀干净的硬切之间、画面稳定的镜头,最短保留 0.12 秒(快剪插入、开头封面帧);更近的几处边界属于同一个转场,保留最强的一处。
- 交叉溶解:中间帧是两端帧的线性混合(α 在 0.2–0.8,残差 <0.2),并用光流排除推拉运动。
- 淡入淡出:亮度降到极暗或极亮再回来。
- MG 节拍:长镜头内"定格 → 动画 → 定格",两个定格内容差异超过 12%,记为镜头内节拍,不算切镜。
diff --git a/tests/test_shots.py b/tests/test_shots.py
new file mode 100644
index 0000000..8526bc1
--- /dev/null
+++ b/tests/test_shots.py
@@ -0,0 +1,50 @@
+"""Shot boundaries in talking-head and fast-cut edits: jump cuts, brief flashes, very short inserts."""
+import cv2
+import numpy as np
+
+from rea_video.media import video_info
+from rea_video.remake import fit_speed
+from rea_video.shots import build_track, detect_shots
+from tests.conftest import _photo_like, _write
+
+W, H = 360, 640
+
+
+def _speaker(bg: np.ndarray, x: int, y: int, t: int, rng) -> np.ndarray:
+ """A person in front of a fixed background, swaying slightly from frame to frame."""
+ f = bg.copy()
+ sway = int(round(3 * np.sin(t / 6)))
+ cv2.ellipse(f, (x + sway, y + 360), (130, 220), 0, 180, 360, (40, 40, 50), -1) # shoulders
+ cv2.circle(f, (x + sway, y + 190), 70, (120, 150, 200), -1) # head
+ cv2.circle(f, (x + sway - 25, y + 175), 8, (30, 30, 30), -1)
+ cv2.circle(f, (x + sway + 25, y + 175), 8, (30, 30, 30), -1)
+ noise = rng.normal(0, 2.0, f.shape)
+ return np.clip(f.astype(np.float32) + noise, 0, 255).astype(np.uint8)
+
+
+def test_jump_cut_found_and_brief_flash_ignored(tmp_path):
+ rng = np.random.default_rng(1)
+ bg = _photo_like(W, H, 3)
+ frames = [_speaker(bg, 180, 160, t, rng) for t in range(45)]
+ # jump cut: same camera and background, the speaker is suddenly further left and lower
+ frames += [_speaker(bg, 120, 210, t, rng) for t in range(45, 120)]
+ for k, gain in ((75, 90.0), (76, 25.0)): # a two-frame light flash inside the second take
+ frames[k] = np.clip(frames[k].astype(np.float32) + gain, 0, 255).astype(np.uint8)
+ p = str(_write(frames, tmp_path / "jump.mp4"))
+ shots = detect_shots(build_track(p, video_info(p)))
+ assert [round(s.start, 2) for s in shots] == [0.0, 1.5]
+
+
+def test_short_insert_between_two_hard_cuts_is_kept(tmp_path):
+ a, b, c = (_photo_like(W, H, s) for s in (11, 12, 13))
+ frames = [a] * 30 + [b] * 4 + [c] * 30 # a 4-frame insert, the kind a fast edit or a cover frame makes
+ p = str(_write(frames, tmp_path / "insert.mp4"))
+ shots = detect_shots(build_track(p, video_info(p)))
+ assert [s.start_frame for s in shots] == [0, 30, 34]
+
+
+def test_generated_clip_is_retimed_to_the_shot():
+ assert fit_speed(4.0, 1.25) == 3.0 # a 1.25 s shot from a 4 s minimum generation: whole clip, capped speed-up
+ assert abs(fit_speed(5.0, 2.5) - 2.0) < 1e-9
+ assert abs(fit_speed(2.0, 4.0) - 0.8) < 1e-9 # too short: slowed a little, the rest held
+ assert fit_speed(0.0, 2.0) == 1.0