AI digital-human talking-head videos from one photo: Renoise MCP generation + 5 editing styles + 48 creator-grade packaging components. Agent skill for Claude Code / Codex / OpenClaw / WorkBuddy …
TypeScript
skill: make a cover by default and splice it in as the first frame
Andy31cf77ef9219
diff --git a/README.md b/README.mdindex 192ddda..036d838 100644--- a/README.md+++ b/README.md@@ -57,6 +57,7 @@ Click a GIF (or "Watch") to play the full video. Every demo below was produced w- **5 editing styles, chosen for your content** — the agent diagnoses your content, recommends 2 styles with preview images and asks you everything in one go (style · ratio & length · caption intensity · presenter).- **48 packaging components** — measured frame-by-frame from 25 videos by top creators (MrBeast, Mark Rober, Ryan Trahan, MKBHD, MediaStorm/影视飓风, 何同学, Johnny Harris, Vox, Kurzgesagt, 回形针, 半佛仙人, 差评, 毕导). Each style has a default packaging recipe; add or remove techniques by just asking.- **Text behind the presenter** — big words / numbers between the background and the person (macOS Vision person segmentation → transparent video → 3-layer composite).+- **Cover as the first frame** — every video gets a cover by default (16:9 / 9:16 / 3:4: presenter frame + hook headline + evidence cards), spliced in as the first 0.5 s. Platforms use the first frame as the thumbnail, so there is nothing to upload separately.- **Multi-language** — English, Japanese, Korean, French, Spanish, Arabic tested (whisper back-check 94–100 %).- **Works with your agent** — a standard `SKILL.md` Agent Skill plus scripts; any agent that can load skills, connect a remote MCP server and run local commands can drive it.@@ -72,6 +73,7 @@ your content ──► 0. setup check (Renoise MCP / ffmpeg / whisper — skip w6. word-level timeline (tl.json)7. edit in Remotion: style template + default packaging (+ your requests)8. render → check mid-transition frames → loudness (-14 / -16 LUFS)+ 9. cover: pick a presenter frame → 16:9 / 9:16 / 3:4 → splice in as the first frame (0.5 s)```<p align="center"><img src="docs/images/ad-breakdown.jpg" width="820" alt="The 5 segments of the livestream ad and the packaging used in each"></p>@@ -145,6 +147,7 @@ Latest official instructions: **[renoise.ai/plugin](https://renoise.ai/plugin)**|---|---|---|---|| ffmpeg | `brew install ffmpeg` | `winget install Gyan.FFmpeg` | `sudo apt install ffmpeg` || Python 3 + numpy + Pillow | `brew install python` then `python3 -m pip install numpy pillow` | `winget install Python.Python.3.12` | `sudo apt install python3-pip` |+| Playwright + Chromium (cover layout) | `python3 -m pip install playwright && python3 -m playwright install chromium` | same | same || Node.js 18+ (Remotion) | `brew install node` | `winget install OpenJS.NodeJS.LTS` | `nvm install --lts` || whisper.cpp (`whisper-cli`) | `brew install whisper-cpp` | [Releases](https://github.com/ggerganov/whisper.cpp/releases) | build from [source](https://github.com/ggerganov/whisper.cpp) || whisper model | [`ggml-medium-q5_0.bin`](https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-medium-q5_0.bin) → `~/models/` (or `export WHISPER_MODEL=/path/to/model.bin`) | same | same |@@ -302,6 +305,7 @@ skills/references/ style menu · packaging · playbook · install · research reportsscripts/ build_tasks · rangedl · assemble · align · check_edit · cutout_videovoicefx/unify · doctor · new_edit · make_assets+ make_cover · cover_first (cover + first frame)templates/huazi-916/ 9:16 data-driven talking-head template (edit.json)packaging/ 48-component kit + gallery projectdiff --git a/README.zh-CN.md b/README.zh-CN.mdindex 46a6c26..b436b80 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -57,6 +57,7 @@- **按内容推荐剪辑风格**:Agent 先诊断内容,推荐 2 种风格并附预览图,一次问完(风格 · 比例时长 · 花字强度 · 主播)。- **48 个包装组件**:逐帧拆了 25 支头部博主视频(MrBeast、Mark Rober、Ryan Trahan、MKBHD、影视飓风、何同学、Johnny Harris、Vox、Kurzgesagt、回形针、半佛仙人、差评、毕导)。每种风格自带默认包装,想加减直接说。- **景深字**:大字 / 数字放在背景和人之间(macOS Vision 人像分割 → 透明视频 → 三层合成)。+- **封面即首帧**:每条片子默认出封面(16:9 / 9:16 / 3:4:主播帧 + 钩子大字 + 证据卡),并接成成片第一帧停 0.5 秒。平台默认拿首帧当封面,不用再单独上传。- **多语言**:英、日、韩、法、西、阿拉伯语实测,whisper 回听准确率 94–100%。- **多种 Agent 都能用**:标准 `SKILL.md` Agent Skill + 脚本,只要能装 Skill、能接远程 MCP、能在本机跑命令,就能驱动整条流程。@@ -72,6 +73,7 @@6. 逐字时间轴(tl.json)7. Remotion 剪辑:风格模板 + 默认包装(+ 你点名的手法)8. 渲染 → 看过渡中间帧 → 响度(-14 / -16 LUFS)+ 9. 封面:挑主播帧 → 16:9 / 9:16 / 3:4 → 接成首帧(停 0.5 秒)```<p align="center"><img src="docs/images/ad-breakdown.jpg" width="820" alt="直播间广告 5 段,每段用的包装"></p>@@ -145,6 +147,7 @@ cd skills && zip -r ../digital-human-skills.zip digital-human-koubo finance-expl|---|---|---|---|| ffmpeg | `brew install ffmpeg` | `winget install Gyan.FFmpeg` | `sudo apt install ffmpeg` || Python 3 + numpy + Pillow | `brew install python` 后 `python3 -m pip install numpy pillow` | `winget install Python.Python.3.12` | `sudo apt install python3-pip` |+| Playwright + Chromium(封面排版) | `python3 -m pip install playwright && python3 -m playwright install chromium` | 同左 | 同左 || Node.js 18+(Remotion) | `brew install node` | `winget install OpenJS.NodeJS.LTS` | `nvm install --lts` || whisper.cpp(`whisper-cli`) | `brew install whisper-cpp` | [Releases 下载](https://github.com/ggerganov/whisper.cpp/releases) | [源码编译](https://github.com/ggerganov/whisper.cpp) || whisper 模型 | 下载 [`ggml-medium-q5_0.bin`](https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-medium-q5_0.bin) 放到 `~/models/`(或 `export WHISPER_MODEL=模型路径`) | 同左 | 同左 |@@ -302,6 +305,7 @@ skills/references/ 风格菜单 · 包装组件 · 手法库 · 安装 · 拆解报告scripts/ build_tasks · rangedl · assemble · align · check_edit · cutout_videovoicefx/unify · doctor · new_edit · make_assets+ make_cover · cover_first(封面 + 首帧)templates/huazi-916/ 9:16 数据驱动花字口播模板(edit.json)packaging/ 48 个组件 + 图鉴工程diff --git a/THIRD_PARTY.md b/THIRD_PARTY.mdindex 7ab663c..17e9eaa 100644--- a/THIRD_PARTY.md+++ b/THIRD_PARTY.md@@ -8,6 +8,7 @@| [world-atlas](https://github.com/topojson/world-atlas) | npm | ISC | Data from [Natural Earth](https://www.naturalearthdata.com/) (public domain). Check border depictions against local rules for formal publications. || [d3-geo](https://github.com/d3/d3-geo), [topojson-client](https://github.com/topojson/topojson-client) | npm | ISC | Map projection. || [whisper.cpp](https://github.com/ggerganov/whisper.cpp) | installed by you | MIT | Speech recognition for QA and alignment. |+| [Playwright](https://playwright.dev/python/) | installed by you (`pip install playwright`) | Apache-2.0 | Headless Chromium screenshot for cover layout (`scripts/make_cover.py`). || Apple Vision | macOS system framework | Apple SDK | Person segmentation for the text-behind effect (`scripts/personmask.swift`, compiled locally on first use; macOS only). || Sound effects & placeholder music | generated by `scripts/make_assets.py` | MIT (this repo) | Synthesized from code — no samples. No third-party audio is shipped. |diff --git a/skills/digital-human-koubo/SKILL.md b/skills/digital-human-koubo/SKILL.mdindex 69ad2b7..42c9e8d 100644--- a/skills/digital-human-koubo/SKILL.md+++ b/skills/digital-human-koubo/SKILL.md@@ -1,6 +1,6 @@---name: digital-human-koubo-description: 用固定的数字人形象(白背心数字人 / 用户本人数字人 / 猫狗角色)做口播视频,先按内容推荐剪辑风格让用户选(小林式解说 / 网红花字口播 / 发布解读 / 保姆级教程 / 多主播多语言),自动套上从 MrBeast、MKBHD、影视飓风、Johnny Harris、Vox、半佛、差评等头部博主拆出来的 48 个包装组件(开场钩子、数字钉子、文字在人身后的景深字、证据截图、地图路线、弹幕、投票、复盘板…),再写稿 → 按 15 秒切段 → Renoise Grok Video 1.5 分段生成(先报价、用户确认才生成)→ 分片下载校验 → 逐段回听 → 对齐 → Remotion 剪辑出片。触发:用我的数字人讲这段、数字人口播、让白背心数字人说、用数字人 Skill、数字人带货 / 解读 / 教程 / 种草视频、做成小林说那样、加花字、加包装 / 加地图 / 加弹幕 / 开场加预告 / 文字放在人身后、做成 MrBeast 那种节奏、有哪些包装手法。不用于:换一个全新形象(先按 references/new-avatar.md 做形象)、冒充真人。+description: 用固定的数字人形象(白背心数字人 / 用户本人数字人 / 猫狗角色)做口播视频,先按内容推荐剪辑风格让用户选(小林式解说 / 网红花字口播 / 发布解读 / 保姆级教程 / 多主播多语言),自动套上从 MrBeast、MKBHD、影视飓风、Johnny Harris、Vox、半佛、差评等头部博主拆出来的 48 个包装组件(开场钩子、数字钉子、文字在人身后的景深字、证据截图、地图路线、弹幕、投票、复盘板…),再写稿 → 按 15 秒切段 → Renoise Grok Video 1.5 分段生成(先报价、用户确认才生成)→ 分片下载校验 → 逐段回听 → 对齐 → Remotion 剪辑出片 → 默认做封面(16:9 / 9:16 / 3:4)并接成成片首帧。触发:用我的数字人讲这段、数字人口播、让白背心数字人说、用数字人 Skill、数字人带货 / 解读 / 教程 / 种草视频、做成小林说那样、加花字、加包装 / 加地图 / 加弹幕 / 开场加预告 / 文字放在人身后、做成 MrBeast 那种节奏、有哪些包装手法。不用于:换一个全新形象(先按 references/new-avatar.md 做形象)、冒充真人。---# 数字人口播@@ -45,7 +45,7 @@ description: 用固定的数字人形象(白背心数字人 / 用户本人数### 2. 切段 + 报价`python3 scripts/build_tasks.py script.json tasks.json --purpose "teaching a beginner tutorial step by step"`-→ 打印段数、秒数、预估 credits。full 段 720p(17/秒),pip 段 480p(10/秒)。拿 `estimate_cost` 核一次,报给用户等确认。用户本人或动物主播用 persona.json → other_hosts 里的提示词模板。+→ 打印段数、秒数、预估 credits。full 段 720p(17/秒),pip 段 480p(10/秒)。**主播要裁成半身 / 放大显示、或者 pip 段的主播卡并不小时,所有出镜段一律 720p(`--all-720p`)**:480p 原片只有 400×736,裁半身再铺满大卡会放大 2 倍以上,明显发糊(vibe-knowledge 介绍片因此重拍 4 段,多花 680 积分)。拿 `estimate_cost` 核一次,报给用户等确认。用户本人或动物主播用 persona.json → other_hosts 里的提示词模板。### 3. 生成tasks.json 每 10 个一批 create_tasks → wait_tasks。要进场景(直播间、门店、街景)时先用 GPT Image 2.5 合成开场画面(人物参考图 + 场景描述,2k 约 23 积分),再把这张图当 Grok 的参考图。@@ -58,6 +58,8 @@ download_results 拿链接 → 整理成 `urls.txt`(每行 `<taskId>.<ext> <ur- whisper `--prompt 原文` 会让个别段漏掉前半句,用中性提示「以下是普通话的句子。」。外语段按语言转写;日韩阿拉伯语不要加 `-ml 1`(会把多字节字符截断成乱码)。- **每段抽 4 帧看一眼**:Grok 横屏口播偶尔自己烧字幕(提示词写了也挡不住),有就重拍那段。- Grok 有时漏念开头的语气词:没影响意思就按实际口播改字幕,别为这个重拍。+- **念错字(不是漏语气词)要当场修,不能交给用户去听**:先用中性提示和带原文提示各转写一次,排除 whisper 误听。确认真念错了,优先 0 积分修:拿同一角色 15–20 秒干声(拼几段 cut/*.wav)当参照,用 MiMo `mimo-v2.5-tts-voiceclone` 只重配错的那几个字,响度对齐后在停顿处接缝替换(不要加速、不要加混响,否则字会糊),替换后再转写确认。口型差太多时再报价重拍那一段。+- 开头第一个字最容易被吞或念歪(例:「一个知识点」→「几个知识地点」),写稿时第一段开头别放关键名词,或者先垫一个短词。### 6. 对齐 + 剪辑`python3 scripts/align.py script.json --out <工程>/src/tl.json` 出逐字时间轴,然后按 brief.json 的风格剪:@@ -68,6 +70,21 @@ download_results 拿链接 → 整理成 `urls.txt`(每行 `<taskId>.<ext> <ur- 声音:数字人视频轨一定 `muted`,人声单独铺一条;多段 Grok 原声用 `python3 scripts/voicefx/unify.py <输出目录> <片段…>` 统一频谱 + 同一个小房间混响(复用旧段时加 `--ref 旧片段目录`,场景/动物片段加 `--scene`)。BGM 压在人声下约 20 dB。- 抽帧检查一定看过渡的中间帧和零间隔衔接处(上一条的尾巴会盖住下一条)。+### 7. 封面 + 首帧(默认做,不用问)+平台默认拿视频第一帧当封面,所以每条片子都做封面,并把它接在成片最前面。交付的主文件就是带封面首帧的版本。+1. 写 `cover.json`(字段见 references/cover.md):+ - 小字栏目名+ - 钩子标题 ≤8 字+ - 红色强调句 ≤6 字+ - 一句副标题+ - ≤3 个标签+ - 链接或号召+ - 主播帧+ - ≤2 张证据卡(官方截图、作品)+2. `python3 scripts/make_cover.py cover.json --candidates` 抽 12 帧拼成候选图。挑一帧笑着、眼睛睁开、没在说话或嘴型好看的,时间写进 `host.t`。+3. `python3 scripts/make_cover.py cover.json` 生成 `cover/cover_16x9.jpg`(横屏),按 ratios 还会出 `cover_9x16.jpg`(竖屏)和 `cover_3x4.jpg`(小红书)。看一眼 `thumb_*.jpg`,540px 宽时标题要读得清,文字不能压到卡片。+4. `python3 scripts/cover_first.py 成片.mp4 cover/cover_<比例>.jpg 交付.mp4`:封面停 0.5 秒后硬切进正片,声音整体后推 0.5 秒。抽 0 秒、0.45 秒、0.55 秒三帧确认。不带封面的版本另存为 `_无封面.mp4`。+## 参考- references/install.md:Renoise MCP 和本机环境的多种装法(只在缺的时候用)- references/style-menu.md:五种风格、内容诊断、怎么问用户、brief.json@@ -79,5 +96,6 @@ download_results 拿链接 → 整理成 `urls.txt`(每行 `<taskId>.<ext> <ur- references/voice.md:换声音(MiMo 克隆 / 音色设计)- references/new-avatar.md:从一张照片做新形象- references/edit-styles.md:各剪辑工程的入口文件和声音统一做法+- references/cover.md:封面 cover.json 字段、三种比例的版式、首帧接法- assets/styles/:五种风格的预览图(给用户选的时候发)- assets/packaging/:包装组件图鉴(47 格总览 + 每个组件一张)diff --git a/skills/digital-human-koubo/references/cover.md b/skills/digital-human-koubo/references/cover.mdnew file mode 100644index 0000000..bc9d1d2--- /dev/null+++ b/skills/digital-human-koubo/references/cover.md@@ -0,0 +1,57 @@+# 封面 + 首帧++每条片子默认都做封面,并接在成片开头当第一帧。抖音、视频号、X、B 站默认都取首帧做封面,这样发布时不用再单独上传封面。++## cover.json+放在工程根目录,所有路径都相对它。++```json+{+ "ratios": ["16:9", "3:4"],+ "theme": "paper",+ "accent_color": "#f4212e",+ "kicker": "X 官方新功能 · UNDER THE HOOD",+ "title": "帖子被限流了?",+ "accent": "一个链接自查",+ "sub": "哪几条被打标签 · 什么原因 · 影响多大",+ "tags": ["官方报告", "每月更新", "逐条列出"],+ "url": "x.com/i/jf/under_the_hood",+ "host": {"video": "film/public/host.mp4", "t": 16.94},+ "props": [+ {"image": "film/public/shots/rep_oct.png", "crop": [90, 630, 1080, 1135]},+ {"image": "film/public/shots/rep_sep.png", "crop": [60, 40, 1100, 520]}+ ]+}+```++| 字段 | 写法 |+|---|---|+| ratios | 和成片画幅一致的那个必出(16:9 / 9:16),3:4 给小红书 |+| theme | paper(浅底点阵,默认)/ dark(X 黑) |+| kicker | 小字栏目名 / 来源,例如「X 官方新功能 · UNDER THE HOOD」 |+| title | 钩子问题或结论,≤8 字,黑色大字 |+| accent | 强调句,≤6 字,红色更大字(9:16 版是黄色) |+| sub | 一句话说清看完能得到什么 |+| tags | ≤3 个,黑底白字 |+| url | 链接或号召,等宽字体 |+| host | `video + t`:从主播视频取一帧,先用 `--candidates` 挑;也可以写 `image` 用定妆照 |+| props | ≤2 张斜放的证据卡(官方截图、产品界面、作品帧),`crop` 用原图像素坐标,只截最有说服力的那块 |+| disclosure | 角标,默认「内容由 AI 数字人演绎」(红线要求,别删) |++文字都会自动缩小到不超出栏宽,不用手算字号。++## 三种版式+- **16:9**:左边文字栏宽 880px(栏目名 → 标题 → 强调句 → 副标题 → 标签 → 链接),右边主播卡,两张证据卡斜着压在主播卡后面。+- **9:16**:主播铺满画面,下方加暗色渐变,字压在渐变上(白色标题、黄色强调),证据卡浮在主播胸口右侧。+- **3:4**:标题在上面,主播卡在右下,证据卡在左中,标签和链接在左下。++## 接到首帧+`python3 scripts/cover_first.py 成片.mp4 cover/cover_16x9.jpg 交付.mp4 [--hold 0.5]`+- 封面停 0.5 秒后硬切进正片,声音整体后推 0.5 秒,前面补静音。成片已经是 -16 LUFS 的话,接完响度不变。+- 抽 0 秒、0.45 秒、0.55 秒三帧确认:前两帧是封面,第三帧是正片。+- 交付的主文件 = 带封面的版本;不带封面的版本另存为 `_无封面.mp4`。++## 挑帧+- 嘴闭着或微笑;别挑正在念字、嘴型张大的帧,也别挑闭眼的。+- 手势自然(叉腰、摊手),不挡脸。+- 和片中主播卡是同一个人、同一身衣服;Grok 段间会有轻微差异,选和参考图最像的那段。diff --git a/skills/digital-human-koubo/scripts/cover_first.py b/skills/digital-human-koubo/scripts/cover_first.pynew file mode 100644index 0000000..b3e2648--- /dev/null+++ b/skills/digital-human-koubo/scripts/cover_first.py@@ -0,0 +1,36 @@+#!/usr/bin/env python3+"""把封面图接到成片最前面,当开头帧(平台默认取首帧做封面)。+python3 cover_first.py <成片.mp4> <封面.jpg> <输出.mp4> [--hold 0.5]+封面停 hold 秒后硬切进正片;声音整体往后推 hold 秒,前面补静音。画幅、帧率跟成片一致,封面按画幅铺满居中裁切。"""+import json+import subprocess+import sys+++def probe(path):+ out = subprocess.run(["ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries", "stream=width,height,r_frame_rate",+ "-of", "json", path], capture_output=True, text=True, check=True).stdout+ s = json.loads(out)["streams"][0]+ a, b = s["r_frame_rate"].split("/")+ return s["width"], s["height"], round(int(a) / int(b))+++def main():+ args = [a for a in sys.argv[1:] if not a.startswith("--")]+ if len(args) != 3:+ sys.exit(__doc__)+ src, cover, out = args+ hold = float(sys.argv[sys.argv.index("--hold") + 1]) if "--hold" in sys.argv else 0.5+ w, h, fps = probe(src)+ ms = round(hold * 1000)+ fc = (f"[1:v]scale={w}:{h}:force_original_aspect_ratio=increase,crop={w}:{h},setsar=1,fps={fps},format=yuv420p,trim=duration={hold}[c];"+ f"[0:v]setsar=1,format=yuv420p[m];[c][m]concat=n=2:v=1:a=0[v];"+ f"[0:a]adelay={ms}:all=1,alimiter=limit=0.79:level=false[a]") # 重编 AAC 会让峰值抬高 0.5–1 dB,先限到约 -2 dBFS,编码后真峰值 ≤ -1+ subprocess.run(["ffmpeg", "-y", "-v", "error", "-i", src, "-loop", "1", "-framerate", str(fps), "-t", str(hold), "-i", cover,+ "-filter_complex", fc, "-map", "[v]", "-map", "[a]", "-c:v", "libx264", "-preset", "slow", "-crf", "18",+ "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "192k", "-movflags", "+faststart", out], check=True)+ print(f"→ {out}(封面 {hold:g} 秒 + 正片)")+++if __name__ == "__main__":+ main()diff --git a/skills/digital-human-koubo/scripts/doctor.sh b/skills/digital-human-koubo/scripts/doctor.shindex d81e486..9c923c8 100755--- a/skills/digital-human-koubo/scripts/doctor.sh+++ b/skills/digital-human-koubo/scripts/doctor.sh@@ -18,6 +18,8 @@ if [ -n "$PY" ]; thenfor m in numpy:numpy PIL:pillow; do mod=${m%%:*}; pkg=${m#*:}$PY -c "import $mod" 2>/dev/null && ok "$pkg" || need "$pkg" "声音统一 / 预览图" "$PY -m pip install $pkg" "$PY -m pip install $pkg" "$PY -m pip install $pkg" "conda install $pkg"done+ PWI="$PY -m pip install playwright && $PY -m playwright install chromium"+ $PY -c "import playwright" 2>/dev/null && ok "playwright" || need "playwright + chromium" "封面排版截图(make_cover.py)" "$PWI" "$PWI" "$PWI" "$PWI"else need "Python 3" "回听、对齐、声音统一脚本" "brew install python" "winget install Python.Python.3.12" "sudo apt install python3 python3-pip" "python.org 下载,或装 Anaconda / Miniconda"; fiif command -v node >/dev/null; thenv=$(node -v | tr -d v | cut -d. -f1); [ "$v" -ge 18 ] && ok "Node $(node -v)" || need "Node 18 以上(现在是 $(node -v))" "Remotion 剪辑" "brew upgrade node" "winget upgrade OpenJS.NodeJS.LTS" "nvm install --lts" "nodejs.org 下载 LTS"diff --git a/skills/digital-human-koubo/scripts/make_cover.py b/skills/digital-human-koubo/scripts/make_cover.pynew file mode 100644index 0000000..b930f45--- /dev/null+++ b/skills/digital-human-koubo/scripts/make_cover.py@@ -0,0 +1,156 @@+#!/usr/bin/env python3+"""数字人口播封面:cover.json → cover_16x9.jpg / cover_9x16.jpg / cover_3x4.jpg(HTML 排版 + Playwright 截图)。+用法:+ python3 make_cover.py cover.json # 按 ratios 出图,写到 cover.json 同目录的 cover/ 下+ python3 make_cover.py cover.json --candidates # 先从主播视频里抽 12 帧拼成候选图 cover/candidates.jpg,挑一帧填 host.t+cover.json 字段(见 references/cover.md):+ ratios ["16:9","3:4"] · theme paper|dark · accent_color · kicker · title · accent · sub · tags[≤3] · url+ host {"video": "…/host.mp4", "t": 3.2} 或 {"image": "…jpg"} · props [{"image": "…png", "crop": [x0,y0,x1,y1]}](≤2 张斜放的证据卡)+ disclosure(默认「内容由 AI 数字人演绎」)+路径都相对 cover.json 所在目录。"""+import base64, html, json, os, subprocess, sys, tempfile+from pathlib import Path++SIZES = {"16:9": (1920, 1080), "9:16": (1080, 1920), "3:4": (1080, 1440)}+HEADLESS = sorted(Path.home().glob("Library/Caches/ms-playwright/chromium_headless_shell-*/chrome-headless-shell-mac-arm64/chrome-headless-shell"))+++def frame(video, t, out):+ subprocess.run(["ffmpeg", "-v", "error", "-y", "-ss", str(t), "-i", str(video), "-frames:v", "1", str(out)], check=True)+++def data_uri(path, crop=None):+ from PIL import Image+ im = Image.open(path).convert("RGB")+ if crop: im = im.crop(tuple(crop))+ tmp = Path(tempfile.mkdtemp()) / "x.jpg"; im.save(tmp, quality=92)+ return "data:image/jpeg;base64," + base64.b64encode(tmp.read_bytes()).decode()+++def candidates(spec, root, outdir):+ from PIL import Image, ImageDraw+ v = root / spec["host"]["video"]+ dur = float(subprocess.run(["ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0", str(v)], capture_output=True, text=True).stdout)+ ts = [round(dur * (i + 0.5) / 12, 2) for i in range(12)]+ tiles = []+ for t in ts:+ p = outdir / f"_c_{t}.jpg"; frame(v, t, p)+ im = Image.open(p); im.thumbnail((300, 540)); tiles.append((t, im)); p.unlink()+ W, H = tiles[0][1].size+ sheet = Image.new("RGB", (6 * (W + 8), 2 * (H + 8)), "white")+ for i, (t, im) in enumerate(tiles):+ x, y = (i % 6) * (W + 8), (i // 6) * (H + 8); sheet.paste(im, (x, y))+ ImageDraw.Draw(sheet).text((x + 6, y + 6), f"t={t}", fill=(255, 0, 0))+ sheet.save(outdir / "candidates.jpg"); print("候选帧 →", outdir / "candidates.jpg", "(挑笑着、眼睛睁开、手势自然的一帧,写进 host.t)")+++CSS = """+*{margin:0;padding:0;box-sizing:border-box}+body{width:%(W)dpx;height:%(H)dpx;overflow:hidden;font-family:"PingFang SC","Hiragino Sans GB",sans-serif;background:%(bg)s;color:%(ink)s;position:relative}+.dots{position:absolute;inset:0;background-image:radial-gradient(%(dot)s 2px,transparent 2px);background-size:30px 30px}+.kicker{font-size:%(k)dpx;font-weight:700;color:%(mute)s;letter-spacing:3px;white-space:nowrap}+.title{font-weight:900;line-height:1.08;white-space:nowrap;letter-spacing:2px}+.accent{color:%(acc)s}+.sub{font-weight:800;white-space:nowrap}+.tags{display:flex;gap:18px;flex-wrap:nowrap}+.tag{font-weight:800;color:#fff;background:%(ink)s;border-radius:16px;padding:10px 24px;white-space:nowrap}+.url{font-family:"SF Mono",Menlo,monospace;font-weight:600;color:%(mute)s;white-space:nowrap}+.host{position:absolute;overflow:hidden;border-radius:36px;box-shadow:0 40px 90px rgba(15,20,25,.28);background:#cfd0d3}+.host img{width:100%%;height:100%%;object-fit:cover;object-position:50%% 20%%;display:block}+.prop{position:absolute;border-radius:22px;overflow:hidden;border:8px solid #fff;box-shadow:0 30px 70px rgba(15,20,25,.3);background:#fff}+.prop img{width:100%%;display:block}+.disc{position:absolute;right:28px;bottom:16px;font-size:22px;color:%(mute)s}+"""++FIT = """+for (const el of document.querySelectorAll('[data-max]')) {+ const max = +el.dataset.max; let fs = parseFloat(getComputedStyle(el).fontSize);+ while (el.scrollWidth > max && fs > 20) { fs -= 2; el.style.fontSize = fs + 'px'; }+}+"""+++def page(spec, ratio, host_uri, props):+ W, H = SIZES[ratio]+ dark = spec.get("theme") == "dark"+ pal = dict(W=W, H=H, bg="#0f1419" if dark else "radial-gradient(ellipse at 30% 20%,#fdfdfd 0%,#f4f5f6 50%,#e6e8eb 100%)",+ ink="#ffffff" if dark else "#0f1419", mute="#8b98a5" if dark else "#536471",+ dot="rgba(255,255,255,.06)" if dark else "rgba(15,20,25,.08)", acc=spec.get("accent_color", "#f4212e"), k=34)+ e = lambda s: html.escape(s or "")+ tags = "".join(f'<div class="tag" style="font-size:{40 if ratio != "9:16" else 44}px">{e(x)}</div>' for x in spec.get("tags", [])[:3])+ disc = e(spec.get("disclosure", "内容由 AI 数字人演绎"))+ if ratio == "16:9":+ tx, tw = 110, 880+ text = f"""<div style="position:absolute;left:{tx}px;top:190px;width:{tw}px;display:flex;flex-direction:column;gap:30px">+ <div class="kicker" data-max="{tw}">{e(spec.get('kicker'))}</div>+ <div class="title" style="font-size:132px" data-max="{tw}">{e(spec['title'])}</div>+ <div class="title accent" style="font-size:168px;margin-top:-6px" data-max="{tw}">{e(spec.get('accent'))}</div>+ <div class="sub" style="font-size:48px;margin-top:6px" data-max="{tw + 40}">{e(spec.get('sub'))}</div>+ <div class="tags" style="margin-top:8px">{tags}</div>+ <div class="url" style="font-size:40px;margin-top:14px" data-max="{tw}">{e(spec.get('url'))}</div></div>"""+ hostbox = (1300, 50, 540, 980)+ propbox = [(1010, 560, 520, -6), (1000, 150, 500, 5)]+ elif ratio == "3:4":+ tw = 960+ text = f"""<div style="position:absolute;left:60px;top:70px;width:{tw}px;display:flex;flex-direction:column;gap:18px">+ <div class="kicker" data-max="{tw}">{e(spec.get('kicker'))}</div>+ <div class="title" style="font-size:118px" data-max="{tw}">{e(spec['title'])}</div>+ <div class="title accent" style="font-size:140px" data-max="{tw}">{e(spec.get('accent'))}</div>+ <div class="sub" style="font-size:44px" data-max="{tw}">{e(spec.get('sub'))}</div></div>+ <div style="position:absolute;left:60px;bottom:120px;display:flex;flex-direction:column;gap:22px;width:560px">+ <div class="tags" style="flex-wrap:wrap">{tags}</div><div class="url" style="font-size:30px" data-max="560">{e(spec.get('url'))}</div></div>"""+ hostbox = (640, 560, 400, 820)+ propbox = [(80, 640, 560, -5)]+ else: # 9:16:主播铺满,下方暗渐变压大字+ tw = 960+ text = f"""<div style="position:absolute;inset:0;background:linear-gradient(180deg,rgba(15,20,25,0) 38%,rgba(15,20,25,.82) 66%,rgba(15,20,25,.95) 100%)"></div>+ <div style="position:absolute;left:60px;bottom:150px;width:{tw}px;display:flex;flex-direction:column;gap:22px;color:#fff">+ <div class="kicker" style="color:#c9d1d9" data-max="{tw}">{e(spec.get('kicker'))}</div>+ <div class="title" style="font-size:124px" data-max="{tw}">{e(spec['title'])}</div>+ <div class="title" style="font-size:140px;color:#ffd400" data-max="{tw}">{e(spec.get('accent'))}</div>+ <div class="sub" style="font-size:46px" data-max="{tw}">{e(spec.get('sub'))}</div>+ <div class="tags">{tags.replace('class="tag"', 'class="tag" style="background:#fff;color:#0f1419;font-size:40px"')}</div></div>"""+ hostbox = (0, 0, W, H)+ propbox = [(600, 420, 440, 6)]+ hx, hy, hw, hh = hostbox+ hstyle = f"left:{hx}px;top:{hy}px;width:{hw}px;height:{hh}px" + (";border-radius:0;box-shadow:none" if ratio == "9:16" else "")+ ptags = "".join(f'<div class="prop" style="left:{x}px;top:{y}px;width:{w}px;transform:rotate({r}deg)"><img src="{u}"></div>'+ for (x, y, w, r), u in zip(propbox, props))+ behind = ratio != "9:16" # 横版 / 3:4:证据卡压在主播卡后面;竖版:卡片浮在主播上+ body = (ptags + f'<div class="host" style="{hstyle}"><img src="{host_uri}"></div>' if behind else f'<div class="host" style="{hstyle}"><img src="{host_uri}"></div>' + ptags)+ return f"""<!doctype html><html><head><meta charset="utf-8"><style>{CSS % pal}</style></head><body>+ {'' if ratio == '9:16' else '<div class="dots"></div>'}{body}{text}<div class="disc" style="{'color:#c9d1d9' if ratio == '9:16' else ''}">{disc}</div>+ <script>{FIT}</script></body></html>"""+++def main():+ a = sys.argv[1:]+ if not a: sys.exit(__doc__)+ spec_path = Path(a[0]).resolve(); root = spec_path.parent+ spec = json.loads(spec_path.read_text())+ outdir = root / spec.get("out_dir", "cover"); outdir.mkdir(exist_ok=True)+ if "--candidates" in a:+ return candidates(spec, root, outdir)+ h = spec["host"]+ if "image" in h: host_uri = data_uri(root / h["image"])+ else:+ p = outdir / "host_frame.png"; frame(root / h["video"], h.get("t", 1.0), p); host_uri = data_uri(p)+ props = [data_uri(root / p["image"], p.get("crop")) for p in spec.get("props", [])[:2]]+ from playwright.sync_api import sync_playwright+ with sync_playwright() as pw:+ kw = {"executable_path": str(HEADLESS[-1])} if HEADLESS else {}+ br = pw.chromium.launch(**kw)+ for ratio in spec.get("ratios", ["16:9"]):+ W, H = SIZES[ratio]+ pg = br.new_page(viewport={"width": W, "height": H}, device_scale_factor=1)+ pg.set_content(page(spec, ratio, host_uri, props)); pg.wait_for_timeout(300)+ out = outdir / f"cover_{ratio.replace(':', 'x')}.jpg"+ pg.screenshot(path=str(out), type="jpeg", quality=93); pg.close()+ from PIL import Image+ th = Image.open(out); th.thumbnail((540, 960)); th.save(outdir / f"thumb_{ratio.replace(':', 'x')}.jpg")+ print("封面 →", out, "(缩略图 thumb_*.jpg:540 宽时标题还要读得清)")+ br.close()+++if __name__ == "__main__":+ main()