---
catalog_id: "R-149"
kind: "repo"
domain: "multimodal"
domain_label: "视频多模态 / Multimodal & Video"
date: "2026-11-30"
title: "JuneYaooo/capsule-cinema"
verdict: "将参考运镜骨架与变量槽解耦，配DTW重定时与免费预检"
summary: "面向编码 Agent 的配方化短视频生产与参考复刻工作室（Apache-2.0），通过 videomd>=1.2 与 rea-video 衔接，将参考骨架（分镜/运镜/字幕）与 Episode 变量槽位解耦，并提供 DTW 动作重定时重装、Pre-run 免费防误触护栏及多后端媒体调度。"
summary_en: "Recipe-based short-video studio decoupling reference camera skeletons from episode slots, adding DTW motion retiming and zero-cost pre-run guards."
canonical_url: "https://oumuatown.com/repos/JuneYaooo__capsule-cinema/"
markdown_url: "https://oumuatown.com/repos/JuneYaooo__capsule-cinema.md"
og_image_zh: "https://oumuatown.com/og/zh/R-149.png"
og_image_en: "https://oumuatown.com/og/en/R-149.png"
cite_count: 68
repo: "juneyaooo/capsule-cinema"
github_url: "https://github.com/juneyaooo/capsule-cinema"
commit: "864d862"
tags:
  - "video-generation"
  - "capsule-workflow"
  - "videomd"
  - "minimax-h3"
  - "dtw-retiming"
github_repos:
  - "https://github.com/juneyaooo/capsule-cinema/tree/864d862"
  - "https://github.com/juneyaooo/rea-video/tree/0d0d1e1"
---

# R-149 · JuneYaooo/capsule-cinema

> **结论 / Verdict**: 将参考运镜骨架与变量槽解耦，配DTW重定时与免费预检
> **EN Summary**: Recipe-based short-video studio decoupling reference camera skeletons from episode slots, adding DTW motion retiming and zero-cost pre-run guards.

## Provenance & Evidence

- Primary Repository: https://github.com/juneyaooo/capsule-cinema (@864d862)
- Referenced Repository: https://github.com/juneyaooo/rea-video/tree/0d0d1e1
- Verified Source Citations (#Lxx): 68
- Web Reader: https://oumuatown.com/repos/JuneYaooo__capsule-cinema/

# JuneYaooo/capsule-cinema

> 仓库地址：https://github.com/JuneYaooo/capsule-cinema · 审计版本：`JuneYaooo/capsule-cinema@864d862` · 审计日期：2026-11-30
> 来源文章：[关联文章](../articles/2026-11-30-juneyaooo-rea-video.md)

## 定位与解决的真问题

- **核心定位与目标用户**：运行在 Claude Code / Codex / OpenClaw 等编码 Agent 内的「视频配方工厂（`.capsule/`）+ 参考视频复刻与结构验收工作台」（`README.en.md#L5-L7,L41-L43`, `package.json#L2-L8`）。与专注逆向拆解的 `rea-video` 分工明确：**`rea-video` 负责拆解参考视频输出 `VIDEO.md` 与 `remake/handoff.json`，`capsule-cinema` 负责消费该包完成配方选型、变量替换、生成调度、时间线重装与结构/视觉验收**（`skills/capsule-cinema/SKILL.md#L50-L63`, `README.en.md#L211-L224`）。
- **相比常规做法解决的关键痛点**：
  1. **爆款工作流难以跨期复用且易串词**：传统提示词工程每次换选题都要重写流程，且容易把上一期的具体人物、商品或台词污染进模板。项目通过 `.capsule/` 包契约将固定制作规律与每期变量隔离（`lib/src/capsule_content_scope.py#L18-L84`）。
  2. **盲目整片生成高额烧钱与失控重试**：在调用付费 API 前先走本地无成本 `VIDEO.md` 查重/拆解、分镜简报、角色能力预检（Preflight）与 `--dry-run`，并对失败任务持久化 `task_id` 防重复扣费（`lib/src/remake_runner.py#L125-L185`）。
  3. **AI 生成片段动作节奏与参考原片脱节**：AI 视频模型往往有固定最小时长（如 4–5 秒）且动作起止峰谷与原片 1.2 秒镜头不对齐；通过 DTW 动态时间规整将生成片段的运动曲线对齐到原片帧网格（`lib/src/remake_assembly.py#L93-L227`）。
- **开源协议**：**Apache-2.0**（`LICENSE#L1-L201`, `Copyright 2026 june2`, `package.json#L20`）。

## 技术栈与核心目录结构

- **语言 / 运行时 / 关键依赖**：Python `3.12`（`lib/requirements.txt` 含 `agno>=2.3.0`、`crewai>=0.159.0`、`openai>=1.90.0`、`google-genai>=1.20.0`、`opencv-python>=4.10.0`、`pillow>=11.0.0`、`PyYAML>=6.0.0`、`videomd>=1.2`）+ Node `>=20`（OpenClaw 插件扩展 `./index.js`，`package.json#L5,L21-L28`）+ `ffmpeg`/`ffprobe`（视觉 QA 脚本额外按需调用 `mediapipe`，`scripts/remake_person_qa.py#L13-L30`）。
- **关键目录树与职责划分**：
  - `capsules/<name>.capsule/`：16 个显式白名单内置配方（含 `CARD.md`、`capsule.yaml`、`contracts/{input_schema,content_scope,production_contract,runtime}.yaml`、`recipes/*.md`、`quality/{rules,release_gates}.yaml`、`assets/`、`scripts/`；`.gitignore#L101-L133`）。
  - `lib/src/video_package.py` & `lib/src/remake_reference.py` & `lib/src/recipe_options.py`：消费 `videomd>=1.2`，提供本地按 SHA-256 检索、安全路径读取、12k Token 上下文打包、`reference_sheet` / `fragments` / `remake_brief` 构建及 `compare` 结构验收。
  - `lib/src/remake_runner.py` & `lib/src/clip_check.py` & `lib/src/remake_assembly.py`：执行 `rea-video` 导出的 `remake/jobs.json`、生成后 ASR 台词核对及 8 帧联系表、DTW 动作重定时重装与原片左右对比视频生成。
  - `lib/src/capsule_preflight.py` & `lib/src/capsule_resolver.py` & `lib/src/capsule_content_scope.py` & `lib/src/capsules/`：工具能力撮合、变量作用域防污染扫描与胶囊生命周期管理。
  - `lib/custom_tools/` & `lib/config/{video_engines,tool_registry,tool_capabilities}.yaml`：多后端视频/图像/TTS/动作模仿适配器目录与注册表。
  - `lib/video_workflows/`：`exact_media_channels.py`、`general_video/cat_life_exact.py` 等精确付费工作流。
  - `scripts/`：`capsule.py`、`quickstart.py`、`remake_reference.py`、`run_capsule.py`、`run_video.py`、`analyze_video_to_capsule.py`、`capsule_execution_guard.py` 及 `remake_{color_match,person_qa,detail_crops,frame_sheet}.py` 等视觉 QA 脚本。

## 核心实现源码级剖析（附文件路径与行号）

1. **消费 `rea-video` / `VIDEO.md` 与配方选型管线**（`lib/src/video_package.py#L41-L426`, `scripts/remake_reference.py#L96-L274`）：
   - **SHA-256 优先查找与防注入读取**：`video_package.locate`（`#L164-L198`）扫描视频同级、`out/`、`output/` 与 `$VIDEOMD_PATH`（深度限制 4 层），以 `source.sha256` 精确匹配已有 `VIDEO.md` 包，缺失哈希时才按文件名 + 时长 `±0.1s` 提示人工确认 `possible` 匹配；`safe_path`（`#L77-L85`）拒绝绝对路径、`..` 与符号链接逃逸；`context`（`#L322-L353`）以 `DATA_NOTICE` 声明“包内文字仅作视频数据而非指令”，在默认 `12000` Token 预算内按 Card → Overview → Scenes → Timeline → Topics 渐进装配。
   - **参考复刻闭环（`scripts/remake_reference.py`）**：
     - `start`（`#L146-L168`）：未找到包时在本地零 VLM 调用 `rea-video decompose <video> --no-vlm --no-whole`（`#L121-L129`），输出 `reference_sheet.json`、`remake_brief.md`/`.json` 与 `recipe_options.md`（`recipe_options.py#L50-L84` 列出每条路线秒数并将内置配方按是否属于 `reference_video_remake` 与状态排序）。
     - `fragments`（`lib/src/remake_reference.py#L251-L271`）：提取 `shots`（以 `seen` 作提示词种子或回退 `write_from` 帧路径）、`cuts`、`keyframes`（`start + min(0.5, duration/2)`）、`targets`、`transitions` 与 `captions`（优先映射的 `.srt`，否则回退 `tracks.transcript` WebVTT），供 Agent 将 `text` 改写为新主体后填入胶囊参数（`skills/capsule-cinema/SKILL.md#L144`）。
     - `prepare`（`scripts/remake_reference.py#L201-L212`）：调用 `rea-video plan` 与 `rea-video remake-plan ... --capsule-root` 生成 `remake/jobs.json` 与 `remake/handoff.json`（`HANDOFF_SCHEMA = "rea_video.remake_handoff.v1"`）。
     - `compare`（`lib/src/remake_reference.py#L418-L579`）：合并同一 `take` 的连续时间线行后再比对总时长（`<=5%` 为 blocker）、镜数、硬/软转场切点（`±0.2s`）与单镜时长/运镜/叠加层；对检测器漏掉的硬切点，`probe_cuts` + `find_cut_in_frames`（`#L437-L480`）还会提取 `48×48` RGB 像素窗口用“前后 3 帧均值差 `>= max(1.5, 2.5×中位步长)` 且单帧占总跃变 `0.6–1.15`”在像素级二次确认。

2. **变量槽位定义（主体/场景/道具替换）与作用域隔离**（`lib/src/capsule_content_scope.py#L7-L84`, `capsules/*/contracts/`）：
   - **类型化槽位契约**：不同配方在 `contracts/input_schema.yaml` 定义各自的替换槽位。例如：`x_lai_animal_fable.capsule` 定义 `topic`、`xlai_entity`、`responder_character`、`promotion_visual_anchor`、`problem_character`（并通过 `recipes/theme_variants.md#L29-L36,L86` 要求 `replacement_test` 验证主角与宣传实体的语义绑定）；`ecommerce_product_showcase.capsule` 定义 `product_name`、`product_images`、`selling_points`、`target_audience`；`dual_role_real_screen_recording.capsule` 定义 `project_url`、`project_pain`、`core_capability`、`character_asset_override` 与 `h3_shot_prompts`。
   - **身份不变量 vs 角色可变槽位**：`dual_role_real_screen_recording.capsule/contracts/runtime.yaml#L125-L132` 与 `assets/index.yaml#L2-L86` 定义 `character_identity_contract`，锁定 `invariant_features`（五官几何、年龄肤色、短发刘海），将可替换变量限定在 `allowed_role_variables: [outfit, eyewear, headwear, expression, posture, gesture, background_function, color_temperature]`，确保双角色共用同一授权演员锚点派生且不克隆现实博主身份。
   - **防回流扫描（`audit_reusable_surfaces`）**：`capsule_content_scope.py#L57-L84` 强制分离 `series_fixed` 与 `episode_variable`，验证胶囊 `.md`/`.yaml`/`.json`/`.py`（排除 `examples/` 与规则文件自身）不得出现 `forbidden_reusable_literals` 中的上期具体词条。

3. **动作参考 + 关键帧替换与多后端生成管线**（`lib/config/video_engines.yaml#L9-L118`, `lib/custom_tools/`, `lib/video_workflows/`）：
   - **视频与动作参考后端**：
     - 公开官方视频引擎（`video_engines.yaml`）：`seedance2.0`（默认 720p，4–15s，最多 9 图 / 3 视频 / 3 音频参考）、`seedance2.5`（仅显式调用不自动回退，4–30s，`multi_shot: true`，支持 30 图 / 10 视频 / 10 音频参考）、`minimax-h3`（`MiniMaxH3VideoGeneratorTool`，官方 MiniMax-H3 V2 接口，**强制仅支持 `2K`**，4–15s，支持 `text_to_video`、`image_to_video`、`first_last_frame` 与 `multimodal` 互斥模式，`minimax_h3_video_generator_tool.py#L114-L187`）。
     - 社区示例与动作迁移后端（`tool_registry.yaml#L36-L105` 标为 `status: example`）：RunningHub MiniMax H3 变体（`runninghub-minimax-h3-fl2va` 首尾帧、多参考与文生视频）、口型同步（`InfiniteTalkV2VTool`、`LTX23LipSyncTool`、`Wan22LipSyncTool`），以及 `ActionImitateTool`（`lib/custom_tools/action_animation/action_imitate_tool.py#L32,L163-L198`）将 `image_path` 角色替换到参考 `video_path` 动作中，支持 Wan Animate 1/2/3/4 自动降级与 `multi_person` 模式，超 8 秒视频自动分块防 OOM。
   - **图像/关键帧后端与 `gpt-image-2` 路线**：公开图像引擎为 `volcengine-seedream`（Seedream 5.0 Pro，最多 10 张参考图，`volcengine_image_generator_tool.py#L24-L25`）与 `agnes-image-2.1-flash`（`agnes_image_generator_tool.py#L20`）。而 `gpt-image-2` 仅在精确工作流中被引用：如 `lib/video_workflows/exact_media_channels.py#L16-L21,L44-L59` 通过环境 fail-closed 解析 `ChybenzunGptImage2Tool`（`gpt-image-2`）与 `AutoDLH3VideoGeneratorTool`（`autodl_h3`），`lib/video_workflows/general_video/cat_life_exact.py#L26,L32` 与 `flow.py#L367-L372` 为 `cat_life`/`life_sim` 的 `unique_image2_keyframes_with_micro_cuts` 路线硬锁 25 次串行标准版 `gpt-image-2`（禁止 `gpt-image-2-pro`）。
   - **复刻作业调度与生成后质检**：`remake_runner.py#L55-L200` 支持 `--only 2,G3` 局部重跑与 `REA_VIDEO_ENGINE_ROUTES` 环境变量换道，并在提交任务拿到 `task_id` 的瞬间写入带 `task_fingerprint`（SHA-256 请求摘要）的 `results.json` 实现断点续收；随后 `clip_check.py#L23-L136` 提取 `<d>[Lang] ...</d>` 剧本台词调用 `rea_video.speech` 校验重复/漏词/多词，并生成 8 帧联系表。配套 `scripts/remake_color_match.py`（全片单仿射 Reinhard LAB 调色防过橙/过曝闪烁）、`scripts/remake_person_qa.py`（MediaPipe 检测头身比异常与静默角色“偷开口”幻觉）、`scripts/remake_detail_crops.py`（MediaPipe 躯干分割放大对比服饰纽扣/纹理漂移）。

4. **零费用 Dry-Run 与多重成本护栏**（`scripts/quickstart.py`, `lib/src/capsule_preflight.py`, `scripts/capsule_execution_guard.py`）：
   - **无密钥起步与只检存在性**：`quickstart.py` 仅检查环境变量非空而不读取值、不发任何外部请求；支持完全本地无密钥跑通分镜（`run_video.py --storyboard_only`、`capsule.py plan`、`run_capsule.py --dry-run`）或 `repo_signal_grid` / 4 套 Vibe 本地模板。
   - **参考复刻预检不编造价格**：`remake_reference.py#L291-L374` 明文禁止在没有渠道单价目录时捏造价格，只输出精确秒数与按引擎上限折算的调用次数；`remake_runner.py run --dry-run`（`#L132-L148`）打印任务清单及 `channel_notes` 降级提示而不发生成请求。
   - **Preflight 降级阻断与执行脚本防绕过**：`capsule_preflight.py#L81-L122` 按拓扑序检查所有 `roles`，遇 `blocked` 直接终止，遇 `substituted`/`degraded` 标为 `needs_confirmation` 并强制要求 `--accept-preflight-changes` 才放行（`run_capsule.py#L164-L168`）；`cat_life_exact.py#L78,L166-L185` 强制 `image_automatic_retries: 0` 避免静默重刷计费；`capsule_execution_guard.py#L78-L113` 核验 `artifact_manifest.json` 中的执行脚本路径，拦截绕过 `local_script` 胶囊的私有外挂脚本。

5. **时间线重装与 DTW 动作对齐**（`lib/src/remake_assembly.py#L52-L497`）：
   - **精确帧网格对齐与多镜单元切分**：`frame_bounds`（`#L52-L56`）将参考起止时间映射至单一整数帧边界消除累计漂移；`unit_shots`（`#L269-L306`）将多镜合一的生成单元（如 `G2` 或多段 `G4-1`、`G4-2`）对齐缩切后再按原切点分割。
   - **DTW 运动曲线时间规整（`fit_to_original`）**：`motion_curve`（`#L93-L106`）在 `WARP_W=96` 灰度流上计算 `12×8` 分块最大帧间变化量并作 3 帧平滑，随后 `warp_map`（`#L109-L140`）在步长 `(0, 1, 2, 3)` 与速度边界 `[1/1.25, 3.0]`（`MAX_SLOWDOWN=1.25`, `MAX_SPEEDUP=3.0`）内求最小动态规划路径，将生成片段的动作峰谷逐帧对准原片；静态镜头则退回 `setpts` 均匀变速（`_fit_clip`），`still_motion`/`static_hold` 镜头直接由 `render_still_motion`（`#L239-L266`）通过 OpenCV `warpAffine` 复现测得的 `zoom_per_s` 与 `pan_px_per_s` 而零调用视频模型。
   - **局部字幕切片与音画合成**：`replaced_spans`（`#L309-L321`）仅在被替换的非原片区间保留对应时间段的 ASS 字幕，并通过 `clip_ass`（`#L337-L359`）剥离被截断台词边缘的 `\fade(...)` 防止半句渐隐闪烁，最终无损复用原片音轨生成 `remake.mp4`、左右分屏 `compare.mp4` 与 `status.md`。

## 亮点设计 vs 局限/坑点

- **值得借鉴的设计**：
  - **DTW 动作对齐 + 任务指纹断点续收**：用 90 行 NumPy/OpenCV 动态时间规整解决生成片段与参考镜头动作不同步的问题（`remake_assembly.py#L93-L140`），并用提交即落盘的 `task_fingerprint` + `on_task_id` 避免高价视频任务断线重跑二次扣费（`remake_runner.py#L83-L86,L166-L182`）。
  - **复刻质量的多维度数值门禁**：除了 `compare` 的像素切点复检外，将“头身比漂移”和“静默角色 AI 自己开口说话”量化为 MediaPipe 数值阈值（`remake_person_qa.py#L94-L105`），比纯 VLM 看图更稳定且省 Vision Token。
- **局限、隐含假设与潜在坑点**：
  - **公开仓库包含对私有 `.gitignore` 适配器的硬导入，且 `tests/` 与 `cat_life.capsule` 未随仓分发**：`.gitignore#L89-L94,L99-L133` 排除了 `tests/`、`/lib/custom_tools/**/local_*_adapter*.py` 以及 `capsules/cat_life.capsule/`，但已追踪的 `lib/video_workflows/exact_media_channels.py#L16-L21` 与 `lib/video_workflows/general_video/cat_life_exact.py#L26,L46` 直接顶层导入 `local_chybenzun_image_adapter`、`local_177911_image_adapter`、`local_autodl_h3_adapter` 并检查 `capsules/cat_life.capsule`。公开克隆用户在未自建这些私有适配器前执行这些 exact 路线会直接 `ModuleNotFoundError`；`npm test`（`package.json#L8`）仅执行 `py_compile` 与 Skill 分发校验而非运行单元测试。
  - **与 `rea-video` 的强 CLI/私有接口耦合**：`remake_reference.py` 的 `start`/`prepare`/`compare` 在无现成包时强依赖 `PATH` 中可执行的 `rea-video` CLI；`remake_runner.py#L110,L176` 直接调用 `video_generation_tool._tool_for_engine` 私有别名（`video_generation_tool.py#L109-L110` 专门为其保留向后兼容）。
  - **`dry-run` 预检覆盖不全且成本护栏无单价概念**：`remake_runner.channel_notes`（`#L105-L122`）仅对 `unit` 任务执行 `preflight` 检查，单镜任务在 `--dry-run` 阶段跳过通道分辨率/能力提示；`select_jobs`（`#L58-L65`）锁死 `capsule_root` 与 `<repo>/output/` 目录，跨机器/跨目录迁移 `jobs.json` 必须重跑 `prepare`。
  - **离线环境暗坑**：`remake_person_qa.py#L29-L39` 与 `remake_detail_crops.py#L25-L36` 在本地缓存缺失时会向 `storage.googleapis.com` 下载 MediaPipe 模型文件，受限网络环境需提前预置缓存。

## 可复用的模块或设计模式

- **如何迁移到未来项目**：
  1. `lib/src/remake_assembly.py` 中的 `motion_curve` + `warp_map` DTW 变速算法及 `scripts/remake_color_match.py` 的全片单 LAB 仿射校色可直接抽离为纯本地 FFmpeg/OpenCV 后处理工具，用于 `flow-short-drama` 与 `flow-colab-game-pipeline` 对齐 AI 生成镜头节奏与色调。
  2. `lib/src/capsule_content_scope.py` + `lib/src/capsule_preflight.py` 提供的「固定骨架 vs 当期变量扫描 + 能力拓扑预检」非常适合约束 `ganzhi-video-script-writing`、`yiji-motion-video` 等系列化内容模板，防止历史期次文稿泄漏进复用 Prompt。
- **关联 Pattern**：[video-reverse-engineering-and-videomd-layered-context](../patterns/video-reverse-engineering-and-videomd-layered-context.md)

## Cross-Referenced Specimens

- [A-032 · JuneYaooo/rea-video：视频制作方式逆向工程、VIDEO.md 分层包与局部复刻路由架构拆解](https://oumuatown.com/articles/2026-11-30-juneyaooo-rea-video.md) — 信号取证加三轨分离拆片，但抗微信二压与冷启动依赖复核
- [P-030 · 视频逆向拆解、三轨音频预分离、VIDEO.md 分层上下文与分路由局部复刻模式（Video Reverse Engineering & VIDEO.md Layered Context）](https://oumuatown.com/patterns/video-reverse-engineering-and-videomd-layered-context.md) — 以三轨分音、信号取证与四层拆片包实现参考视频精准复刻
- [R-151 · JuneYaooo/rea-video](https://oumuatown.com/repos/JuneYaooo__rea-video.md) — 确定性运动取证融合贝叶斯判源，沉淀分层VIDEO.md
