Assets 资产定义

可复用资源配置

Assets 资产定义

Assets 字段用于定义可复用的资源,如字体、图片、视频、音频等。

字段定义

interface Assets {
  fonts?: FontAsset[];       // 字体资源
  images?: ImageAsset[];     // 图片资源
  videos?: VideoAsset[];     // 视频资源
  audios?: AudioAsset[];     // 音频资源
  subtitles?: SubtitleAsset[]; // 字幕资源
}

资源类型

FontAsset 字体资源

interface FontAsset {
  id: string;      // 资源唯一标识
  src: string;     // 字体文件地址
  family: string;  // 字体名称
}

ImageAsset 图片资源

interface ImageAsset {
  id: string;  // 资源唯一标识
  src: string; // 图片文件地址
}

VideoAsset 视频资源

interface VideoAsset {
  id: string;  // 资源唯一标识
  src: string; // 视频文件地址
}

AudioAsset 音频资源

interface AudioAsset {
  id: string;  // 资源唯一标识
  src: string; // 音频文件地址
}

SubtitleAsset 字幕资源

interface SubtitleWord {
  word: string;              // 单词(无标点)
  punctuated_word: string;   // 带标点的单词
  start: number;             // 开始时间(秒)
  end: number;               // 结束时间(秒)
  confidence?: number;       // 置信度 0-1
}

interface SubtitleAsset {
  id: string;            // 资源唯一标识
  words: SubtitleWord[]; // 字幕词数据
}

示例

{
  "assets": {
    "fonts": [
      {
        "id": "main-font",
        "src": "https://fonts.gstatic.com/s/roboto/v30/font.woff2",
        "family": "Roboto"
      },
      {
        "id": "title-font",
        "src": "https://fonts.gstatic.com/s/playfair/v29/font.woff2",
        "family": "Playfair Display"
      }
    ],
    "images": [
      {
        "id": "logo",
        "src": "https://example.com/images/logo.png"
      },
      {
        "id": "background",
        "src": "https://example.com/images/bg.jpg"
      }
    ],
    "videos": [
      {
        "id": "intro-video",
        "src": "https://example.com/videos/intro.mp4"
      }
    ],
    "audios": [
      {
        "id": "click-sound",
        "src": "https://example.com/sounds/click.mp3"
      }
    ],
    "subtitles": [
      {
        "id": "main-subtitle",
        "words": [
          { "word": "hello", "punctuated_word": "Hello", "start": 0.5, "end": 1.0 },
          { "word": "world", "punctuated_word": "world!", "start": 1.0, "end": 1.5 }
        ]
      }
    ]
  }
}

使用资源引用

定义资源后,可以在 Clip 中通过 { $ref: "id" } 引用:

引用图片

{
  "type": "image",
  "src": { "$ref": "logo" },
  "start": 0,
  "duration": 5
}

引用字体

{
  "type": "text",
  "text": "Hello",
  "style": {
    "fontFamily": { "$ref": "main-font" }
  }
}

引用字幕

{
  "type": "subtitle",
  "start": 0,
  "duration": 10,
  "words": { "$ref": "main-subtitle" }
}

字段说明

字段类型必填描述
idstring资源唯一标识符,用于引用
srcstring资源文件地址(URL)
familystring是(字体)字体名称(仅字体资源)
wordsarray是(字幕)字幕词数据(仅字幕资源)

最佳实践

  1. 使用资源引用:对于重复使用的资源,通过 Assets 定义后引用,避免重复写 URL
  2. 字体加载:确保字体文件格式正确(推荐 WOFF2 格式)
  3. 图片优化:使用 CDN 托管图片,确保加载速度
  4. ID 命名:使用有意义的 ID 名称,如 main-font, logo-image
  5. 缓存策略:资源 URL 应支持缓存控制