添加字幕
学习如何为视频添加字幕
添加字幕
为视频添加专业字幕,支持单词级别高亮和样式选项。
字幕模式
Video Schema 支持两种字幕模式:
| 模式 | 描述 | 使用场景 |
|---|---|---|
batch | 批量显示多个单词 | 标准字幕 |
stream | 逐个显示单词 | 卡拉OK风格、逐字显示 |
基础字幕片段
{
"type": "subtitle",
"start": 0,
"duration": 10,
"words": [
{ "word": "你好", "punctuated_word": "你好,", "start": 0, "end": 0.5 },
{ "word": "世界", "punctuated_word": "世界!", "start": 0.5, "end": 1.0 }
],
"config": {
"mode": "batch",
"wordsPerBatch": 5,
"fontSize": 48,
"textColor": "#ffffff",
"highlightColor": "#ffff00",
"position": "bottom",
"paddingBottom": 100
}
}单词数据结构
字幕中的每个单词有以下属性:
{
"word": "你好", // 原始单词
"punctuated_word": "你好,", // 带标点
"start": 0.0, // 开始时间(秒)
"end": 0.5, // 结束时间(秒)
"confidence": 0.95 // 可选:置信度
}字幕配置
位置
| 位置 | 描述 |
|---|---|
bottom | 屏幕底部(默认) |
top | 屏幕顶部 |
center | 屏幕中央 |
样式选项
{
"config": {
"fontSize": 48,
"fontFamily": "Arial",
"fontWeight": 700,
"textAlign": "center",
"textBoxWidth": "80%",
"textColor": "#ffffff",
"highlightColor": "#ffff00",
"backgroundColor": "rgba(0,0,0,0.5)",
"shadowColor": "#000000",
"shadowBlur": 10,
"borderColor": "#ffffff",
"borderWidth": 2,
"fadeInAnimation": true,
"position": "bottom",
"paddingBottom": 100
}
}批量模式示例
批量显示多个单词,当前单词高亮:
{
"type": "subtitle",
"start": 0,
"duration": 10,
"words": [
{ "word": "欢迎", "punctuated_word": "欢迎", "start": 0, "end": 0.5 },
{ "word": "来到", "punctuated_word": "来到", "start": 0.5, "end": 0.7 },
{ "word": "我们的", "punctuated_word": "我们的", "start": 0.7, "end": 0.9 },
{ "word": "视频", "punctuated_word": "视频", "start": 0.9, "end": 1.3 },
{ "word": "教程", "punctuated_word": "教程。", "start": 1.3, "end": 1.8 }
],
"config": {
"mode": "batch",
"wordsPerBatch": 5,
"fontSize": 56,
"textColor": "#ffffff",
"highlightColor": "#00ff88",
"backgroundColor": "rgba(0,0,0,0.7)",
"position": "bottom",
"paddingBottom": 120
}
}流式模式示例
逐个显示单词,适合音乐视频或戏剧效果:
{
"type": "subtitle",
"start": 0,
"duration": 5,
"words": [
{ "word": "敢于", "punctuated_word": "敢于", "start": 0, "end": 0.5 },
{ "word": "梦想", "punctuated_word": "梦想", "start": 0.5, "end": 1.0 },
{ "word": "永不", "punctuated_word": "永不", "start": 1.0, "end": 1.3 },
{ "word": "放弃", "punctuated_word": "放弃!", "start": 1.3, "end": 1.8 }
],
"config": {
"mode": "stream",
"fontSize": 72,
"fontWeight": 900,
"textColor": "#ffffff",
"highlightColor": "#ff6b6b",
"position": "center",
"fadeInAnimation": true
}
}使用外部字幕文件
可以引用外部字幕数据:
{
"type": "subtitle",
"words": {
"$ref": "subtitles.main"
},
"config": {
"mode": "batch",
"wordsPerBatch": 8
}
}或从 URL 加载:
{
"type": "subtitle",
"words": {
"src": "https://example.com/subtitles.json"
}
}最佳实践
- 字体大小:移动端使用 48-64px 以确保可读性
- 对比度:确保文字与背景有高对比度
- 时间匹配:精确匹配单词与音频
- 位置:让字幕远离重要视觉内容
- 批量大小:每批 5-8 个单词便于阅读