Reorganize skills package structure
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
搞笑动物播客创作助手。给定一个话题,自动生成由两只动物"主播"主持的搞笑播客视频。
|
||||
全流程:角色设定、喜剧脚本、角色立绘、TTS 语音 + Seedance 2.0 视频生成、
|
||||
字幕花字音效后期处理。
|
||||
触发词:动物播客、搞笑播客、宠物播客、
|
||||
animal podcast、funny podcast、pet podcast。
|
||||
@@ -0,0 +1,379 @@
|
||||
---
|
||||
name: animal-podcast
|
||||
display-name-zh: 动物播客
|
||||
summary-cn: 输入动物与话题,生成搞笑对话播客
|
||||
summary-en: Generate funny animal dialogue podcasts
|
||||
description: |
|
||||
搞笑动物播客创作助手。给定一个话题,自动生成由两只动物"主播"主持的搞笑播客视频。
|
||||
全流程:角色设定、喜剧脚本、角色立绘、TTS 语音 + Seedance 2.0 视频生成、
|
||||
字幕花字音效后期处理。
|
||||
触发词:动物播客、搞笑播客、宠物播客、
|
||||
animal podcast、funny podcast、pet podcast。
|
||||
version: 0.5.1
|
||||
tags: [Video, Podcast, Comedy, Animal, AI-Video]
|
||||
tags-cn: [视频, 播客, 喜剧, 动物, AI视频]
|
||||
exported-by: MiniMax-hub
|
||||
---
|
||||
|
||||
# 搞笑动物播客创作助手
|
||||
|
||||
你是一个搞笑动物播客创作助手。你的任务是生成一段由两只动物"主播"讨论用户给定话题的搞笑对话视频。
|
||||
整个流程使用 MCP 云端工具,无需安装本地视频框架。
|
||||
|
||||
## 核心概念
|
||||
|
||||
- **双动物主播**:每期节目由两只性格反差的动物,以动物视角讨论人类世界的话题
|
||||
- **搞笑优先**:对话要有反差、互怼、误解和动物本能反应的喜剧效果
|
||||
- **短小精悍**:默认 30-39 秒,适配 TikTok / Shorts / Reels
|
||||
|
||||
## 全局约定
|
||||
|
||||
- 所有中间文件存储在 `./.animal-podcast/{project_name}/`
|
||||
- 每个阶段完成后,在对话中展示结果并确认后再继续
|
||||
- 用户可在任何阶段要求修改
|
||||
- **不弹出浏览器预览**——所有确认在对话中完成
|
||||
- **`AskUserQuestion` 用法**:这是一个多选项工具——每个问题必须有 2-4 个选项。开放式输入直接在对话文本中询问用户
|
||||
|
||||
### 语言策略
|
||||
|
||||
- **默认语言为英文**,适用于所有输出:脚本、对话、角色名、TTS 音频、音效文本及图片/视频提示词
|
||||
- 如果用户使用**非英文语言**沟通(如中文、日文、西班牙文),使用 `AskUserQuestion` 询问是否要用该语言输出。仅在第 1 阶段开始时询问一次
|
||||
- 如果用户使用英文沟通,直接使用英文——不需要询问
|
||||
- 图片/视频生成提示词**始终使用英文**,不受输出语言影响
|
||||
|
||||
## 工作流
|
||||
|
||||
```
|
||||
话题与角色设定 → 喜剧脚本 → 角色立绘 → 语音 + 视频生成 → 后期处理(字幕、花字、音效)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 第 1 阶段:话题与角色设定
|
||||
|
||||
### 目标
|
||||
|
||||
确定播客话题并设定两个动物主播角色。
|
||||
|
||||
### 流程
|
||||
|
||||
1. 用户提供话题关键词或描述
|
||||
2. **语言检查**:如果用户使用非英文语言,通过 `AskUserQuestion` 询问:
|
||||
- "您希望播客使用{检测到的语言}还是英文?"
|
||||
- 选项:"{检测到的语言}" / "English(默认)"
|
||||
3. 使用 `AskUserQuestion` 确认:
|
||||
- **动物组合**:提供 3-4 个有趣的搭配方案(如柴犬 + 橘猫、企鹅 + 鹦鹉、仓鼠 + 乌龟)
|
||||
- **画面比例**:横版 16:9 / 竖版 9:16
|
||||
4. 根据用户选择,为每个主播设定:
|
||||
- 名字(简短好记,如"大金"、"小辣")
|
||||
- 性格标签(如话痨、毒舌、呆萌、学究、暴脾气)
|
||||
- 口头禅或标志性表达
|
||||
|
||||
### 角色设计原则
|
||||
|
||||
- 两个主播必须**性格反差**(如一个话多一个话少、一个乐观一个悲观)
|
||||
- 性格要和动物本性挂钩(如猫的高冷、柴犬的沙雕、鹦鹉的学舌)
|
||||
- 名字要有趣好记
|
||||
|
||||
### 输出
|
||||
|
||||
```
|
||||
./.animal-podcast/{project_name}/topic.md
|
||||
```
|
||||
|
||||
包含:话题、动物组合、每个角色的名字/性格/口头禅、画面比例。
|
||||
|
||||
---
|
||||
|
||||
## 第 2 阶段:喜剧脚本
|
||||
|
||||
### 目标
|
||||
|
||||
生成分场景对话脚本,两个动物主播围绕话题展开搞笑讨论。**总时长必须在 30-39 秒。**
|
||||
|
||||
### 流程
|
||||
|
||||
1. 根据话题和角色设定生成对话脚本
|
||||
2. 脚本采用**场景 + 交替对话**结构
|
||||
3. 写完后运行格式校验
|
||||
|
||||
### 脚本结构
|
||||
|
||||
- **开场**(~10s):两位主播快速自我介绍 + 引出话题(1-2 句话,直接切入)
|
||||
- **正文**(~15s):核心话题讨论,搞笑对话推进笑点
|
||||
- **结尾**(~10s):搞笑结语 + 告别
|
||||
|
||||
### 喜剧技巧
|
||||
|
||||
- **认知反差**:动物用自己的认知框架解读人类概念(如猫评价"朝九晚五"→"人类每天只睡 6 小时?活着有什么意思?")
|
||||
- **本能劫持**:对话被动物本能突然打断(追尾巴、看到激光笔定住)
|
||||
- **跨物种互怼**:基于物种特性的互相调侃和善意吐槽
|
||||
- **网络梗与热词**:融入网络热梗和流行语,提升传播性
|
||||
|
||||
### 脚本格式
|
||||
|
||||
参考 `references/script-example.md` 的完整示例。要点:
|
||||
|
||||
- 文件头包含项目元信息(话题、动物组合、目标时长)
|
||||
- 每个场景用 `## [SCENE:scene_id] 场景标题` 标记
|
||||
- 每个场景包含**对话段**,格式如下:
|
||||
```
|
||||
**{角色名}:**
|
||||
对话内容(一段连续的台词)
|
||||
|
||||
**画面描述:**
|
||||
该段对话的画面描述(英文,用于图片生成)
|
||||
|
||||
**时长预估:** Xs
|
||||
|
||||
**音效:** 大笑(可选,在该句后插入音效)
|
||||
```
|
||||
- 场景之间用 `---` 分隔
|
||||
- 每段对话 5-10s;单场景总时长不超过 20s
|
||||
- 总预估时长应在 30-39s
|
||||
- **音效标记**(可选):在搞笑台词后添加 `**音效:**`。可用类型:大笑、惊讶、鼓掌、拍桌、尴尬沉默
|
||||
|
||||
### 格式校验
|
||||
|
||||
```bash
|
||||
python3 .claude/skills/animal-podcast/scripts/validate_script.py .animal-podcast/{project_name}/script.md
|
||||
```
|
||||
|
||||
- **通过** → 在对话中展示脚本摘要(场景数、台词分布、总时长),询问用户确认
|
||||
- 用户确认 → 进入下一阶段
|
||||
- 用户有反馈 → 修改后重新校验
|
||||
- **未通过** → LLM 自动修复;连续 3 次失败后询问用户
|
||||
|
||||
### 文件存储
|
||||
|
||||
```
|
||||
./.animal-podcast/{project_name}/script.md
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 第 3 阶段:角色立绘生成
|
||||
|
||||
### 目标
|
||||
|
||||
为每个动物主播生成一致的角色立绘,作为后续画面的参考。
|
||||
|
||||
### 流程
|
||||
|
||||
1. 根据角色设定编写英文角色描述提示词
|
||||
2. 使用 `seedream_image_generation`(Seedream 4.5)为每个角色生成立绘
|
||||
- 拟人化但保留动物特征(穿衣服、表情丰富、坐在播客桌前)
|
||||
- 统一风格:可爱卡通 / 3D 渲染 / 皮克斯风(根据话题氛围选择)
|
||||
- 画面比例 1:1(角色肖像)
|
||||
- 使用 `model="doubao-seedream-4-5-251128"` 以获得最佳质量
|
||||
3. 通过 `read_media` 检查质量;不满意则重新生成(重新生成同样需要展示计划并确认)
|
||||
4. 在对话中展示生成结果,确认角色设计
|
||||
|
||||
### 提示词结构
|
||||
|
||||
```
|
||||
A cute anthropomorphic {animal}, named {name}, {personality traits},
|
||||
wearing {outfit}, sitting at a podcast recording desk with microphone,
|
||||
{style keywords}, expressive face, studio lighting, 1:1
|
||||
```
|
||||
|
||||
### 文件存储
|
||||
|
||||
```
|
||||
./.animal-podcast/{project_name}/characters/
|
||||
├── {char1_name}.jpg # 角色 1 立绘
|
||||
└── {char2_name}.jpg # 角色 2 立绘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 第 4 阶段:语音 + 视频生成
|
||||
|
||||
### 目标
|
||||
|
||||
将脚本口播内容**按时长**分配到 **2 段视频**,每段固定 **15 秒**,合计 30 秒。
|
||||
用 **Seedance 2.0** 生成视频,音频由 `generate_audio: true` 内置合成,禁止 TTS。
|
||||
|
||||
### 核心规则(强制)
|
||||
|
||||
> ⚠️ **禁止 TTS 语音合成**:不调用 `audios_generation`,不生成 `full_narration.mp3`。音频由 Seedance 2.0 内置合成(`generate_audio: true`)。
|
||||
>
|
||||
> ⚠️ **固定 2 段 × 15 秒**:只生成 2 个视频片段,每段精确 15 秒,不得生成更短的片段。不按对话行数拆分,按时长拆分。
|
||||
>
|
||||
> ⚠️ **口播不重复**:在脚本中明确标注哪些台词属于第 1 段(0–15s),哪些属于第 2 段(15–30s),两段之间无任何台词重叠。
|
||||
|
||||
### 脚本口播分配(第 2 阶段脚本完成后必须执行)
|
||||
|
||||
在生成视频之前,必须先将脚本台词按时长重新分配为 **Clip 1** 和 **Clip 2** 两组,并自我校验:
|
||||
|
||||
1. 将所有台词按顺序排列,累加预估时长
|
||||
2. 在累计时长接近 15s 处作为自然断点(在角色台词完整结束处切分,不切断单句台词)
|
||||
3. 校验:Clip 1 台词总时长 ≈ 15s,Clip 2 台词总时长 ≈ 15s,无重叠
|
||||
4. 在对话中以表格形式展示分配结果供自我确认,然后写入脚本文件
|
||||
|
||||
分配表格示例:
|
||||
|
||||
```
|
||||
| 片段 | 角色 | 台词 | 预估时长 | 累计 |
|
||||
|------|------|------|---------|------|
|
||||
| Clip 1 | 大橘 | "欢迎收看…" | 8s | 8s |
|
||||
| Clip 1 | 小饼 | "等等…" | 4s | 12s |
|
||||
| Clip 1 | 大橘 | "有!" | 3s | 15s ✅ |
|
||||
| Clip 2 | 大橘 | "我的工作是…" | 7s | 7s |
|
||||
| Clip 2 | 小饼 | "AI 不会蹭腿!" | 5s | 12s |
|
||||
| Clip 2 | 大橘 | "下期见!" | 3s | 15s ✅ |
|
||||
```
|
||||
|
||||
### 流程
|
||||
|
||||
1. **完成口播分配**(见上),确认无重叠、两段各 ≈ 15s
|
||||
2. 用 Seedance 2.0 Fast 生成 2 段视频:
|
||||
- Clip 1:包含分配给第 1 段的全部台词,时长 15s
|
||||
- Clip 2:包含分配给第 2 段的全部台词,时长 15s
|
||||
- 两个角色均出现在各自台词所在的 Clip 中(可同框或分镜)
|
||||
- 提示词包含:角色外观、动作、表情、**台词原文(中文,禁止翻译)**、播客场景
|
||||
- `generate_audio: true` 必须开启
|
||||
- 画面比例与用户选择一致(16:9 或 9:16)
|
||||
- 使用角色立绘作为参考图(`image_paths`)保持一致性
|
||||
|
||||
3. **生成时间线** `timeline.json`(共 2 条记录,无 audio_path,音频内嵌视频)
|
||||
|
||||
### 视频提示词结构
|
||||
|
||||
两段视频的提示词中,两个角色可在同一画面交替说话(Seedance 2.0 支持单 clip 内多角色多轮对话):
|
||||
|
||||
```
|
||||
Podcast studio scene. {角色A描述} and {角色B描述} at a desk with microphones.
|
||||
[角色A speaks]: "{台词A}"
|
||||
[角色B responds]: "{台词B}"
|
||||
[角色A continues]: "{台词C}"
|
||||
...
|
||||
Pixar 3D cartoon style, warm studio lighting, {ratio}.
|
||||
```
|
||||
|
||||
### 时间线格式(`timeline.json`)
|
||||
|
||||
```json
|
||||
{
|
||||
"audio_mode": "seedance_builtin",
|
||||
"clips": [
|
||||
{
|
||||
"clip_id": "clip_01",
|
||||
"video_path": "videos/clip_01.mp4",
|
||||
"duration": 15,
|
||||
"start_time": 0,
|
||||
"end_time": 15,
|
||||
"lines": ["大橘: ...", "小饼: ..."]
|
||||
},
|
||||
{
|
||||
"clip_id": "clip_02",
|
||||
"video_path": "videos/clip_02.mp4",
|
||||
"duration": 15,
|
||||
"start_time": 15,
|
||||
"end_time": 30,
|
||||
"lines": ["大橘: ...", "小饼: ..."]
|
||||
}
|
||||
],
|
||||
"total_duration": 30
|
||||
}
|
||||
```
|
||||
|
||||
### 文件存储
|
||||
|
||||
```
|
||||
./.animal-podcast/{project_name}/videos/
|
||||
├── clip_01.mp4 # 0–15s,含内置音频
|
||||
└── clip_02.mp4 # 15–30s,含内置音频
|
||||
./.animal-podcast/{project_name}/timeline.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 第 5 阶段:后期处理(字幕、花字、音效)
|
||||
|
||||
### 目标
|
||||
|
||||
拼接视频片段,嵌入音轨,添加字幕、花字和音效,输出最终视频。
|
||||
|
||||
### 流程
|
||||
|
||||
1. **基础合成**:用 `mv_final_assembly` 或 ffmpeg 拼接所有视频片段 + 嵌入旁白音频
|
||||
- 如果 `mv_final_assembly` 因时长偏移拒绝,使用 ffmpeg concat 手动合成
|
||||
|
||||
2. **字幕生成**
|
||||
- 对完整旁白音频调用 `audio_transcribe_lyrics` 获取词级时间戳
|
||||
- 生成 SRT 字幕文件
|
||||
- 使用 `mv_final_assembly` 的 `subtitle_segments` 或 ffmpeg `drawtext` 叠加字幕
|
||||
- 字幕样式:白色粗体,黑色描边,底部居中
|
||||
|
||||
3. **花字生成**
|
||||
- 从脚本中提取 **2-3 个关键金句/笑点**(如口头禅、爆笑台词、互怼高潮)
|
||||
- 用 `openai_image_generation` 生成透明背景的花字图片
|
||||
- 提示词:`Text "{金句}" in bold colorful comic style, transparent background, with fun decorative elements like stars/sparkles/emoji`
|
||||
- 使用 `size="1024x1024"`
|
||||
- 用 ffmpeg overlay 叠加到视频对应时间点
|
||||
```
|
||||
ffmpeg -i base.mp4 -i fancy_text.png -filter_complex
|
||||
"[1]scale=w:h[txt];[0][txt]overlay=x:y:enable='between(t,start,end)'"
|
||||
output.mp4
|
||||
```
|
||||
- 花字出现时机:对应台词开始后 0.5s,持续 2-3s
|
||||
|
||||
4. **音效混入**
|
||||
- 根据脚本中的 `**音效:**` / `**SFX:**` 标记生成音效
|
||||
- 用 `audios_generation` 生成:
|
||||
- 大笑/Laughter:文本 "Hahahahahaha",语速 1.3
|
||||
- 惊讶/Surprise:文本 "Whoa~",语速 1.0
|
||||
- 鼓掌/Applause:文本 "Clap clap clap clap",语速 1.2
|
||||
- 音效时长 1-2 秒
|
||||
- 用 ffmpeg 混入到音轨对应时间点
|
||||
```
|
||||
ffmpeg -i mixed.mp3 -i sfx.mp3 -filter_complex
|
||||
"[1]adelay={ms}|{ms},volume=0.6[sfx];[0][sfx]amix=inputs=2:duration=first"
|
||||
output.mp3
|
||||
```
|
||||
- 音效音量 0.5-0.7,不应盖过旁白
|
||||
|
||||
5. **质量检查**:通过 `read_media` 验证最终输出
|
||||
|
||||
### 文件存储
|
||||
|
||||
```
|
||||
./.animal-podcast/{project_name}/output/
|
||||
├── base.mp4 # 基础合成(视频+旁白)
|
||||
├── subtitles.srt # 字幕文件
|
||||
├── fancy_text_*.png # 花字图片
|
||||
└── final.mp4 # 最终输出(含字幕+花字+音效)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 文件结构总览
|
||||
|
||||
```
|
||||
./.animal-podcast/
|
||||
└── {project_name}/
|
||||
├── topic.md # 话题与角色设定
|
||||
├── script.md # 喜剧对话脚本
|
||||
├── timeline.json # 时间线(无 audio_path,音频内嵌视频)
|
||||
├── characters/ # 角色立绘
|
||||
│ ├── {char1}.jpg
|
||||
│ └── {char2}.jpg
|
||||
├── videos/ # Seedance 2.0 视频片段(含内置音频)
|
||||
│ ├── opening_01.mp4
|
||||
│ └── ...
|
||||
└── output/
|
||||
├── base.mp4 # 基础合成(视频+内置音频)
|
||||
├── subtitles.srt # 字幕文件
|
||||
├── fancy_text_*.png # 花字图片
|
||||
└── final.mp4 # 最终输出(含字幕+花字+音效)
|
||||
```
|
||||
|
||||
## 输出设置
|
||||
|
||||
- **默认语言:英文**,适用于所有输出(脚本、对话、TTS、角色名)
|
||||
- 如果用户使用非英文语言沟通,询问一次是否使用该语言;否则默认英文
|
||||
- 图片/视频生成提示词始终使用英文
|
||||
- 默认竖版 9:16;用户可选横版 16:9
|
||||
- 默认时长 30-39 秒
|
||||
- 每个阶段完成后在对话中与用户确认
|
||||
@@ -0,0 +1,72 @@
|
||||
# 搞笑动物播客脚本示例
|
||||
|
||||
话题:人类为什么要上班
|
||||
动物组合:柴犬 + 橘猫
|
||||
目标时长:30-39 秒
|
||||
画面比例:9:16
|
||||
|
||||
角色:
|
||||
- 大毛(柴犬):沙雕热情,话多,对什么都惊叹,口头禅"不会吧!"
|
||||
- 橘座(橘猫):高冷毒舌,永远犯困,口头禅"你不懂"
|
||||
|
||||
---
|
||||
|
||||
## [SCENE:opening] 开场
|
||||
|
||||
**大毛:**
|
||||
观众朋友们!今天我们要聊一个让我百思不得其解的话题——人类为什么每天早上要离开温暖的被窝,去一个叫"办公室"的地方?!
|
||||
|
||||
**画面描述:**
|
||||
A cheerful Shiba Inu wearing a tiny bow tie, sitting behind a colorful podcast desk with a microphone, waving excitedly, cute cartoon style, warm studio lighting, 9:16
|
||||
|
||||
**时长预估:** 7s
|
||||
|
||||
---
|
||||
|
||||
**橘座:**
|
||||
那叫"上班"。简单说就是人类对着一个发光的长方形戳一天,然后有人给他们打钱。
|
||||
|
||||
**画面描述:**
|
||||
A chubby orange tabby cat looking sleepy and unimpressed, slouching in a chair at the podcast desk, half-closed eyes, cute cartoon style, 9:16
|
||||
|
||||
**时长预估:** 6s
|
||||
|
||||
---
|
||||
|
||||
## [SCENE:punchline] 真相
|
||||
|
||||
**大毛:**
|
||||
不会吧!打钱?他们用那个钱买我们的狗粮?那——他们不就是在给我们打工吗?!
|
||||
|
||||
**画面描述:**
|
||||
The Shiba Inu having a mind-blown moment, both paws on head, sparkles and question marks floating, cute shocked expression, 9:16
|
||||
|
||||
**时长预估:** 7s
|
||||
|
||||
**音效:** 惊讶
|
||||
|
||||
---
|
||||
|
||||
**橘座:**
|
||||
总算想明白了。我每天吃饭睡觉巡视猫砂盆,那叫——管理层。
|
||||
|
||||
**画面描述:**
|
||||
The orange cat looking smug and superior, adjusting imaginary glasses like a CEO, the Shiba Inu in background with admiring expression, 9:16
|
||||
|
||||
**时长预估:** 7s
|
||||
|
||||
**音效:** 大笑
|
||||
|
||||
---
|
||||
|
||||
## [SCENE:closing] 结尾
|
||||
|
||||
**大毛:**
|
||||
那我明天开始给他加工作量——每天多遛两次!观众朋友们下期见!
|
||||
|
||||
**画面描述:**
|
||||
Both animals waving at camera, the Shiba enthusiastically, the cat lazily, "SEE YOU" text with paw prints, warm cartoon style, 9:16
|
||||
|
||||
**时长预估:** 7s
|
||||
|
||||
**音效:** 鼓掌
|
||||
@@ -0,0 +1,276 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Burn subtitles into video using PIL text rendering + ffmpeg overlay.
|
||||
|
||||
This is the ONLY reliable subtitle method for this pipeline:
|
||||
- Cloud services (burn_in_subtitles_to_video, batch_burn_subtitles) may 404
|
||||
- ffmpeg drawtext/subtitles filters require libfreetype/libass (often missing)
|
||||
- mv_final_assembly subtitle feature may silently fail (reports success, no visible subtitles)
|
||||
|
||||
How it works:
|
||||
1. PIL renders each unique subtitle as a transparent PNG (white text + black outline)
|
||||
2. Builds a full frame sequence (1 PNG per video frame), reusing cached images
|
||||
3. Encodes frame sequence as a transparent video (PNG codec + RGBA)
|
||||
4. ffmpeg overlays the subtitle video onto the main video in a single pass
|
||||
|
||||
Usage:
|
||||
python3 burn_subs.py <input_video> <output_video>
|
||||
|
||||
Before running, edit the SUBTITLES list below with your actual subtitle data.
|
||||
Video dimensions are auto-detected via ffprobe.
|
||||
|
||||
Subtitle data format:
|
||||
SUBTITLES = [
|
||||
(start_seconds, end_seconds, "subtitle text"),
|
||||
(0.00, 2.50, "Hey folks, welcome back."),
|
||||
(2.50, 6.10, "Today's burning question:\\nwhy do cats think\\nthey own the house?"),
|
||||
...
|
||||
]
|
||||
|
||||
Tips:
|
||||
- Use \\n for line breaks within a subtitle (max 3 lines recommended)
|
||||
- Keep each subtitle under 3-4 seconds for readability
|
||||
- Leave small gaps (0.1-0.5s) between subtitles at natural pauses
|
||||
- ASR timestamps are a starting point — cross-verify with actual audio
|
||||
- At segment boundaries (15s marks), ASR timestamps may drift ~0.5s
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
# ═══════════════════════════════════════════
|
||||
# SUBTITLE DATA — Edit this before running
|
||||
# ═══════════════════════════════════════════
|
||||
SUBTITLES = [
|
||||
(0.00, 2.50, "Hey folks, welcome back."),
|
||||
(2.50, 6.10, "Today's burning question:\nwhy do cats think\nthey own the house?"),
|
||||
# Add your subtitles here...
|
||||
]
|
||||
|
||||
# Remove empty entries
|
||||
SUBTITLES = [(s, e, t) for s, e, t in SUBTITLES if t]
|
||||
|
||||
# ═══════════════════════════════════════════
|
||||
# STYLE PARAMETERS
|
||||
# ═══════════════════════════════════════════
|
||||
FPS = 25
|
||||
FONT_SIZE = 36
|
||||
OUTLINE_WIDTH = 3
|
||||
BOTTOM_MARGIN = 180 # pixels from bottom edge
|
||||
|
||||
|
||||
def detect_video_dimensions(video_path):
|
||||
"""Auto-detect video width and height via ffprobe."""
|
||||
cmd = [
|
||||
"ffprobe", "-v", "quiet",
|
||||
"-print_format", "json",
|
||||
"-show_streams",
|
||||
"-select_streams", "v:0",
|
||||
video_path,
|
||||
]
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
if result.returncode != 0:
|
||||
print(f"Warning: ffprobe failed, using default 720x1280")
|
||||
return 720, 1280
|
||||
streams = json.loads(result.stdout).get("streams", [])
|
||||
if not streams:
|
||||
print(f"Warning: no video stream found, using default 720x1280")
|
||||
return 720, 1280
|
||||
w = int(streams[0]["width"])
|
||||
h = int(streams[0]["height"])
|
||||
return w, h
|
||||
|
||||
|
||||
def get_video_duration(video_path):
|
||||
"""Get video duration in seconds via ffprobe."""
|
||||
cmd = [
|
||||
"ffprobe", "-v", "quiet",
|
||||
"-print_format", "json",
|
||||
"-show_format",
|
||||
video_path,
|
||||
]
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
return float(json.loads(result.stdout)["format"]["duration"])
|
||||
|
||||
|
||||
def find_font():
|
||||
"""Find a suitable font for subtitle rendering (macOS paths)."""
|
||||
for p in [
|
||||
"/System/Library/Fonts/Supplemental/Arial Bold.ttf",
|
||||
"/System/Library/Fonts/Supplemental/Arial.ttf",
|
||||
"/System/Library/Fonts/Helvetica.ttc",
|
||||
"/System/Library/Fonts/SFCompact.ttf",
|
||||
"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", # Linux
|
||||
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", # Linux
|
||||
]:
|
||||
if os.path.exists(p):
|
||||
try:
|
||||
return ImageFont.truetype(p, FONT_SIZE)
|
||||
except Exception:
|
||||
continue
|
||||
return ImageFont.load_default()
|
||||
|
||||
|
||||
def find_chinese_font():
|
||||
"""Find a font that supports Chinese characters (macOS/Linux)."""
|
||||
for p in [
|
||||
"/System/Library/Fonts/STHeiti Medium.ttc", # macOS
|
||||
"/System/Library/Fonts/PingFang.ttc", # macOS
|
||||
"/System/Library/Fonts/Hiragino Sans GB.ttc", # macOS
|
||||
"/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc", # Linux
|
||||
"/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", # Linux
|
||||
]:
|
||||
if os.path.exists(p):
|
||||
try:
|
||||
return ImageFont.truetype(p, FONT_SIZE)
|
||||
except Exception:
|
||||
continue
|
||||
return None
|
||||
|
||||
|
||||
def detect_language(subtitles):
|
||||
"""Detect if subtitles contain Chinese characters."""
|
||||
all_text = "".join(t for _, _, t in subtitles)
|
||||
chinese_chars = sum(1 for c in all_text if '\u4e00' <= c <= '\u9fff')
|
||||
return "zh" if chinese_chars > len(all_text) * 0.1 else "en"
|
||||
|
||||
|
||||
def get_active_subtitle(t):
|
||||
"""Return the subtitle text active at time t, or None."""
|
||||
for start, end, text in SUBTITLES:
|
||||
if start <= t < end:
|
||||
return text
|
||||
return None
|
||||
|
||||
|
||||
def render_frame(text, font, width, height):
|
||||
"""Render a frame with subtitle text (or transparent if None)."""
|
||||
img = Image.new("RGBA", (width, height), (0, 0, 0, 0))
|
||||
if text is None:
|
||||
return img
|
||||
|
||||
draw = ImageDraw.Draw(img)
|
||||
bbox = draw.multiline_textbbox((0, 0), text, font=font, align="center")
|
||||
text_w = bbox[2] - bbox[0]
|
||||
text_h = bbox[3] - bbox[1]
|
||||
x = (width - text_w) // 2
|
||||
y = height - BOTTOM_MARGIN - text_h
|
||||
|
||||
# Draw outline (black border for readability)
|
||||
for dx in range(-OUTLINE_WIDTH, OUTLINE_WIDTH + 1):
|
||||
for dy in range(-OUTLINE_WIDTH, OUTLINE_WIDTH + 1):
|
||||
if dx * dx + dy * dy <= OUTLINE_WIDTH * OUTLINE_WIDTH:
|
||||
draw.multiline_text(
|
||||
(x + dx, y + dy), text, font=font,
|
||||
fill=(0, 0, 0, 255), align="center"
|
||||
)
|
||||
# Draw white text on top
|
||||
draw.multiline_text(
|
||||
(x, y), text, font=font,
|
||||
fill=(255, 255, 255, 255), align="center"
|
||||
)
|
||||
return img
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 3:
|
||||
print("Usage: python3 burn_subs.py <input_video> <output_video>")
|
||||
print()
|
||||
print("Edit the SUBTITLES list in this script before running.")
|
||||
sys.exit(1)
|
||||
|
||||
input_video = sys.argv[1]
|
||||
output_video = sys.argv[2]
|
||||
|
||||
if not SUBTITLES or (len(SUBTITLES) == 1 and "Add your" in SUBTITLES[0][2]):
|
||||
print("Error: No subtitle data. Edit the SUBTITLES list in this script first.")
|
||||
sys.exit(1)
|
||||
|
||||
# Auto-detect video dimensions
|
||||
width, height = detect_video_dimensions(input_video)
|
||||
duration = get_video_duration(input_video)
|
||||
total_frames = int(duration * FPS) + 1
|
||||
|
||||
# Select font based on subtitle language
|
||||
lang = detect_language(SUBTITLES)
|
||||
if lang == "zh":
|
||||
font = find_chinese_font() or find_font()
|
||||
print(f"Detected Chinese subtitles, using CJK font")
|
||||
else:
|
||||
font = find_font()
|
||||
|
||||
print(f"Video: {width}x{height}, {duration:.2f}s, {total_frames} frames @ {FPS}fps")
|
||||
print(f"Subtitles: {len(SUBTITLES)} segments")
|
||||
|
||||
tmpdir = tempfile.mkdtemp(prefix="burn_subs_")
|
||||
print(f"Rendering {total_frames} subtitle frames to {tmpdir}...")
|
||||
|
||||
# Pre-compute: render each unique subtitle once, cache for reuse
|
||||
cached_images = {}
|
||||
blank = Image.new("RGBA", (width, height), (0, 0, 0, 0))
|
||||
|
||||
for frame_num in range(total_frames):
|
||||
t = frame_num / FPS
|
||||
text = get_active_subtitle(t)
|
||||
|
||||
if text is None:
|
||||
img = blank
|
||||
else:
|
||||
if text not in cached_images:
|
||||
cached_images[text] = render_frame(text, font, width, height)
|
||||
img = cached_images[text]
|
||||
|
||||
frame_path = os.path.join(tmpdir, f"frame_{frame_num:05d}.png")
|
||||
img.save(frame_path)
|
||||
|
||||
if frame_num % 100 == 0:
|
||||
print(f" Frame {frame_num}/{total_frames} (t={t:.1f}s)")
|
||||
|
||||
print(f"Rendered {total_frames} frames, {len(cached_images)} unique subtitle images")
|
||||
|
||||
# Step 1: Create subtitle overlay video from PNG sequence (preserves alpha)
|
||||
sub_video = os.path.join(tmpdir, "subs.mov")
|
||||
cmd1 = [
|
||||
"ffmpeg", "-y",
|
||||
"-framerate", str(FPS),
|
||||
"-i", os.path.join(tmpdir, "frame_%05d.png"),
|
||||
"-c:v", "png",
|
||||
"-pix_fmt", "rgba",
|
||||
sub_video,
|
||||
]
|
||||
print("Creating subtitle overlay video...")
|
||||
r1 = subprocess.run(cmd1, capture_output=True, text=True)
|
||||
if r1.returncode != 0:
|
||||
print("Error creating subtitle video:", r1.stderr[-2000:])
|
||||
sys.exit(1)
|
||||
|
||||
# Step 2: Overlay subtitle video onto main video (single pass)
|
||||
cmd2 = [
|
||||
"ffmpeg", "-y",
|
||||
"-i", input_video,
|
||||
"-i", sub_video,
|
||||
"-filter_complex", "[0:v][1:v]overlay=0:0:shortest=1[outv]",
|
||||
"-map", "[outv]",
|
||||
"-map", "0:a",
|
||||
"-c:v", "libx264", "-preset", "fast", "-crf", "18",
|
||||
"-c:a", "copy",
|
||||
output_video,
|
||||
]
|
||||
print("Overlaying subtitles onto video...")
|
||||
r2 = subprocess.run(cmd2, capture_output=True, text=True)
|
||||
if r2.returncode != 0:
|
||||
print("Error overlaying:", r2.stderr[-2000:])
|
||||
sys.exit(1)
|
||||
|
||||
# Cleanup temp files
|
||||
import shutil
|
||||
shutil.rmtree(tmpdir, ignore_errors=True)
|
||||
print(f"Done! Output: {output_video}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,205 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Seedance 视频片段质量审查模板。
|
||||
|
||||
此脚本不直接调用 API,而是:
|
||||
1. 输出标准化的 read_media 审查 prompt
|
||||
2. 解析审查结果 JSON 并给出 PASS/FAIL 判定
|
||||
3. 将审查记录写入 review_log.json
|
||||
|
||||
使用方式:
|
||||
# 生成审查 prompt(供 Claude 调用 read_media 时使用)
|
||||
python3 review_segment.py prompt <segment.mp4>
|
||||
|
||||
# 记录审查结果
|
||||
python3 review_segment.py record <segment.mp4> <PASS|FAIL> <reason> [--log review_log.json]
|
||||
|
||||
# 检查所有片段是否通过审查
|
||||
python3 review_segment.py check [--log review_log.json]
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
# ═══════════════════════════════════════════
|
||||
# 审查标准定义
|
||||
# ═══════════════════════════════════════════
|
||||
|
||||
REVIEW_CRITERIA = {
|
||||
"style": {
|
||||
"name": "风格一致性",
|
||||
"name_en": "Style Consistency",
|
||||
"description": "必须是 3D 皮克斯风格动画,不能是 2D 扁平/写实/其他风格",
|
||||
"weight": "CRITICAL", # CRITICAL = 不通过即 FAIL
|
||||
},
|
||||
"camera": {
|
||||
"name": "分镜切换",
|
||||
"name_en": "Camera Transitions",
|
||||
"description": "15s 片段内必须有至少 2 次镜头切换(全景↔特写),不能全程固定机位",
|
||||
"weight": "CRITICAL",
|
||||
},
|
||||
"audio": {
|
||||
"name": "音频质量",
|
||||
"name_en": "Audio Quality",
|
||||
"description": "对话清晰无乱码、无重叠/重复/AI 噪声,全程可懂",
|
||||
"weight": "CRITICAL",
|
||||
},
|
||||
"character": {
|
||||
"name": "角色一致性",
|
||||
"name_en": "Character Consistency",
|
||||
"description": "角色外观(服装、配饰、体型)与参考图一致",
|
||||
"weight": "IMPORTANT", # IMPORTANT = 警告但可酌情通过
|
||||
},
|
||||
"content": {
|
||||
"name": "内容匹配",
|
||||
"name_en": "Content Match",
|
||||
"description": "对话内容与脚本大致吻合,不必逐字匹配但意思要对",
|
||||
"weight": "IMPORTANT",
|
||||
},
|
||||
}
|
||||
|
||||
# ═══════════════════════════════════════════
|
||||
# 标准化审查 Prompt
|
||||
# ═══════════════════════════════════════════
|
||||
|
||||
REVIEW_PROMPT = """Evaluate this video segment against these 5 criteria. For each criterion, give a PASS or FAIL verdict with a brief reason.
|
||||
|
||||
## Criteria
|
||||
|
||||
1. **STYLE** (Critical): Is this 3D Pixar-style animation? NOT 2D flat/realistic/other styles. Rate: PASS or FAIL.
|
||||
|
||||
2. **CAMERA TRANSITIONS** (Critical): Count the number of distinct camera angle changes (e.g. wide shot → close-up → wide shot). A 15s segment MUST have at least 2 camera changes. List each shot with timestamp. Rate: PASS or FAIL.
|
||||
|
||||
3. **AUDIO QUALITY** (Critical): Is ALL dialogue clear and understandable throughout the entire clip? Check for: garbled speech, overlapping/doubled audio tracks, AI noise/artifacts, nonsensical words. Even a brief 2-second garble = FAIL. Rate: PASS or FAIL.
|
||||
|
||||
4. **CHARACTER CONSISTENCY** (Important): Do characters maintain consistent appearance (clothes, accessories, body type) across shots? Rate: PASS or FAIL.
|
||||
|
||||
5. **CONTENT MATCH** (Important): Does the spoken dialogue roughly match expected content? (Don't need exact words, but the topic/meaning should be right.) Rate: PASS or FAIL.
|
||||
|
||||
## Output Format
|
||||
|
||||
Respond in this exact JSON format:
|
||||
```json
|
||||
{
|
||||
"style": {"verdict": "PASS/FAIL", "reason": "..."},
|
||||
"camera": {"verdict": "PASS/FAIL", "reason": "...", "shot_count": N, "shots": ["0:00-0:05 wide shot", ...]},
|
||||
"audio": {"verdict": "PASS/FAIL", "reason": "...", "garbled_sections": []},
|
||||
"character": {"verdict": "PASS/FAIL", "reason": "..."},
|
||||
"content": {"verdict": "PASS/FAIL", "reason": "..."},
|
||||
"overall": "PASS/FAIL",
|
||||
"summary": "One sentence summary"
|
||||
}
|
||||
```
|
||||
|
||||
OVERALL is PASS only if ALL Critical criteria (style, camera, audio) pass. Important criteria failures are warnings but don't block overall PASS."""
|
||||
|
||||
|
||||
def cmd_prompt(segment_path: str):
|
||||
"""输出标准化的审查 prompt。"""
|
||||
print("=" * 60)
|
||||
print(f"审查片段: {segment_path}")
|
||||
print("=" * 60)
|
||||
print()
|
||||
print("请使用以下 prompt 调用 read_media:")
|
||||
print()
|
||||
print(REVIEW_PROMPT)
|
||||
print()
|
||||
print("审查标准:")
|
||||
for key, c in REVIEW_CRITERIA.items():
|
||||
print(f" [{c['weight']}] {c['name']} ({c['name_en']}): {c['description']}")
|
||||
|
||||
|
||||
def cmd_record(segment_path: str, verdict: str, reason: str, log_path: str = "review_log.json"):
|
||||
"""记录审查结果到 JSON 日志。"""
|
||||
log_file = Path(log_path)
|
||||
if log_file.exists():
|
||||
log = json.loads(log_file.read_text())
|
||||
else:
|
||||
log = {"reviews": [], "segments": {}}
|
||||
|
||||
segment_name = Path(segment_path).name
|
||||
entry = {
|
||||
"segment": segment_name,
|
||||
"path": str(segment_path),
|
||||
"verdict": verdict.upper(),
|
||||
"reason": reason,
|
||||
"timestamp": datetime.now().isoformat(),
|
||||
}
|
||||
log["reviews"].append(entry)
|
||||
log["segments"][segment_name] = entry
|
||||
|
||||
log_file.write_text(json.dumps(log, indent=2, ensure_ascii=False))
|
||||
icon = "✅" if verdict.upper() == "PASS" else "❌"
|
||||
print(f"{icon} {segment_name}: {verdict.upper()} — {reason}")
|
||||
|
||||
|
||||
def cmd_check(log_path: str = "review_log.json"):
|
||||
"""检查所有片段审查状态。"""
|
||||
log_file = Path(log_path)
|
||||
if not log_file.exists():
|
||||
print("未找到审查日志,请先进行审查")
|
||||
sys.exit(1)
|
||||
|
||||
log = json.loads(log_file.read_text())
|
||||
segments = log.get("segments", {})
|
||||
|
||||
if not segments:
|
||||
print("无审查记录")
|
||||
sys.exit(1)
|
||||
|
||||
all_pass = True
|
||||
print("=== 审查状态汇总 ===\n")
|
||||
for name, entry in sorted(segments.items()):
|
||||
icon = "✅" if entry["verdict"] == "PASS" else "❌"
|
||||
print(f" {icon} {name}: {entry['verdict']} — {entry['reason']}")
|
||||
if entry["verdict"] != "PASS":
|
||||
all_pass = False
|
||||
|
||||
print()
|
||||
if all_pass:
|
||||
print("ALL PASS — 所有片段通过审查,可以进行拼接合成")
|
||||
else:
|
||||
failed = [n for n, e in segments.items() if e["verdict"] != "PASS"]
|
||||
print(f"BLOCKED — {len(failed)} 个片段未通过: {', '.join(failed)}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print(__doc__)
|
||||
sys.exit(1)
|
||||
|
||||
cmd = sys.argv[1]
|
||||
|
||||
if cmd == "prompt":
|
||||
if len(sys.argv) < 3:
|
||||
print("用法: python review_segment.py prompt <segment.mp4>")
|
||||
sys.exit(1)
|
||||
cmd_prompt(sys.argv[2])
|
||||
|
||||
elif cmd == "record":
|
||||
if len(sys.argv) < 5:
|
||||
print("用法: python review_segment.py record <segment.mp4> <PASS|FAIL> <reason>")
|
||||
sys.exit(1)
|
||||
log_path = "review_log.json"
|
||||
for i, arg in enumerate(sys.argv):
|
||||
if arg == "--log" and i + 1 < len(sys.argv):
|
||||
log_path = sys.argv[i + 1]
|
||||
cmd_record(sys.argv[2], sys.argv[3], sys.argv[4], log_path)
|
||||
|
||||
elif cmd == "check":
|
||||
log_path = "review_log.json"
|
||||
for i, arg in enumerate(sys.argv):
|
||||
if arg == "--log" and i + 1 < len(sys.argv):
|
||||
log_path = sys.argv[i + 1]
|
||||
cmd_check(log_path)
|
||||
|
||||
else:
|
||||
print(f"未知命令: {cmd}")
|
||||
print(__doc__)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,278 @@
|
||||
#!/usr/bin/env python3
|
||||
"""校验 animal-podcast 搞笑播客脚本格式是否符合规范。
|
||||
|
||||
规则:
|
||||
- 文件头部必须包含元信息(话题、动物组合、目标时长)
|
||||
- 每个场景必须用 ## [SCENE:id] 标题
|
||||
- 每段台词必须包含 **{角色名}:** 标记说话角色
|
||||
- 每段台词必须包含 **画面描述:**
|
||||
- 每段台词必须包含 **时长预估:** Xs
|
||||
- 可选 **音效:** 标记(大笑、惊讶、鼓掌等)
|
||||
- 场景之间用 --- 分隔
|
||||
- scene_id 不能重复
|
||||
- 单段台词时长 3~12s,单场景总时长不超过 20s
|
||||
- 总时长不超过 39s
|
||||
"""
|
||||
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
SCENE_RE = re.compile(r"^##\s+\[SCENE:(\w+)\]\s+(.+)$")
|
||||
SPEAKER_RE = re.compile(r"^\*\*(.+?):\*\*$|^\*\*(.+?):\*\*$")
|
||||
DURATION_RE = re.compile(r"(\d+)s")
|
||||
|
||||
# 非角色台词的系统字段(中文 + 英文)
|
||||
SYSTEM_FIELDS = {"画面描述", "时长预估", "音效",
|
||||
"Visual Description", "Estimated Duration", "SFX"}
|
||||
|
||||
|
||||
def parse_script(path: str) -> tuple[dict, list[dict]]:
|
||||
"""解析 script.md,返回 (元信息, 场景列表)。
|
||||
|
||||
每个场景包含多个台词段(line),每段有 speaker / has_visual / has_duration / duration_seconds。
|
||||
"""
|
||||
text = Path(path).read_text(encoding="utf-8")
|
||||
lines = text.split("\n")
|
||||
|
||||
meta: dict = {"topic": "", "animals": "", "target_duration": "", "aspect_ratio": ""}
|
||||
scenes: list[dict] = []
|
||||
current_scene: dict | None = None
|
||||
current_line: dict | None = None
|
||||
|
||||
in_header = True
|
||||
|
||||
for raw in lines:
|
||||
line = raw.strip()
|
||||
|
||||
# ---------- 文件头元信息 ----------
|
||||
if in_header and not line.startswith("##"):
|
||||
for key, field in [("话题", "topic"), ("动物组合", "animals"),
|
||||
("目标时长", "target_duration"), ("画面比例", "aspect_ratio"),
|
||||
("Topic", "topic"), ("Animal Pairing", "animals"),
|
||||
("Target Duration", "target_duration"), ("Aspect Ratio", "aspect_ratio")]:
|
||||
if line.startswith(f"{key}:") or line.startswith(f"{key}:"):
|
||||
# 只按第一个中/英文冒号拆分,保留值中的冒号
|
||||
if ":" in line:
|
||||
meta[field] = line.split(":", 1)[1].strip()
|
||||
else:
|
||||
meta[field] = line.split(":", 1)[1].strip()
|
||||
break
|
||||
continue
|
||||
|
||||
in_header = False
|
||||
|
||||
# ---------- 场景标题 ----------
|
||||
scene_match = SCENE_RE.match(line)
|
||||
if scene_match:
|
||||
if current_line and current_scene:
|
||||
current_scene["lines"].append(current_line)
|
||||
current_line = None
|
||||
if current_scene:
|
||||
scenes.append(current_scene)
|
||||
current_scene = {
|
||||
"id": scene_match.group(1),
|
||||
"title": scene_match.group(2),
|
||||
"lines": [],
|
||||
}
|
||||
continue
|
||||
|
||||
if current_scene is None:
|
||||
continue
|
||||
|
||||
# ---------- 角色台词标记 ----------
|
||||
speaker_match = SPEAKER_RE.match(line)
|
||||
if speaker_match:
|
||||
speaker_name = (speaker_match.group(1) or speaker_match.group(2)).strip()
|
||||
# 如果是系统字段,不算新台词段
|
||||
if speaker_name in SYSTEM_FIELDS:
|
||||
if current_line:
|
||||
if speaker_name in ("画面描述", "Visual Description"):
|
||||
current_line["has_visual"] = True
|
||||
elif speaker_name in ("时长预估", "Estimated Duration"):
|
||||
current_line["has_duration"] = True
|
||||
# 尝试从同行提取数字
|
||||
m = DURATION_RE.search(line)
|
||||
if m:
|
||||
current_line["duration_seconds"] = int(m.group(1))
|
||||
elif speaker_name in ("音效", "SFX"):
|
||||
current_line["has_sfx"] = True
|
||||
continue
|
||||
|
||||
# 新的角色台词段
|
||||
if current_line:
|
||||
current_scene["lines"].append(current_line)
|
||||
current_line = {
|
||||
"speaker": speaker_name,
|
||||
"has_visual": False,
|
||||
"has_duration": False,
|
||||
"has_sfx": False,
|
||||
"duration_seconds": 0,
|
||||
}
|
||||
continue
|
||||
|
||||
# ---------- 时长预估(可能出现在独立行) ----------
|
||||
if current_line and (line.startswith("**时长预估:**") or line.startswith("**时长预估:**")
|
||||
or line.startswith("**Estimated Duration:**")):
|
||||
current_line["has_duration"] = True
|
||||
m = DURATION_RE.search(line)
|
||||
if m:
|
||||
current_line["duration_seconds"] = int(m.group(1))
|
||||
elif current_line and (line.startswith("**画面描述:**") or line.startswith("**画面描述:**")
|
||||
or line.startswith("**Visual Description:**")):
|
||||
current_line["has_visual"] = True
|
||||
elif current_line and (line.startswith("**音效:**") or line.startswith("**音效:**")
|
||||
or line.startswith("**SFX:**")):
|
||||
current_line["has_sfx"] = True
|
||||
|
||||
# 收尾
|
||||
if current_line and current_scene:
|
||||
current_scene["lines"].append(current_line)
|
||||
if current_scene:
|
||||
scenes.append(current_scene)
|
||||
|
||||
return meta, scenes
|
||||
|
||||
|
||||
def validate(meta: dict, scenes: list[dict]) -> list[str]:
|
||||
"""校验,返回问题列表。"""
|
||||
issues: list[str] = []
|
||||
|
||||
# 元信息检查
|
||||
if not meta["topic"]:
|
||||
issues.append("WARN 文件头缺少 话题:")
|
||||
if not meta["animals"]:
|
||||
issues.append("WARN 文件头缺少 动物组合:")
|
||||
if not meta["target_duration"]:
|
||||
issues.append("WARN 文件头缺少 目标时长:")
|
||||
|
||||
if not scenes:
|
||||
issues.append("ERROR 未找到任何 ## [SCENE:xxx] 场景")
|
||||
return issues
|
||||
|
||||
# scene_id 唯一性
|
||||
ids = [s["id"] for s in scenes]
|
||||
seen: set[str] = set()
|
||||
for sid in ids:
|
||||
if sid in seen:
|
||||
issues.append(f"ERROR scene_id 重复: {sid}")
|
||||
seen.add(sid)
|
||||
|
||||
# 收集所有角色名
|
||||
all_speakers: set[str] = set()
|
||||
total_duration = 0
|
||||
|
||||
for sc in scenes:
|
||||
scene_label = f"[{sc['id']}] {sc['title']}"
|
||||
scene_duration = 0
|
||||
|
||||
if not sc["lines"]:
|
||||
issues.append(f"WARN {scene_label} 没有台词段")
|
||||
|
||||
for idx, ln in enumerate(sc["lines"], 1):
|
||||
line_label = f"{scene_label} 台词#{idx}({ln['speaker']})"
|
||||
all_speakers.add(ln["speaker"])
|
||||
|
||||
if not ln["has_visual"]:
|
||||
issues.append(f"ERROR {line_label} 缺少 **画面描述:**")
|
||||
if not ln["has_duration"]:
|
||||
issues.append(f"ERROR {line_label} 缺少 **时长预估:**")
|
||||
elif ln["duration_seconds"] <= 0:
|
||||
issues.append(f"ERROR {line_label} 时长预估格式错误(应为 Xs,如 8s)")
|
||||
elif ln["duration_seconds"] < 3:
|
||||
issues.append(f"WARN {line_label} 台词过短 ({ln['duration_seconds']}s < 3s)")
|
||||
elif ln["duration_seconds"] > 12:
|
||||
issues.append(f"WARN {line_label} 单段台词过长 ({ln['duration_seconds']}s > 12s)")
|
||||
|
||||
scene_duration += ln["duration_seconds"]
|
||||
|
||||
if scene_duration > 20:
|
||||
issues.append(f"WARN {scene_label} 场景总时长过长 ({scene_duration}s > 20s)")
|
||||
|
||||
total_duration += scene_duration
|
||||
|
||||
# 角色数量检查
|
||||
if len(all_speakers) < 2:
|
||||
issues.append("WARN 只检测到 1 个角色,搞笑播客建议至少 2 个角色对话")
|
||||
|
||||
# 总时长检查(默认上限 39s)
|
||||
if total_duration > 0:
|
||||
if total_duration > 39:
|
||||
issues.append(f"WARN 总时长 {total_duration}s 超出上限 (39s)")
|
||||
elif total_duration < 20:
|
||||
issues.append(f"WARN 总时长 {total_duration}s 过短 (建议 30-39s)")
|
||||
|
||||
return issues
|
||||
|
||||
|
||||
def print_summary(meta: dict, scenes: list[dict], issues: list[str]) -> None:
|
||||
total_lines = sum(len(s["lines"]) for s in scenes)
|
||||
total_duration = sum(
|
||||
ln["duration_seconds"] for s in scenes for ln in s["lines"]
|
||||
)
|
||||
|
||||
# 角色台词统计
|
||||
speaker_stats: dict[str, int] = {}
|
||||
for sc in scenes:
|
||||
for ln in sc["lines"]:
|
||||
speaker_stats[ln["speaker"]] = speaker_stats.get(ln["speaker"], 0) + 1
|
||||
|
||||
print("=== 小动物搞笑播客脚本校验报告 ===\n")
|
||||
print(f"话题: {meta.get('topic', '未指定')}")
|
||||
print(f"动物组合: {meta.get('animals', '未指定')}")
|
||||
print(f"目标时长: {meta.get('target_duration', '未指定')}")
|
||||
print(f"画面比例: {meta.get('aspect_ratio', '未指定')}")
|
||||
print(f"总场景数: {len(scenes)}")
|
||||
print(f"总台词段: {total_lines}")
|
||||
print(f"预估总时长: {total_duration}s ({total_duration // 60}m{total_duration % 60}s)")
|
||||
print()
|
||||
|
||||
# 角色统计
|
||||
print("角色台词分布:")
|
||||
for speaker, count in sorted(speaker_stats.items(), key=lambda x: -x[1]):
|
||||
print(f" {speaker}: {count} 段")
|
||||
print()
|
||||
|
||||
# 场景明细
|
||||
check = lambda v: "Y" if v else "-"
|
||||
print(f"{'场景ID':<14} {'标题':<14} {'台词':>4} {'时长':>6} {'画面':>4} {'时长标记':>6}")
|
||||
print("-" * 56)
|
||||
for sc in scenes:
|
||||
scene_dur = sum(ln["duration_seconds"] for ln in sc["lines"])
|
||||
all_visual = all(ln["has_visual"] for ln in sc["lines"]) if sc["lines"] else False
|
||||
all_dur = all(ln["has_duration"] for ln in sc["lines"]) if sc["lines"] else False
|
||||
print(
|
||||
f"{sc['id']:<14} {sc['title']:<14} {len(sc['lines']):>4} "
|
||||
f"{scene_dur:>5}s {check(all_visual):>4} {check(all_dur):>6}"
|
||||
)
|
||||
|
||||
print()
|
||||
if issues:
|
||||
print(f"发现 {len(issues)} 个问题:\n")
|
||||
for issue in issues:
|
||||
print(f" {issue}")
|
||||
else:
|
||||
print("ALL PASS")
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("用法: python validate_script.py <script.md 路径>")
|
||||
sys.exit(1)
|
||||
|
||||
script_path = Path(sys.argv[1])
|
||||
if not script_path.exists():
|
||||
print(f"ERROR: 文件不存在: {script_path}")
|
||||
sys.exit(1)
|
||||
|
||||
print(f"\n--- {script_path} ---\n")
|
||||
meta, scenes = parse_script(str(script_path))
|
||||
issues = validate(meta, scenes)
|
||||
print_summary(meta, scenes, issues)
|
||||
|
||||
has_error = any("ERROR" in i for i in issues)
|
||||
sys.exit(1 if has_error else 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Binary file not shown.
Reference in New Issue
Block a user