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 格式输出。

Follow VIDEO.md draft 2

junecdcdfb413238
diff --git a/CHANGELOG.md b/CHANGELOG.md
index da2986e..6f219df 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,12 +2,12 @@
## 视频拆解标准包 VIDEO.md,报告重写,音效单独分离
-这一版定下了视频拆解的标准包格式:拆片包(VIDEO.md)。拆一条视频现在得到两样东西:给人看的报告(HTML / PDF),和给模型、下游项目读的拆片包。格式介绍和规范见 [docs/videomd.md](docs/videomd.md)。
+这一版定下了视频拆解的标准包格式:拆片包(VIDEO.md)。拆一条视频现在得到两样东西:给人看的报告(HTML / PDF),和给模型、下游项目读的拆片包。VIDEO.md 是开放格式,规范在 [videomd/videomd](https://github.com/videomd/videomd);rea-video 生成的内容见 [docs/videomd.md](docs/videomd.md)。
**拆片包 VIDEO.md**
- 四层逐级展开:卡片 → 概览和地图 → 时间线(一行一镜)→ 单镜文件,最后才是完整数据。一条 3 分钟口播读到概览约 2k token,完整数据约 19 万 token。
- 每个文件开头写着自己的 token 数;看到的和推断的分开写,时间线里推断的键名带 `~`。
-- 字段有 JSON Schema(`rea_video/videomd.schema.json`)。`rea-video videomd out/ref --check` 检查一个目录是否合格,`videomd.read()` 读出结构化数据。
+- 字段有 JSON Schema。`rea-video videomd out/ref --check` 检查一个目录是否合格,`videomd.read()` 读出结构化数据(校验和读取用 `videomd` 包)。
- 拆解时自动生成;旧的输出目录用 `rea-video videomd out/ref` 补出来。
**给人看的报告**
diff --git a/docs/videomd-design.md b/docs/videomd-design.md
deleted file mode 100644
index 2dc43b1..0000000
--- a/docs/videomd-design.md
+++ /dev/null
@@ -1,150 +0,0 @@
-# VIDEO.md 的设计思路
-
-[videomd.md](videomd.md) 讲 VIDEO.md 拆片包长什么样、怎么校验。这一页讲为什么长这样:要解决什么问题,每个设计决定背后的考虑,借鉴了哪些现成的做法,以及它给使用者带来什么。
-
-## 一句话
-
-VIDEO.md 是一种**给模型读的视频拆解格式**。每个技能有一个 `SKILL.md`,每条视频也有一个 `VIDEO.md`:从一张百来 token 的卡片开始,逐层展开到单个镜头,每一层都写明自己有多大、里面哪些是看到的、哪些是推断的。
-
-打个比方:卡片是这条视频的身份证,一眼看清它是什么、怎么做的、有多确定;整个包是它的档案,从概览、时间线到单个镜头,要查哪一层就翻到哪一层,不用整本读完。
-
-## 要解决的问题
-
-拆解一条视频,工具会产出大量东西:逐镜的测量值、制作方式的概率、证据、字幕时间轴、音效位置、复刻提示词、截图、分轨音频。这些数据有三类读者,需求完全不同:
-
-| 读者 | 要什么 | 怕什么 |
-|---|---|---|
-| 人 | 结论、看点、照着做的步骤 | 看不懂、信息太散 |
-| 模型 / agent | 能回答用户问题的那部分事实 | 上下文太贵、在细节里迷路、把推断当事实 |
-| 下游程序 | 稳定的字段和取值 | 格式悄悄变了、解析正文 |
-
-给人看的有 `report.html`,给程序的有 `breakdown.json`。缺的是中间那个:模型。
-
-把 `breakdown.json` 直接交给模型行不通。一条 3 分钟口播约 19 万 token,一条 75 镜的影视解说约 24 万。模型每回答一个问题都读一遍,又贵又慢;而且 JSON 里测量值、推断和最终结论平铺在一起,模型很容易把「工具猜 41% 是录屏」读成「这是录屏」。
-
-把 `report.md` 交给模型也不对。报告是按人的阅读顺序写的,有折叠、有修辞、有重复的引导语,模型拿不到稳定的结构,也没法只读其中一段。
-
-VIDEO.md 就是为模型这一类读者设计的。
-
-## 借鉴了什么
-
-VIDEO.md 没有发明新东西,它把几种已经被证明好用的做法组合在一起。
-
-### Agent Skills:逐层展开
-
-Agent Skill 的结构是:`SKILL.md` 开头的 `name` / `description` 常驻上下文,只有几十个 token;agent 判断用得上时才读正文;正文再指向 `references/` 下的文件,需要时才打开。用多少读多少,这叫渐进式展开(progressive disclosure)。
-
-VIDEO.md 照搬了这个结构,只是把「一项能力」换成了「一条视频」:
-
-| Agent Skill | VIDEO.md |
-|---|---|
-| `SKILL.md` 前置信息(name、description) | `VIDEO.md` 前置信息:卡片(name、description、制作占比、置信度) |
-| `SKILL.md` 正文:流程和指引 | `VIDEO.md` 正文:结论、不确定点、地图 |
-| `references/*.md`:按需打开 | `video/*.md`:按主题按需打开 |
-| 脚本、资源文件 | `breakdown.json`、截图、分轨音频 |
-
-区别在于 VIDEO.md 多走了一步:每个文件的前置信息里写着自己的 token 数,地图里也列着。Skill 只告诉 agent 「这里有什么」,VIDEO.md 还告诉它「打开要花多少」。模型可以在读之前就权衡值不值得。
-
-### DSL:一行一镜的时间线
-
-时间线是整个包的主干。它没有用 JSON 数组,也没有用 Markdown 表格,而是一个很小的行格式:
-
-```
-#07 16.2-18.5 | seen 男子讲话,画面上弹出多张聊天截图 | cam 固定 | made~ 屏幕录制/截图(screen_capture) 41% | flag 低置信
-```
-
-这是一种很窄的领域语言(DSL),思路和 SRT 字幕、EDL 剪辑表、日志格式一样:一行一条记录,开头是编号和时间,后面是 `键 值` 对。选它的原因:
-
-- **省 token。** 同样的信息写成 JSON,键名、引号、括号要占掉一大半。75 镜的时间线约 3.5k token,模型可以一次读完全片。
-- **人和模型都能直接读。** 不需要渲染,打开就能看懂;模型生成和改写也不容易出错。
-- **程序能稳定解析。** 语法只有三条:行首 `#编号 起-止`,字段用 ` | ` 分隔,第一个空格前是键。值里保证不出现 `|`。`videomd.parse_timeline_line()` 不到二十行。
-- **能表达「推断」。** 键名后带 `~`(`made~`、`real~`)表示这是工具推断的,不带的是画面里看到或直接测得的。这个区分写在语法里,不用靠模型去理解上下文。
-
-但 VIDEO.md 只在时间线这一处用了 DSL。卡片和单镜数据用 YAML 前置信息,有 JSON Schema 约束;细节说明用普通 Markdown。小语法只放在最需要密度的地方,其他地方用大家都会读的格式。
-
-### 其他
-
-- **Markdown + YAML 前置信息**:静态站点生成器(Jekyll、Hugo)和 Agent Skills 都这么用。正文给模型读,前置信息给程序读,一个文件两种用途。
-- **JSON Schema**:卡片、主题文件、镜头文件的前置信息都有 schema,`rea-video videomd --check` 用它校验。
-- **目录即包**:和 Skill 一样,一个目录就是一个完整的包,没有打包格式、没有索引数据库,复制、压缩、放进 git 都行。
-
-## 设计决定
-
-### 分四层,每层比上一层贵一个量级
-
-| 层 | 大小 | 够回答什么 |
-|---|---|---|
-| L0 卡片 | 约 150 token | 这是什么视频、怎么做的、有多确定 |
-| L1 概览和地图 | 约 1–2k | 结论、复刻概要、哪里不确定、下一步该读哪个文件 |
-| L2 主题文件 | 几百到几千 | 某一方面(时间线、声音、包装、复刻方案)的全部信息 |
-| L3 单镜文件 | 约 500–1000 | 某一镜看得到什么、推断是什么、依据、提示词、帧图 |
-| L4 原始数据 | 几十万 | 程序用 |
-
-实际使用中,大多数问题(「这条怎么做的」「要准备什么素材」「哪几镜要复核」)读到 L1 就能回答,按镜头回答再加上时间线,一共约 4k token。只有核实某一镜时才需要打开 L3。
-
-分层的依据是问题的粒度:用户先问整体,再问某一方面,最后才问某一镜。每一层正好对应一种粒度的问题。
-
-### 读之前就知道代价
-
-每个文件的前置信息里都有 `tokens`,地图表格里也有一列。这看起来是个小细节,但它改变了模型读文件的方式:不是「打开看看」,而是「这个问题值得花 14k token 去读复刻方案吗,还是时间线里的 `remake` 字段就够了」。
-
-### 看到的和推断的分开
-
-这是 VIDEO.md 最重要的一条规矩。视频拆解里有两种性质完全不同的信息:
-
-- **看到的**:画面里有一个人在讲话、右上角有标题、镜头是固定机位。对着截图就能核实。
-- **推断的**:这一镜是 AI 生成的(72%),依据是噪声分布和帧率。肉眼不一定能核实。
-
-两者混在一起,模型就会把推断当事实告诉用户,用户也分不清哪句该信。所以 VIDEO.md 在三个地方把它们分开:时间线用 `~` 标出推断的键;单镜文件分成「画面里看得到的」和「工具推断的制作方式」两节;推断的字段统一放在 `inferred` 下,附概率、次选和 `decided_by`(`tools` 工具 / `model` 看图模型 / `agent` / `human` 人)。两者对不上时,以截图为准。
-
-### 时间线是主干
-
-视频天然是线性的,几乎所有问题最后都会落到「第几秒、第几镜」。所以时间线是唯一一个一定要读完整的 L2 文件,其他主题文件和单镜文件都通过镜头编号挂在它上面。时间线里的 `flag` 字段直接标出要复核的镜头,模型扫一遍就知道该去看哪几张图。
-
-### 格式固定,内容开放
-
-能被程序依赖的部分是固定的:前置信息的字段、时间线的语法、类别 id(`live_action`、`ai_video`……)。可以增加的部分是开放的:时间线可以加新键、可以加新的主题文件、叠加层的取值可以增加。规则是读的一方遇到不认识的东西就忽略,不报错。只加不改时版本号不变,改了已有字段的含义才升 `videomd:` 版本。
-
-这样拆解能力变强时(比如加了新的拍法维度),旧的读取方不用跟着改。
-
-### 给模型的值跟语言走,给程序的 id 保持稳定
-
-时间线里写的是「屏幕录制/截图」还是 screen capture,跟着包的语言走,因为它是给模型读的。但括号里的 `(screen_capture)` 和单镜前置信息里的 `inferred.made` 永远是稳定的英文 id,程序只认这个。
-
-## 好处和价值
-
-**对 agent:**
-- 回答一个问题的成本从几十万 token 降到几千,可以在同一个对话里拆多条视频、来回追问。
-- 不需要理解 rea-video 的内部数据结构,读 Markdown 就行。
-- 推断和事实分开,转述给用户时不容易说过头。
-- 地图和 token 数让它自己决定读多深,不用写死读取流程。
-
-**对下游程序:**
-- 有 schema、有校验命令、有参考读取实现(`videomd.read()`),可以只依赖前置信息和时间线,不碰正文和 `breakdown.json`。
-- 新增内容不会弄坏已有的解析。
-
-**对人:**
-- 拆片包本身就是能直接读的 Markdown,不需要工具也能翻。
-- 判断来源写在包里(`readers`、`decided_by`),看得出哪些结论是机器测的、哪些是看图确认过的、哪些是用户纠正过的。
-
-**对整个流程:**
-- 拆解和使用解耦。拆解工具可以换、可以升级,只要输出合格的 VIDEO.md,读的一方不受影响;反过来也一样,任何能读 Markdown 的 agent 都能用拆解结果。
-- 复核有了落点。低置信镜头在时间线上标着,复核结果写回后重新生成包,`decided_by` 跟着变。
-
-## VIDEO.md 不是什么
-
-- **不是报告。** 报告写给人,讲故事、给步骤;VIDEO.md 写给模型,讲事实、给结构。两者从同一份数据生成,内容一致,组织方式不同。
-- **不是剪辑工程文件。** EDL、OpenTimelineIO 描述的是「片段怎么拼成成片」,给剪辑软件用。VIDEO.md 描述的是「这条视频里有什么、是怎么做出来的」,给理解和复刻用。
-- **不是数据库。** 没有查询语言,没有索引。一条视频一个目录,靠地图和文件名找东西。
-
-## 和其他做法的对比
-
-| 做法 | 问题 |
-|---|---|
-| 直接给模型 `breakdown.json` | 太大;测量、推断、结论混在一起 |
-| 直接给模型报告 | 没有稳定结构,没法只读一部分 |
-| 每次让模型自己去读视频 | 贵、慢、不可复现,也拿不到帧率、噪声、元数据这类肉眼看不到的证据 |
-| 一个大 Markdown 文件 | 要么太长读不完,要么太短不够用;无法按需展开 |
-| 纯 JSON API | 程序友好,但模型读起来浪费 token,人也看不了 |
-
-VIDEO.md 的做法是不在这些里面选一个,而是分层:上层给模型、中层给模型和程序、底层给程序。
diff --git a/docs/videomd.md b/docs/videomd.md
index 3434773..589f72b 100644
--- a/docs/videomd.md
+++ b/docs/videomd.md
@@ -1,216 +1,47 @@
-# VIDEO.md 拆片包:视频拆解的标准包
+# VIDEO.md 拆片包
拆一条视频,会得到两样东西:
- **给人看的报告**(`report.html` / `report.pdf`):这条视频讲什么、为什么能火、怎么做的、照着怎么复刻。
-- **给模型和程序读的拆片包**(`VIDEO.md`):同样的结论,按固定格式放进一个目录。agent 回答问题、下游项目生成复刻任务,都读它。每个技能有一个 `SKILL.md`,每条视频也有一个 `VIDEO.md`。
+- **给模型和程序读的拆片包**(`VIDEO.md` + `video/`):同样的结论,按固定格式放进一个目录。agent 回答问题、下游项目生成复刻任务,都读它。
-VIDEO.md 是一个开放格式,规范、schema、校验器和示例在 [videomd/videomd](https://github.com/videomd/videomd),以那边为准。这一页介绍 rea-video 生成的拆片包,后半部分是格式规范的中文说明。设计上的考虑(借鉴了 Agent Skills 和 DSL 的哪些做法、每个决定的理由)见 [videomd-design.md](videomd-design.md)。
+每个技能有一个 `SKILL.md`,每条视频也有一个 `VIDEO.md`。VIDEO.md 是一个开放格式,规范、设计思路、接入和生成指南、校验器都在 [videomd/videomd](https://github.com/videomd/videomd)([中文](https://github.com/videomd/videomd/blob/main/i18n/README_zh.md)),以那边为准。这一页只讲 rea-video 生成的拆片包里有什么。
-## 为什么要有拆片包
+## 逐层读
-完整的拆解数据(`breakdown.json`)一条 3 分钟的口播就有约 19 万 token:逐镜的测量值、证据、帧率、字幕时间轴都在里面。模型每回答一个问题都读一遍,又贵又慢,还容易在细节里迷路。
+1. **卡片**(`VIDEO.md` 前置信息,几百 token):这条视频讲什么、怎么做的、有多确定。
+2. **概览和地图**(`VIDEO.md` 正文,约 1–2k token):结论、叙事线、复刻概要、不确定点。地图一行一个文件:`路径 | 约 token | 里面有什么 · 什么时候读`。
+3. **时间线**(`video/timeline.md`):一行一个镜头。键名带 `~` 的是推断,不带的是画面里看得到或测得的。
+4. **镜头文件**(`video/shots/<编号>.md`)和截图:核实某一镜时才打开。
-拆片包把它分成四层,像 agent skill 一样逐层展开:
+同一条 3 分钟口播,读到概览约 2k token,加上时间线约 4k token;完整数据 `breakdown.json` 约 19 万 token。
-1. 先读一张**卡片**(约 150 token):这是什么视频、怎么做的、有多确定,值不值得往下读。
-2. 再读一页**概览和地图**(约 1–2k token):结论、叙事线、复刻概要、不确定点。地图写清每个文件里有什么、什么时候该读、有多大。
-3. 要按镜头回答时读**时间线**:一行一个镜头。
-4. 要核实某一镜时,才打开那一镜的**镜头文件**和截图。
+## rea-video 写进包里的内容
-同一条口播,读到第 2 层约 2k token,加上时间线约 4k token,就能回答「这条怎么做的、要准备什么、哪几镜要复核」。
-
-## 三条规矩
+| 文件 | 内容 |
+|---|---|
+| `VIDEO.md` | 卡片带 `made_mix`(按时长的制作方式占比)、`confidence`、`readers`(工具 / 看图模型 / agent / 人工)、`source.sha256`;正文是结论、讲什么、叙事线、复刻概要、要拿到的真实素材、不确定点、地图 |
+| `video/timeline.md` | `story` 叙事作用 · `seen` 画面 · `camera` 运镜 · `overlay` 叠加层 · `made~` 制作方式 · `material~` 素材来源 · `remake` 复刻路线 · `flag` 需要复核 |
+| `video/content.md` | 内容与结构、叙事线、台词 |
+| `video/cast.md` | 角色、场景、道具 |
+| `video/sound.md` | 人声、BGM、音效、节拍和来源 |
+| `video/look.md` | 实拍镜头的景别、机位、打光、剪辑和器材(有实拍镜头时) |
+| `video/packaging.md` | 字幕、花字、贴纸、画中画的时间和样式 |
+| `video/remake.md` | 复刻方案:生成单元、拍摄场次、代码合成、要准备的真实素材 |
+| `video/shots/<编号>.md` | 每镜的 `inferred`(制作方式、概率、次选、由谁判定、有没有真实素材)、`flags`、`frames`;正文是看得到的、推断和依据、提示词 |
+| `breakdown.json`、`shots/`、`stems/`、`sfx/`、`packaging/`、`storyboard.jpg`、`audio.png` | 完整数据和媒体文件,地图里都列着 |
-- **看到的和推断的分开写。** 画面里看得到、能对着截图核实的,和工具推断的制作方式,放在不同的字段和小节里;时间线里推断的键名带 `~`。两者对不上时,以截图为准。
-- **读之前就知道代价。** 每个文件开头都写着自己有多少 token。
-- **格式固定,内容可以扩展。** 卡片、时间线、镜头文件的字段有 JSON Schema,可以程序校验;读的一方遇到不认识的字段、键、文件时忽略,不报错。
+没有内容的主题文件不生成。
-## 怎么得到、怎么检查
+## 命令
```bash
rea-video decompose ref.mp4 -o out/ref # 拆解时一起生成拆片包
-rea-video videomd out/ref # 旧的输出目录,从 breakdown.json 补出拆片包
-rea-video videomd out/ref --check # 检查是否符合 VIDEO.md 规范
+rea-video videomd out/ref # 从 breakdown.json 重新生成拆片包
+rea-video videomd out/ref --check # 按 VIDEO.md 规范校验(用的是 videomd 包)
```
```python
-from rea_video import videomd
-pkg = videomd.read("out/ref") # 卡片、时间线、每个镜头的结构化数据
-```
-
----
-
-以下是格式规范。
-
-## 目录
-
-拆解的输出目录本身就是一个拆片包:
-
-```
-out/ref/
- VIDEO.md 入口。L0 卡片(前置信息)+ L1 概览和地图(正文)
- video/
- timeline.md L2 时间线:一行一个镜头,整个包的主干
- content.md L2 内容与结构、叙事线、台词
- cast.md L2 角色、场景、道具
- sound.md L2 人声、BGM、音效、节拍、来源
- look.md L2 拍法、打光、剪辑(有实拍镜头时)
- packaging.md L2 字幕、花字、贴纸、画中画
- remake.md L2 复刻方案、要准备的真实素材和参考素材
- shots/07.md L3 单个镜头的全部细节
- breakdown.json L4 完整原始数据
- shots/ stems/ sfx/ packaging/ storyboard.jpg audio.png L4 帧图、分轨音频、音效片段、字幕文件
- report.html report.md 给人看的报告
-```
-
-没有内容的主题文件不生成(比如没有实拍镜头就没有 `look.md`)。**所有路径都相对包根目录**,包括写在 `video/` 下文件里的路径。
-
-## 四层
-
-| 层 | 在哪 | 大小 | 回答什么 |
-|---|---|---|---|
-| L0 卡片 | `VIDEO.md` 前置信息 | 约 150 token | 这是什么视频、怎么做的、有多确定,值不值得往下读 |
-| L1 概览 | `VIDEO.md` 正文 | 约 1–2k token | 结论、叙事线、复刻概要、不确定点,以及地图 |
-| L2 主题 | `video/*.md` | 每个几百到几千 token | 某一方面的完整信息;`timeline.md` 一行一镜 |
-| L3 镜头 | `video/shots/<编号>.md` | 每个约 500–1000 token | 某一镜看得到什么、推断是什么、依据、提示词、帧图 |
-| L4 原始 | `breakdown.json`、媒体文件 | 几十万 token | 程序用;模型一般不需要打开 |
-
-
-## 每个文件的前置信息
-
-每个 `.md` 文件开头都是 YAML 前置信息,至少有:
-
-```yaml
-videomd: 1 # 格式版本
-part: timeline # 这是哪一部分:timeline / content / cast / sound / look / packaging / remake / shot
-tokens: 2275 # 正文大约多少 token,读之前就知道代价
-```
-
-`VIDEO.md` 的前置信息就是卡片:
-
-```yaml
-videomd: 1
-name: ref
-description: 混合制作:实拍 94% + 屏幕录制/截图 4% + AI 生成视频 2%
-source: {file: ref.mp4, duration: 174.067, size: 1080x1920, fps: 30.0, aspect: '9:16'}
-shots: 25
-confidence: 0.771 # 按时长加权的判断置信度
-made_mix: {live_action: 0.943, screen_capture: 0.039, ai_video: 0.019} # 推断,按时长
-readers: [tools, model, agent] # 谁参与了判断:工具测量 / 看图模型 / agent 看图 / 人工纠正(human)
-open_questions: 9
-lang: zh
-generator: {name: rea-video, version: 0.1.0} # 谁生成的这个包
+import videomd
+pkg = videomd.read("out/ref") # {"card", "map", "timeline", "shots"}
```
-
-## 看到的和推断的
-
-拆片包始终把两类信息分开:
-
-- **看到的**:画面里看得到、能对着截图核实的东西(画面内容、运镜、叠加层、文字、破绽),以及直接测得的量。
-- **推断的**:工具和看图模型对制作方式、素材来源的判断,附概率和依据。依据可能是肉眼看不出的测量(帧率、噪声、转码、元数据)。
-
-时间线里用键名标出来:**键名后带 `~` 的是推断**,不带的是看到的或测得的。每镜文件里分成「画面里看得到的」和「工具推断的制作方式」两节。两者对不上时,以截图为准。
-
-## 时间线语法
-
-`video/timeline.md` 里,镜头行放在 ```` ```videomd-timeline ```` 代码块中,一行一个镜头:
-
-```
-#07 16.2-18.5 | seen 男子讲话,画面上弹出多张聊天截图 | cam 固定 | made~ 屏幕录制/截图(screen_capture) 41% · 次选 代码/模板渲染 29% | real~ 用户真实素材:录屏素材 | remake 录屏重建 · 段1 | flag 低置信
-```
-
-- 行首:`#编号 起-止`,时间单位是秒。
-- 之后是用 ` | ` 分隔的字段,每个字段是 `键 值`(第一个空格前是键)。值里不会出现 `|`。
-- 字段按下表顺序出现,没有的字段省略:
-
-| 键 | 含义 | 类别 |
-|---|---|---|
-| `say` | 这一镜在叙事里的作用和讲的点 | 看图得出 |
-| `seen` | 画面里有什么(一句话) | 看到的 |
-| `cam` | 运镜(固定、手持、平滑运镜、整图推拉……) | 测得的 |
-| `over` | 叠加层(字幕、花字、标题、贴纸……) | 测得的 |
-| `made~` | 制作方式和置信度,括号里是类别 id;`· 次选` 后是第二可能 | 推断 |
-| `real~` | 素材来源:AI 生成、用户真实素材、混合…… | 推断 |
-| `remake` | 复刻路线和所属的生成单元 / 拍摄场次 / 代码工程 | 方案 |
-| `flag` | 需要复核:低置信、待确认、有分歧、用户纠正 | — |
-
-读写时遇到不认识的键要保留、不能报错,以后的版本可以加键。
-
-## 镜头文件
-
-`video/shots/07.md` 的前置信息是这一镜的结构化数据,正文是给模型读的细节:
-
-```yaml
-videomd: 1
-part: shot
-shot: 7
-time: [16.2, 18.467]
-camera: static
-overlays: [subtitle]
-inferred:
- made: screen_capture # 类别 id,见 skills/rea-video/references/taxonomy.md
- p: 0.408
- alternatives: {code_render: 0.294, live_action: 0.209}
- decided_by: model # tools / model / agent / human:最后由谁定的
- real_material: true
-flags: [low_confidence] # uncertain / disputed / low_confidence
-frames: {sheet: shots/shot_007.jpg, first: shots/shot_007_first.jpg, last: shots/shot_007_last.jpg}
-tokens: 572
-```
-
-正文依次是:画面里看得到的 → 工具推断的制作方式(推断、素材来源、判断依据)→ 复刻(说明、首帧图像提示词、视频提示词)。
-
-## 怎么读
-
-模型:
-
-1. 读 `VIDEO.md`。大多数问题(怎么做的、要准备什么、哪里不确定)到这里就能回答。
-2. 要按镜头回答时读 `video/timeline.md`,找到相关的行或带 `flag` 的行。
-3. 要核实某一镜时,打开 `video/shots/<编号>.md` 和它 `frames` 里的截图。
-4. 不读 `breakdown.json`。
-
-程序:用前置信息和时间线行,不解析正文。rea-video 带了一个参考实现:
-
-```python
-from rea_video import videomd
-pkg = videomd.read("out/ref") # {"card": {...}, "timeline": [{"shot": 7, "start": 16.2, "made~": ...}], "shots": {7: {...}}}
-```
-
-## 取值
-
-| 字段 | 取值 |
-|---|---|
-| 制作方式 `made` / `made_mix` / `alternatives` 的键 | `live_action` 实拍、`ai_video` AI 生成视频、`avatar` 数字人、`cg_3d` 3D 渲染、`code_render` 代码/模板渲染、`screen_capture` 录屏/截图、`still_motion` 静图推拉、`static_hold` 静帧、`anim_2d` 2D 动画、`stop_motion` 定格动画、`film_footage` 影视片段 |
-| `camera` | `static` 固定、`static_with_subject_motion` 固定(主体在动)、`planar_zoom_pan` 整图推拉/平移、`handheld_like` 手持晃动、`smooth_move` 平滑运镜、`unknown` |
-| `overlays`(开放取值,可能增加) | `subtitle` 字幕、`title` 标题、`label` 标注、`styled_text` 花字、`static_graphic` 图形贴片、`layout_template` 版式模板、`animated_sticker` 动图贴纸、`static_sticker` 静态贴纸、`pip` 画中画 |
-| `decided_by` | `tools` 只有工具测量、`model` 工具 + 看图模型、`agent` 工具 + agent 看图复核、`human` 人工纠正 |
-| `flags` | `uncertain` 待确认、`disputed` 有分歧、`low_confidence` 低置信 |
-| `readers` | `tools`、`model`、`agent`、`human` |
-
-取值表以外的类别,生成方可以用 `x-` 开头的 id 自己扩展(如 `x-game_capture`),读的一方不认识时当作未知处理。主题文件也一样:生成方自己的主题用 `x-<名字>.md`。
-
-时间线里的值是写给模型读的,跟着包的语言走(中文或英文);程序要用稳定的 id,就读镜头文件的前置信息,或者取 `made~` 括号里的类别 id。
-
-## 一致性要求
-
-一个目录是合格的 VIDEO.md 拆片包,当且仅当:
-
-1. 根目录有 `VIDEO.md`,前置信息符合 schema 里的 `card`。
-2. `VIDEO.md` 地图里列出的每个路径都存在。
-3. `video/` 下每个 `.md` 都有前置信息,符合 `part`(镜头文件符合 `shot`)。
-4. `video/timeline.md` 有 ```` ```videomd-timeline ```` 代码块;块里每一行都符合时间线语法,编号严格递增,结束时间不早于开始时间,行数等于卡片里的 `shots`。
-5. 时间线每一行在 `video/shots/` 下有同编号的镜头文件,两边的编号和时间一致(允许 0.06 秒误差),`made~` 括号里的 id 和 `inferred.made` 一致。
-6. 镜头文件 `frames` 里的路径都存在。
-
-schema 在 `rea_video/videomd.schema.json`(JSON Schema 2020-12)。检查一个目录:
-
-```bash
-rea-video videomd out/ref --check # 合格时输出“符合 VIDEO.md 规范”,否则逐条列出问题,退出码 1
-```
-
-写拆片包的一方必须满足上面全部规则;读的一方遇到不认识的字段、键、主题文件时忽略,不报错。
-
-## 版本
-
-`videomd: 1` 是当前版本。只加字段、加键、加主题文件时版本号不变,读的一方忽略不认识的内容;改了已有字段的含义或时间线语法时升版本号。
diff --git a/pyproject.toml b/pyproject.toml
index c532d88..eba9ee6 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -14,6 +14,7 @@ dependencies = [
"opencv-python-headless>=4.8,<5",
"Pillow>=9.0",
"PyYAML>=6.0",
+ "videomd>=1.1", # VIDEO.md 拆片包的校验和读取(https://github.com/videomd/videomd)
"onnxruntime>=1.16", # 人声/配乐/音效分离(UVR MDX-Net 约 67 MB + BandIt v2 约 149 MB,首次运行自动下载)
]
@@ -36,7 +37,7 @@ rea-video = "rea_video.cli:main"
include = ["rea_video*"]
[tool.setuptools.package-data]
-rea_video = ["capabilities/*.yaml", "capabilities/*.json", "capabilities/*.md", "capabilities/models/*.yaml", "videomd.schema.json"]
+rea_video = ["capabilities/*.yaml", "capabilities/*.json", "capabilities/*.md", "capabilities/models/*.yaml"]
[tool.pytest.ini_options]
testpaths = ["tests"]
diff --git a/rea_video/cli.py b/rea_video/cli.py
index 6cb2e80..817d38d 100644
--- a/rea_video/cli.py
+++ b/rea_video/cli.py
@@ -551,7 +551,7 @@ def main(argv: list[str] | None = None) -> int:
rl = sub.add_parser("videomd", help="从 breakdown.json 重新生成给模型读的拆片包(VIDEO.md + video/);decompose 和 apply-review 会自动生成")
rl.add_argument("out_dir")
- rl.add_argument("--check", action="store_true", help="只校验目录是否符合 VIDEO.md 规范(docs/videomd.md),不重写")
+ rl.add_argument("--check", action="store_true", help="只校验目录是否符合 VIDEO.md 规范(https://github.com/videomd/videomd),不重写")
rl.set_defaults(func=cmd_videomd)
pd = sub.add_parser("pdf", help="把 report.html 打印成 report.pdf(用本机的 Chrome / Chromium / Edge,折叠内容全部展开)")
diff --git a/rea_video/videomd.py b/rea_video/videomd.py
index 56fa6d1..ae62d3f 100644
--- a/rea_video/videomd.py
+++ b/rea_video/videomd.py
@@ -8,7 +8,7 @@ The output directory is the package. Levels, each cheaper than the next:
L4 breakdown.json, shots/, stems/, sfx/, packaging/ raw data and media
Every file opens with front matter saying what it covers and roughly how many tokens it holds, so a reader can decide
before opening it. Paths are relative to the package root. In timeline lines a key ending in `~` is the tools'
-inference; keys without it are what is visible on screen or measured directly. The spec is docs/videomd.md.
+inference; keys without it are what is visible on screen or measured directly. The spec is https://github.com/videomd/videomd; reading and checking use the `videomd` package.
"""
from __future__ import annotations
@@ -28,13 +28,14 @@ VERSION = 1
ENTRY = "VIDEO.md"
DIR = "video"
BLOCK = "videomd-timeline"
+MAP_BLOCK = "videomd-map"
# producer-side values -> the neutral ids in the spec
DECIDED_BY = {"deterministic": "tools", "fused": "model", "fused_agent": "agent", "user": "human"}
OVERLAY_ID = {"huazi": "styled_text"}
# timeline keys, in line order; `~` = inferred by the tools
-KEYS = ("say", "seen", "cam", "over", "made~", "real~", "remake", "flag")
+KEYS = ("story", "seen", "camera", "overlay", "made~", "material~", "remake", "flag")
# ------------------------------------------------------------------ helpers ---------------------------------------
@@ -88,19 +89,19 @@ def timeline_line(r: dict, roles: dict, units: dict) -> str:
f = {}
n = roles.get(r["index"]) or {}
if n.get("role_zh") or n.get("point"):
- f["say"] = _one_line(join(x for x in (n.get("role_zh"), n.get("point")) if x), 48)
+ f["story"] = _one_line(join(x for x in (n.get("role_zh"), n.get("point")) if x), 48)
desc = (r.get("vlm") or r.get("review") or {}).get("description")
if desc:
f["seen"] = _one_line(desc, 60)
- f["cam"] = CAMERA_ZH.get((r.get("features") or {}).get("camera", "unknown"), "—")
+ f["camera"] = CAMERA_ZH.get((r.get("features") or {}).get("camera", "unknown"), "—")
if _layers(r) != "—":
- f["over"] = _layers(r)
- made = f"{base['label_zh']}({base['label']}) {base['confidence']:.0%}"
- alt = next(((k, v) for k, v in sorted(base["probs"].items(), key=lambda kv: -kv[1]) if k != base["label"] and v > 0), None)
+ f["overlay"] = _layers(r)
+ made = f"{base['label_zh']} {base['confidence']:.0%}"
+ alt = next(((k, v) for k, v in sorted(base["probs"].items(), key=lambda kv: -kv[1]) if k != base["label"] and v >= 0.01), None)
if alt and base["decided_by"] != "user":
made += T(" · 次选 {l} {p:.0%}", " · runner-up {l} {p:.0%}", l=LABEL_ZH[alt[0]], p=alt[1])
f["made~"] = made
- f["real~"] = _one_line(_origin(r), 40)
+ f["material~"] = _one_line(_origin(r), 40)
f["remake"] = _one_line(_route(r, units), 30)
flags = []
if base["decided_by"] == "user":
@@ -117,29 +118,13 @@ def timeline_line(r: dict, roles: dict, units: dict) -> str:
return " | ".join([head] + [f"{k} {f[k]}" for k in KEYS if f.get(k)])
-_RE_HEAD = re.compile(r"^#(\d+) (\d+(?:\.\d+)?)-(\d+(?:\.\d+)?)$")
-
-
-def parse_timeline_line(line: str) -> dict | None:
- """`#07 16.2-18.5 | seen … | made~ …` -> {"shot": 7, "start": 16.2, "end": 18.5, "seen": "…", "made~": "…"}; None if not a shot line."""
- parts = line.strip().split(" | ")
- m = _RE_HEAD.match(parts[0])
- if not m:
- return None
- out: dict = {"shot": int(m.group(1)), "start": float(m.group(2)), "end": float(m.group(3))}
- for p in parts[1:]:
- k, _, v = p.partition(" ")
- out[k] = v
- return out
-
-
def _legend() -> list[str]:
return [T("每行一个镜头:`#编号 起-止(秒) | 键 值 | …`。键后带 `~` 的是工具推断,不带的是画面里看得到或直接测得的。",
"One shot per line: `#<n> start-end (s) | key value | …`. A key ending in `~` is the tools' inference; keys without it are visible on screen or measured directly."),
- T("`say` 在叙事里的作用和讲的点 · `seen` 画面里看到的 · `cam` 运镜 · `over` 叠加层 · `made~` 制作方式(推断)· "
- "`real~` 素材来源(推断)· `remake` 复刻路线 · `flag` 需要复核",
- "`say` job in the story and the point · `seen` what is on screen · `cam` camera move · `over` overlays · `made~` how it was made (inferred) · "
- "`real~` material origin (inferred) · `remake` remake route · `flag` needs a second look"),
+ T("`story` 在叙事里的作用和讲的点 · `seen` 画面里看到的 · `camera` 运镜 · `overlay` 叠加层 · `made~` 制作方式(推断)· "
+ "`material~` 素材来源(推断)· `remake` 复刻路线 · `flag` 需要复核",
+ "`story` job in the story and the point · `seen` what is on screen · `camera` camera move · `overlay` overlays · `made~` how it was made (inferred) · "
+ "`material~` where the material came from (inferred) · `remake` remake route · `flag` needs a second look"),
T("某一镜的全部细节在 `{d}/shots/编号.md`(如 `{d}/shots/07.md`)。", "Full detail for a shot is in `{d}/shots/<n>.md` (e.g. `{d}/shots/07.md`).", d=DIR)]
@@ -194,17 +179,47 @@ def _card(b: dict) -> dict:
readers = ["tools"] + (["model"] if b["analysis"]["vlm"].get("used") else []) + (["agent"] if (b["analysis"].get("review") or {}).get("shots") else [])
if any(r["base"]["decided_by"] == "user" for r in b["shots"]):
readers.append("human")
+ source = {"file": src["filename"]}
+ digest = _sha256(src.get("path"))
+ if digest:
+ source["sha256"] = digest
+ source.update({"duration": src["duration"], "size": f"{src['width']}x{src['height']}", "fps": src["fps"], "aspect": src["aspect_ratio"]})
return {
- FORMAT: VERSION, "name": Path(src["filename"]).stem,
- "description": _one_line(s["verdict"].split(T(";", "; "))[0], 120),
- "source": {"file": src["filename"], "duration": src["duration"], "size": f"{src['width']}x{src['height']}", "fps": src["fps"], "aspect": src["aspect_ratio"]},
- "shots": len(b["shots"]), "confidence": s["confidence"],
- "made_mix": {m["label"]: m["ratio"] for m in s["production_mix"]},
- "readers": readers, "open_questions": len(entities.open_questions(b)), "lang": b.get("lang", "zh"),
+ FORMAT: VERSION, "name": slug(Path(src["filename"]).stem), "description": _description(b),
+ "source": source, "shots": len(b["shots"]), "lang": b.get("lang", "zh"),
+ "made_mix": {m["label"]: m["ratio"] for m in s["production_mix"]}, "confidence": s["confidence"],
+ "readers": readers, "open_questions": len(entities.open_questions(b)),
"generator": {"name": "rea-video", "version": __version__},
}
+def slug(stem: str) -> str:
+ """A card name: lowercase letters, digits and single hyphens, at most 64 characters."""
+ s = re.sub(r"[^a-z0-9]+", "-", stem.lower()).strip("-")[:64].strip("-")
+ return s or "video"
+
+
+def _description(b: dict) -> str:
+ """What the video is about first, then how it was made: an agent picks a package by this line."""
+ about = _one_line((b.get("whole_video_vlm") or {}).get("summary"), 600)
+ made = join(f"{m['label_zh']} {m['ratio']:.0%}" for m in b["summary"]["production_mix"])
+ made = T("制作方式(推断):{m}", "Made with (inferred): {m}", m=made)
+ return _one_line(f"{about} {made}" if about else made, 1000)
+
+
+def _sha256(path) -> str | None:
+ """sha256 of the whole source file, when it is still where the breakdown found it."""
+ import hashlib
+
+ if not path or not Path(path).is_file():
+ return None
+ h = hashlib.sha256()
+ with open(path, "rb") as fh:
+ for chunk in iter(lambda: fh.read(1 << 20), b""):
+ h.update(chunk)
+ return h.hexdigest()
+
+
def _overview(b: dict, files: list[tuple[str, str, str, int]]) -> str:
s = b["summary"]
w = b.get("whole_video_vlm") or {}
@@ -228,9 +243,10 @@ def _overview(b: dict, files: list[tuple[str, str, str, int]]) -> str:
if len(qs) > 8:
L.append(T("- 另有 {n} 处,见 `{d}/timeline.md` 里带 `flag` 的行", "- {n} more, see the `flag` lines in `{d}/timeline.md`", d=DIR, n=len(qs) - 8))
L += ["", T("## 地图", "## Map"), "",
- T("先读本页;要细节时按下表只打开需要的文件。路径相对本目录。", "Read this page first; for detail, open only the file you need. Paths are relative to this directory."), "",
- T("| 文件 | 里面有什么 | 什么时候读 | 约 token |", "| File | What is in it | When to read it | ~tokens |"), "|---|---|---|---|"]
- L += [f"| `{p}` | {title} | {when} | {n or '—'} |" for p, title, when, n in files]
+ T("先读本页;要细节时只打开需要的文件。每行是 `路径 | 约 token | 里面有什么 · 什么时候读`,路径相对本目录。",
+ "Read this page first; for detail, open only the file you need. Each line is `path | ~tokens | what is in it · when to read it`; paths are relative to this directory."), "",
+ f"```{MAP_BLOCK}"]
+ L += [f"{p} | {n if n else '-'} | {_one_line(title)} · {_one_line(when)}" for p, title, when, n in files] + ["```"]
L += ["", T("## 读法", "## How to read"), ""] + [f"- {x}" for x in _legend()] + [
T("- 「看到的」可以对着截图核实;「推断」是工具和看图模型的判断,依据写在每镜文件的「判断依据」里,两者对不上时以截图为准。",
"- What is “seen” can be checked against the frames; what is “inferred” is the tools' and image readers' judgement, with the basis in each shot file. When they disagree, trust the frames.")]
@@ -267,115 +283,37 @@ def write(b: dict, out: Path) -> Path:
text = _shot_file(r)
(d / "shots" / f"{_shot_name(r['index'])}.md").write_text(text, encoding="utf-8")
shot_tokens += tokens(text)
- files.append((f"{DIR}/shots/01.md … {len(b['shots']):02d}.md", T("逐镜细节", "Per-shot detail"),
+ files.append((f"{DIR}/shots/*.md", T("逐镜细节,token 是每个文件的平均值", "Per-shot detail, tokens per file on average"),
T("核实某一镜:看得到的、推断和依据、提示词、帧图", "checking one shot: what is seen, the inference and its basis, prompts, frames"),
shot_tokens // max(1, len(b["shots"]))))
- files.append(("breakdown.json", T("完整原始数据", "Full raw data"), T("程序读取;模型一般不用打开", "for programs; a model rarely needs it"),
- tokens((out / "breakdown.json").read_text(encoding="utf-8")) if (out / "breakdown.json").is_file() else 0))
- media = [p for p in ("shots/", "stems/", "sfx/", "packaging/", "storyboard.jpg", "audio.png") if (out / p.rstrip("/")).exists()]
- if media:
- files.append((", ".join(media), T("截图、分轨音频、字幕文件", "frames, audio stems, subtitle files"),
- T("看图核实、复刻时当参考", "checking by eye, references for the remake"), 0))
+ if (out / "breakdown.json").is_file():
+ files.append(("breakdown.json", T("完整原始数据", "Full raw data"), T("程序读取;模型一般不用打开", "for programs; a model rarely needs it"),
+ tokens((out / "breakdown.json").read_text(encoding="utf-8"))))
+ for rel, what, when in (
+ ("shots/", T("每镜的联系表和首尾帧", "contact sheet, first and last frame of each shot"), T("看图核实", "checking by eye")),
+ ("storyboard.jpg", T("全片故事板", "storyboard of the whole video"), T("一眼看全片", "the whole video at a glance")),
+ ("stems/", T("人声、配乐、音效分轨", "voice, music and effects stems"), T("听声音、复刻配音配乐", "listening, remaking the sound")),
+ ("sfx/", T("每处音效的试听片段", "a clip of each sound effect"), T("找同款音效", "finding matching effects")),
+ ("packaging/", T("字幕文件、包装时间轴、贴纸截图", "subtitle files, packaging timeline, sticker frames"), T("复刻字幕和包装", "remaking subtitles and packaging")),
+ ("audio.png", T("声音波形和节拍图", "waveform and beat chart"), T("看节奏", "seeing the rhythm"))):
+ if (out / rel.rstrip("/")).exists():
+ files.append((rel, what, when, 0))
entry = out / ENTRY
entry.write_text(_front(_card(b), _overview(b, files)), encoding="utf-8")
return entry
-# ------------------------------------------------------------------ read (reference reader) ------------------------
-
-def read_file(path: Path) -> tuple[dict, str]:
- """(front matter, body) of one file in the package."""
- text = Path(path).read_text(encoding="utf-8")
- if not text.startswith("---\n"):
- return {}, text
- fm, _, body = text[4:].partition("\n---\n")
- return yaml.safe_load(fm) or {}, body.strip()
-
+# ------------------------------------------------------------------ read and check: the videomd reference library --
def read(root: Path) -> dict:
- """The package as data: {"card", "timeline": [shot dicts], "shots": {n: front matter}}. For programs that consume one."""
- root = Path(root)
- card, _ = read_file(root / ENTRY)
- _, tl = read_file(root / DIR / "timeline.md")
- shots = {}
- for p in sorted((root / DIR / "shots").glob("*.md")):
- fm, _ = read_file(p)
- shots[fm.get("shot")] = fm
- return {"card": card, "timeline": [x for x in map(parse_timeline_line, tl.splitlines()) if x], "shots": shots}
-
+ """The package as data: {"card", "map", "timeline": [shot dicts], "shots": {n: front matter}}."""
+ import videomd
-# ------------------------------------------------------------------ check (conformance) ----------------------------
-
-SCHEMA = Path(__file__).with_name("videomd.schema.json")
-_RE_LINE = re.compile(r"^#(\d+) (\d+(?:\.\d+)?)-(\d+(?:\.\d+)?)((?: \| [a-z]+~? [^|]+?)*)$")
-_RE_ID = re.compile(r"\(([a-z_0-9]+)\)")
-
-
-def _schema_errors(data: dict, part: str, where: str) -> list[str]:
- try:
- import jsonschema
- except ImportError: # the structural checks below still run; the schema adds field-level detail when installed
- return []
- import json
-
- schema = json.loads(SCHEMA.read_text(encoding="utf-8"))
- v = jsonschema.Draft202012Validator({**schema, "$ref": f"#/$defs/{part}"})
- return [f"{where}: {'/'.join(map(str, e.absolute_path)) or '(root)'}: {e.message}" for e in v.iter_errors(data)]
+ return videomd.read(root)
def check(root: Path) -> list[str]:
- """Problems that make `root` a non-conforming package (empty list = conforms). See docs/videomd.md, “Conformance”."""
- root = Path(root)
- entry_name, D = ENTRY, DIR
- errs: list[str] = []
- entry = root / entry_name
- if not entry.is_file():
- return [f"{ENTRY} missing"]
- card, body = read_file(entry)
- errs += _schema_errors(card, "card", entry_name)
- for p in re.findall(r"^\| `([^`]+)` \|", body, re.M):
- if "…" not in p and "," not in p and not (root / p).exists():
- errs.append(f"{entry_name}: map lists {p}, which does not exist")
- for p in sorted((root / D).glob("*.md")):
- fm, _ = read_file(p)
- errs += _schema_errors(fm, "part", f"{D}/{p.name}")
- if not fm:
- errs.append(f"{D}/{p.name}: no front matter")
- tl_path = root / D / "timeline.md"
- if not tl_path.is_file():
- return errs + [f"{D}/timeline.md missing"]
- _, tl = read_file(tl_path)
- m = re.search(rf"```{BLOCK}\n(.*?)\n?```", tl, re.S)
- if not m:
- return errs + [f"{D}/timeline.md: no ```{BLOCK} block"]
- rows = []
- for ln in [x for x in m.group(1).split("\n") if x.strip()]:
- if not _RE_LINE.match(ln):
- errs.append(f"{D}/timeline.md: not a timeline line: {ln[:80]}")
- continue
- rows.append(parse_timeline_line(ln))
- if card.get("shots") is not None and len(rows) != card["shots"]:
- errs.append(f"{D}/timeline.md: {len(rows)} lines, card says {card['shots']} shots")
- last = 0
- for x in rows:
- if x["shot"] <= last:
- errs.append(f"{D}/timeline.md: #{x['shot']:02d} out of order")
- if x["end"] < x["start"]:
- errs.append(f"{D}/timeline.md: #{x['shot']:02d} ends before it starts")
- last = x["shot"]
- sp = root / D / "shots" / f"{_shot_name(x['shot'])}.md"
- if not sp.is_file():
- errs.append(f"{D}/shots/{sp.name} missing")
- continue
- fm, _ = read_file(sp)
- errs += _schema_errors(fm, "shot", f"{D}/shots/{sp.name}")
- t = fm.get("time") or [None, None]
- if fm.get("shot") != x["shot"] or t[0] is None or abs(t[0] - x["start"]) > 0.06 or abs(t[1] - x["end"]) > 0.06:
- errs.append(f"{D}/shots/{sp.name}: shot number or time differs from the timeline")
- made = _RE_ID.search(x.get("made~", ""))
- if made and made.group(1) != (fm.get("inferred") or {}).get("made"):
- errs.append(f"{D}/shots/{sp.name}: inferred.made differs from the timeline's made~")
- for k, fp in (fm.get("frames") or {}).items():
- if not (root / fp).is_file():
- errs.append(f"{D}/shots/{sp.name}: frames.{k} {fp} does not exist")
- return errs
+ """Problems that make `root` a non-conforming package (empty list = conforms), per the VIDEO.md spec."""
+ import videomd
+
+ return videomd.check(root)
diff --git a/rea_video/videomd.schema.json b/rea_video/videomd.schema.json
deleted file mode 100644
index b720ca4..0000000
--- a/rea_video/videomd.schema.json
+++ /dev/null
@@ -1,104 +0,0 @@
-{
- "$schema": "https://json-schema.org/draft/2020-12/schema",
- "$id": "https://github.com/videomd/videomd/blob/main/schema/videomd-1.schema.json",
- "title": "VIDEO.md front matter",
- "description": "Front matter of the files in a VIDEO.md package, version 1. Unknown fields are allowed everywhere: readers ignore what they do not know. Ids starting with x- are producer extensions.",
- "$defs": {
- "version": {"const": 1},
- "ext": {"type": "string", "pattern": "^x-[a-z0-9][a-z0-9_-]*$"},
- "made": {
- "description": "How the base picture was made",
- "anyOf": [
- {"enum": ["live_action", "ai_video", "avatar", "cg_3d", "code_render", "screen_capture", "still_motion", "static_hold", "anim_2d", "stop_motion", "film_footage"]},
- {"$ref": "#/$defs/ext"}
- ]
- },
- "camera": {
- "anyOf": [
- {"enum": ["static", "static_with_subject_motion", "planar_zoom_pan", "handheld_like", "smooth_move", "unknown"]},
- {"$ref": "#/$defs/ext"}
- ]
- },
- "reader": {"anyOf": [{"enum": ["tools", "model", "agent", "human"]}, {"$ref": "#/$defs/ext"}]},
- "prob": {"type": "number", "minimum": 0, "maximum": 1},
- "tokens": {"type": "integer", "minimum": 0},
- "path": {"type": "string", "description": "Relative to the package root", "pattern": "^(?!/)(?!.*\\.\\./)"},
-
- "card": {
- "type": "object",
- "required": ["videomd", "name", "description", "source", "shots", "made_mix", "lang"],
- "properties": {
- "videomd": {"$ref": "#/$defs/version"},
- "name": {"type": "string", "minLength": 1},
- "description": {"type": "string", "minLength": 1, "maxLength": 200},
- "source": {
- "type": "object",
- "required": ["file", "duration"],
- "properties": {
- "file": {"type": "string"},
- "url": {"type": "string"},
- "duration": {"type": "number", "minimum": 0},
- "size": {"type": "string", "pattern": "^\\d+x\\d+$"},
- "fps": {"type": "number", "minimum": 0},
- "aspect": {"type": "string"}
- }
- },
- "shots": {"type": "integer", "minimum": 0},
- "confidence": {"$ref": "#/$defs/prob"},
- "made_mix": {"type": "object", "propertyNames": {"$ref": "#/$defs/made"}, "additionalProperties": {"$ref": "#/$defs/prob"}},
- "readers": {"type": "array", "items": {"$ref": "#/$defs/reader"}, "uniqueItems": true},
- "open_questions": {"type": "integer", "minimum": 0},
- "lang": {"type": "string", "pattern": "^[a-z]{2}(-[A-Za-z]+)?$"},
- "generator": {
- "type": "object",
- "required": ["name"],
- "properties": {"name": {"type": "string", "minLength": 1}, "version": {"type": "string"}}
- }
- }
- },
-
- "part": {
- "type": "object",
- "required": ["videomd", "part", "tokens"],
- "properties": {
- "videomd": {"$ref": "#/$defs/version"},
- "part": {"type": "string", "pattern": "^(x-)?[a-z][a-z0-9_]*$", "description": "timeline, content, cast, sound, look, packaging, remake; x-<name> for producer topics"},
- "tokens": {"$ref": "#/$defs/tokens"},
- "shots": {"type": "integer", "minimum": 0}
- },
- "if": {"properties": {"part": {"const": "timeline"}}},
- "then": {"required": ["shots"]}
- },
-
- "shot": {
- "type": "object",
- "required": ["videomd", "part", "shot", "time", "inferred", "tokens"],
- "properties": {
- "videomd": {"$ref": "#/$defs/version"},
- "part": {"const": "shot"},
- "shot": {"type": "integer", "minimum": 1},
- "time": {"type": "array", "items": {"type": "number", "minimum": 0}, "minItems": 2, "maxItems": 2},
- "camera": {"$ref": "#/$defs/camera"},
- "overlays": {"type": "array", "items": {"type": "string"}, "uniqueItems": true,
- "description": "subtitle, title, label, styled_text, static_graphic, layout_template, animated_sticker, static_sticker, pip; open: more may be added"},
- "inferred": {
- "type": "object",
- "required": ["made", "p"],
- "properties": {
- "made": {"$ref": "#/$defs/made"},
- "p": {"$ref": "#/$defs/prob"},
- "alternatives": {"type": "object", "propertyNames": {"$ref": "#/$defs/made"}, "additionalProperties": {"$ref": "#/$defs/prob"}},
- "decided_by": {"$ref": "#/$defs/reader"},
- "real_material": {"type": "boolean"}
- }
- },
- "flags": {"type": "array", "items": {"anyOf": [{"enum": ["uncertain", "disputed", "low_confidence"]}, {"$ref": "#/$defs/ext"}]}, "uniqueItems": true},
- "frames": {
- "type": "object",
- "properties": {"sheet": {"$ref": "#/$defs/path"}, "first": {"$ref": "#/$defs/path"}, "last": {"$ref": "#/$defs/path"}}
- },
- "tokens": {"$ref": "#/$defs/tokens"}
- }
- }
- }
-}
diff --git a/skills/rea-video/SKILL.md b/skills/rea-video/SKILL.md
index cb48c8a..bc068f5 100644
--- a/skills/rea-video/SKILL.md
+++ b/skills/rea-video/SKILL.md
@@ -37,7 +37,7 @@ rea-video --env-file <你的 .env> decompose ref.mp4 -o out/ref --vlm --lang <zh
rea-video summary out/ref/breakdown.json
```
-**省 token,按拆片包逐层读**(格式见仓库 `docs/videomd.md`):先读 `out/ref/VIDEO.md`(卡片 + 概览 + 地图,约 2k token),多数问题到这里就能答;要按镜头回答时读 `video/timeline.md`(一行一镜,键名带 `~` 的是推断,不带的是画面里看得到的);要核实某一镜再打开 `video/shots/<编号>.md` 和它 `frames` 里的截图;某一方面(声音、包装、复刻方案)按地图打开对应的 `video/*.md`。不要读 `breakdown.json`(几十万字)或 `report.md`(那是给人看的)。复核时每镜看 `shots/shot_XXX.jpg` 联系表就够(已含首 / 中 / 尾帧),`_first` / `_last` 是复刻时给生成模型参照用的,不用另开。旧的输出目录没有 `VIDEO.md` 时运行 `rea-video videomd out/ref` 补出来。
+**省 token,按拆片包逐层读**(格式见仓库 `docs/videomd.md`;地图一行一个文件:`路径 | 约 token | 内容`):先读 `out/ref/VIDEO.md`(卡片 + 概览 + 地图,约 2k token),多数问题到这里就能答;要按镜头回答时读 `video/timeline.md`(一行一镜,键名带 `~` 的是推断,不带的是画面里看得到的);要核实某一镜再打开 `video/shots/<编号>.md` 和它 `frames` 里的截图;某一方面(声音、包装、复刻方案)按地图打开对应的 `video/*.md`。不要读 `breakdown.json`(几十万字)或 `report.md`(那是给人看的)。复核时每镜看 `shots/shot_XXX.jpg` 联系表就够(已含首 / 中 / 尾帧),`_first` / `_last` 是复刻时给生成模型参照用的,不用另开。旧的输出目录没有 `VIDEO.md` 时运行 `rea-video videomd out/ref` 补出来。
### 看图复核并入(能看图的 agent 必做,开了 VLM 也建议做低置信镜头)
diff --git a/tests/test_videomd.py b/tests/test_videomd.py
index 1e13302..9ac2c2f 100644
--- a/tests/test_videomd.py
+++ b/tests/test_videomd.py
@@ -2,6 +2,8 @@
import json
import re
+import videomd as spec
+
from rea_video import videomd
from rea_video.i18n import set_lang
from rea_video.report import write_reports
@@ -13,19 +15,17 @@ def test_package_levels_and_map(breakdown, tmp_path): # noqa: F811
b, out = breakdown
set_lang("zh")
write_reports(_with_vlm(b), out)
- card, body = videomd.read_file(out / videomd.ENTRY)
+ card, body = spec.read_file(out / videomd.ENTRY)
# L0: the card is small and says what the video is and how sure
assert card["videomd"] == videomd.VERSION and card["generator"]["name"] == "rea-video" and card["shots"] == len(b["shots"]) and card["description"]
assert videomd.tokens(json.dumps(card, ensure_ascii=False)) < 300
assert abs(sum(card["made_mix"].values()) - 1) < 0.02
# L1: every file the map names exists; sizes are given so a reader can choose
- rows = re.findall(r"^\| `([^`]+)` \|", body, re.M)
- assert "video/timeline.md" in rows and "breakdown.json" in rows
- for p in rows:
- if "…" not in p and "," not in p:
- assert (out / p).exists(), p
+ rows = [x["path"] for x in spec.read(out)["map"]]
+ assert "video/timeline.md" in rows and "video/shots/*.md" in rows and "breakdown.json" in rows
+ assert card["name"] == videomd.slug(card["name"]) and len(card["description"]) <= 1024
for p in out.glob("video/*.md"):
- fm, text = videomd.read_file(p)
+ fm, text = spec.read_file(p)
assert fm["videomd"] == videomd.VERSION and fm["tokens"] > 0 and "<details>" not in text
assert len(list((out / "video" / "shots").glob("*.md"))) == len(b["shots"])
@@ -38,7 +38,7 @@ def test_timeline_lines_parse_and_mark_inference(breakdown): # noqa: F811
tl = pkg["timeline"]
assert [x["shot"] for x in tl] == [r["index"] for r in b["shots"]]
for x, r in zip(tl, b["shots"]):
- assert abs(x["start"] - r["start"]) < 0.06 and f"({r['base']['label']})" in x["made~"]
+ assert abs(x["start"] - r["start"]) < 0.06 and x["made~"].startswith(r["base"]["label_zh"])
assert set(x) - {"shot", "start", "end"} <= set(videomd.KEYS)
# the per-shot front matter is the machine view of the same verdict
for r in b["shots"]:
@@ -48,9 +48,7 @@ def test_timeline_lines_parse_and_mark_inference(breakdown): # noqa: F811
def test_shot_line_escapes_separators():
assert videomd._one_line("a | b|c\nd") == "a / b/c d"
- assert videomd.parse_timeline_line("#07 16.2-18.5 | seen 红圈 | made~ 录屏(screen_capture) 44%") == {
- "shot": 7, "start": 16.2, "end": 18.5, "seen": "红圈", "made~": "录屏(screen_capture) 44%"}
- assert videomd.parse_timeline_line("## heading") is None
+ assert videomd.slug("Salted_Egg 最终版") == "salted-egg" and videomd.slug("最终版") == "video"
def test_rewrite_drops_stale_shot_files(breakdown, tmp_path): # noqa: F811
@@ -81,9 +79,9 @@ def test_english_package(breakdown, tmp_path): # noqa: F811
videomd.write(b, out)
finally:
set_lang("zh")
- _, body = videomd.read_file(out / videomd.ENTRY)
+ _, body = spec.read_file(out / videomd.ENTRY)
# the package's own words follow the language (the verdict keeps the language the breakdown was made in)
- assert "## Map" in body and "## How to read" in body and "| File | What is in it |" in body
+ assert "## Map" in body and "## How to read" in body and "Each line is `path | ~tokens |" in body
def test_check_accepts_a_written_package_and_names_what_breaks(breakdown, tmp_path): # noqa: F811