Communitygithub.com

动态字幕动画

当用户要求“添加动画字幕”、“制作 TikTok 字幕”、“卡拉 OK 字幕”、“逐词字幕”、“自动字幕”、“高亮当前单词”、“将字幕嵌入视频”或“将 SRT/转录文本转为动画文本”时使用。涵盖 Whisper 的词级时间戳、逐词弹出/缩放进入、当前词高亮、9:16 安全区域布局、可读字体以及嵌入字幕与旁白 SRT/VTT。

动态字幕动画 是什么?

该技能专注于将语音转录或旁白转换为逐词时间同步的动画字幕,特别适用于 TikTok、Reels 和 Shorts 等短视频平台。它使用 Whisper 等工具获取精确的逐词时间戳,并通过 Remotion 或纯 CSS 实现每个单词的弹出动画和当前高亮效果,确保字幕与旁白完美同步。技能强调两核心规则:必须使用词级时间戳(而非行级),以及可读性高于样式(使用粗体无衬线字体、高对比度、描边和阴影)。它支持在 9:16 纵向视频的安全区域内放置字幕,并同时输出嵌入字幕(MP4)和独立 SRT/VTT 文件,兼顾社交媒体和可访问性需求。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ItsMeMal/mallss3d-motion/tree/main/.claude/skills/caption-animation

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

动态字幕动画 是做什么的?

将转录文本或旁白转化为逐词时间同步、令人目不转睛的字幕:每个单词在音节上弹出,当前单词高亮,文本始终与叙述紧紧贴合。打造那些能够促进 TikTok、Reels 和 Shorts 观看时长的字幕——可读、合拍、且位于安全区域内。

何时使用

  • 在短视频(9:16)上制作逐词或卡拉 OK 风格字幕。
  • 将转录文本作为字幕嵌入到旁白/叙述音轨中。
  • 将 Whisper/SRT 转录文本转化为 Remotion 或网页上的动画文本。
  • 将自动生成的字幕重新样式化为品牌化的、"Hormozi 风格"的逐词揭示效果。

处理流程

阶段任务工具
转录音频 → 词级时间戳Whisper (@remotion/install-whisper-cpp), AssemblyAI
标准化→ { text, startMs, endMs }[] 令牌@remotion/captions Caption 类型
分页将单词分组为 1–4 个单词的“页面”createTikTokStyleCaptions()
动画逐词弹出 + 当前词高亮Remotion spring() / CSS
放置安全区域、可读字体以下布局规则
导出嵌入字幕 (MP4) 和/或旁白 SRT/VTTRemotion 渲染 / 文件输出

两个不可妥协的规则

  1. 词级时间戳,而非行级。 只有当每个单词在音节上准确落地时,卡拉 OK 效果才显得神奇。始终使用逐词时间戳进行转录;切勿通过将一行文本的平均时长拆分来伪造时间戳——漂移会立刻显现。
  2. 可读性优于样式。 字幕是在手机上、阳光下、静音状态下阅读的。首先确保粗体无衬线字体、厚重描边或阴影、高对比度;其次才是装饰。没人能读的字幕只是装饰,而不是字幕。

从转录文本获取词级时间

Whisper 可以直接输出词级时间戳。将所有来源标准化为一种平坦的令牌格式,这样渲染器就无需关心单词的来源:

// 字幕令牌——所有下游消费的统一格式
type Token = { text: string; startMs: number; endMs: number };

// 解析 SRT 提示块 "00:00:01,200 --> 00:00:01,640" 为毫秒
const toMs = (t: string) => {
  const [h, m, rest] = t.split(":");
  const [s, ms] = rest.split(",");
  return ((+h * 60 + +m) * 60 + +s) * 1000 + +ms;
};

如果只有句子级提示存在,请重新转录以获得词级时间戳——不要插值。Whisper 的 medium.en 比 large 快约 2 倍,对于清晰的语音音频来说足够准确。

逐词弹出动画 (Remotion)

将每个单词的缩放和透明度驱动到以其自身 startMs 为锚点的弹簧上。微小的过冲使其感觉“有生命力”。

import { useCurrentFrame, useVideoConfig, spring, interpolate } from "remotion";

const Word: React.FC<{ token: Token; active: boolean }> = ({ token, active }) => {
  const frame = useCurrentFrame();
  const { fps } = useVideoConfig();
  const enter = (token.startMs / 1000) * fps;            // 单词自身的入场帧
  const p = spring({ frame: frame - enter, fps, config: { damping: 12, mass: 0.6 } });
  const scale = interpolate(p, [0, 1], [0.6, 1]);        // 从 60% 弹出到 100%(带过冲)
  return (
    <span style={{
      display: "inline-block",
      transform: `scale(${scale})`,
      opacity: interpolate(p, [0, 1], [0, 1]),
      color: active ? "#FFE45E" : "#FFFFFF",             // 当前词高亮
      transition: "color 80ms linear",
    }}>{token.text}&nbsp;</span>
  );
};

通过检查 frame 是否在令牌的 [startMs, endMs] 范围内来计算 active 状态。将高亮保持为单一强调色或当前词后的填充“框”——切勿同时动画化所有单词的颜色。

分页,而非文本墙

一次显示 1–4 个单词。使用 Remotion 的 createTikTokStyleCaptions()(或手动分组),并调整 combineTokensWithinMilliseconds:约 200–500 毫秒用于真正的逐词显示,约 1000–1500 毫秒用于简短可读的短语。

import { createTikTokStyleCaptions } from "@remotion/captions";
const { pages } = createTikTokStyleCaptions({
  captions, combineTokensWithinMilliseconds: 1200,       // 每页约 2–3 个词
});

网页/CSS 弹出动画(无需 Remotion)

对于 DOM/实时播放器,为每个单词设置与 startMs 相等的 animation-delay:

.word { display:inline-block; opacity:0; animation: pop .26s cubic-bezier(.34,1.56,.64,1) forwards; }
@keyframes pop { from { opacity:0; transform:translateY(.18em) scale(.7) } to { opacity:1; transform:none } }
.word.active { color:#FFE45E; }
words.forEach(w => { const el = mk(w.text); el.style.animationDelay = `${w.startMs}ms`; track.append(el); });

可读字体与安全区域放置(9:16,1080×1920)

属性值原因
字体粗体/超粗体无衬线(Montserrat, Inter, Helvetica)在小而繁忙的屏幕上可读
字号56–80px(约帧高度的 8%),最小 45px在手机上静音状态下清晰可见
描边2–6px 纯黑色轮廓在任何背景下保持可见
阴影作为描边备份的柔和投影在明亮帧上提供分离度
大小写全大写或句子大小写;高对比度填充冲击力 + 可扫描性
垂直位置中心带,约向下 62–70%位于 UI 之上,动作之下
底部安全保持远离底部约 280px / 15%避免字幕/CTA/音频 UI
侧面安全保持在中心宽度的 80% 内避免右侧图标

将字幕放置在中心带——而非固定在底部,平台 UI(用户名、音频、按钮)就在那里。文本最多填充约 2 行。

与旁白/叙述同步

转录文本已经携带了确切音频的时间信息。将该音频直接放置在合成下方,并保持时间戳在音频的时间基准内——字幕和语音将自动锁定,无需手动调整。如果重新录制了旁白,请重新转录;切勿手动偏移时间。

嵌入字幕 vs 旁白 SRT/VTT

嵌入字幕(开放)旁白 SRT/VTT(封闭)
位置MP4 中的像素独立的 .srt/.vtt 文件
社交媒体(TikTok/Reels)必须——保证显示,可设置样式通常被平台忽略
可访问性(ADA/WCAG)单独使用不满足要求必须(可切换)
最佳实践为社交媒体嵌入动画字幕同时为网页/SEO 提供旁白文件

两者都输出:为社交媒体嵌入动画字幕,并从相同的令牌生成纯文本 SRT/VTT 以实现可访问和 SEO 回放。

输出检查清单

  • 词级时间戳(真实,来自转录)——无等分伪造。
  • 逐词弹出并带有微过冲;当前单词一种强调色。
  • 每页 1–4 个单词;决不出现文本墙。
  • 粗体无衬线,56–80px,2–6px 描边 + 阴影,高对比度。
  • 中心带,远离底部约 280px 和侧栏。
  • 音频放置在合成下方;时间戳在音频时间基准内。
  • 为社交媒体提供嵌入字幕,为可访问性提供旁白 SRT/VTT。

交付与验证(渲染静帧 → MP4)

打包助手 (scripts/):使用 scripts/contact-sheet.sh sheet.png f-hook.png f-mid.png f-end.png 平铺您的静帧,然后使用 scripts/probe-mp4.sh out.mp4 [WxH] [fps] 验证编码。参见 scripts/README.md。

字幕作为 Remotion 组合(<Composition> + zod schema + defaultProps)提供——所有单词运动都由 useCurrentFrame() 基于帧驱动,绝不使用 Date.now() / Math.random() / 定时器。可交付物 = out/*.mp4(嵌入字幕)+ 项目 + 旁白 SRT/VTT。9:16 纵向(1080×1920)为默认。

验证循环——渲染静帧 → 检查 → 编码。 词级时间戳是最容易出问题的环节;在开始编码前,在精确的帧上检查它。

# 在开始 / 采样当前词帧 / 结束处渲染静帧——使用已提供的属性(真实令牌 + 音频)
npx remotion still Captions out/f-start.png --frame=0   --props='{"captionsSrc":"vo.json"}'
npx remotion still Captions out/f-mid.png   --frame=90  --props='{"captionsSrc":"vo.json"}'
npx remotion still Captions out/f-end.png   --frame=N   --props='{"captionsSrc":"vo.json"}'  # N = durationInFrames-1

# 检查每个 PNG:
#  - 在第 90 帧高亮的单词是 [startMs,endMs] 包含 90/fps 的那个(无漂移)
#  - 嵌入字幕清晰可读:粗体无衬线,描边+阴影保持,无裁剪
#  - 9:16 安全区域:字幕位于中心带,远离顶部约 12% 和底部约 20-35%(字幕/CTA/音频 UI)以及右侧操作栏

npx remotion render Captions out/captions.mp4 --props='{"captionsSrc":"vo.json"}'   # 静帧正确后再编码
npx remotion render Captions out/demo.gif --codec=gif                                # README 证明剪辑

使用 npx remotion compositions 读取 durationInFrames/fps 并选择当前词帧和结束帧。

完成之前:

  1. 静帧在第 0 帧、一个中间当前词帧和最后一帧处渲染清晰——无缺失字体/音频。
  2. 在采样的帧处高亮了正确的单词(frame/fps 落在其令牌内);无等分伪造。
  3. 嵌入字幕清晰可读(描边+阴影),并且在每个检查的帧上字幕完全位于 9:16 安全区域内。
  4. 仅基于帧驱动——无 Date.now() / Math.random() / 定时器。
  5. 已提供的属性(真实令牌,不仅仅是 defaultProps)正确渲染;输出 MP4 + 旁白 SRT/VTT,GIF 可选。

参考文件

  • references/word-timed-captions.md — 端到端构建:Whisper 转录和 Caption 类型、完整的 SRT 解析器、带当前词高亮的 Remotion 逐词组件、手动分页、SRT/VTT 发射器、各平台安全区域映射以及可读字体规范表。

Individual skills in this repo

This repo contains 3 individual skills — each has its own dedicated page.

short-form-video

This skill should be used when the user asks to "make a Reels/TikTok/YouTube Shorts video", "build a short-form video template", "write a hook for a short", "edit for retention", "add pattern interrupts", "make a video loop", "fix the first 3 seconds", "pace cuts for a vertical video", or "set up 9:16 safe areas". Covers the hook→retention→loop grammar of vertical short-form (distinct from a launch hype film).

talking-head-b-roll

Add b-roll motion graphics to a talking-head video. Transcribes the recording with word timings, decides line by line when the speaker is shown, when a graphic is laid over them and when a full-frame graphic covers them, draws each graphic from what is actually said (numbers, comparisons, steps, key words) in JavaScript on a canvas, and renders the finished MP4 with the original sound, plus the b-roll alone with alpha for an editor. Use when someone has a recording of a person talking to camera (a talking head, a spoken explainer, a course lesson, an ad read, a podcast clip) and wants it more engaging to watch, wants b-roll, or wants motion graphics added to it.

text-message-animation

This skill should be used when the user asks to "make a fake text message video", "animate an iMessage conversation", "create a text story video", "do a chat reply animation", "WhatsApp/SMS conversation video", "typing indicator animation", "render a chat thread to a video", or "batch text-message videos from a script/CSV". Covers sent/received bubble layout, staggered appear timing with typing indicators, read receipts/timestamps, per-message pop sound-sync, 9:16 safe-area, and data-driven render from a messages array.

相关技能