字幕制作Timeline示例

本文介绍智能媒体服务目前支持的字幕制作能力的时间线示例。字幕相关字段见Timeline中的字幕轨道SubtitleTrack,或者见Type=Text的Effect

视频添加换行字幕并设置对齐方式

换行:您可以在字幕文本Content中需要换行的位置插入“\n”或者“\\n”实现字幕指定位置的换行。

换行后对齐:可以在Alignment中设置“TopCenter”、“TopLeft”和“TopRight”实现文字换行后的居中对齐、左对齐和右对齐。

{
  "VideoTracks": [
    {
      "VideoTrackClips": [
        {
          "MediaId": "MediaId3",
          "Effects": [
            {
              "Type": "Text",
              "X": 20,
              "Y": 34,
              "Font": "WenQuanYi Zen Hei Mono",
              "Content": "在Content中添加\n来实现换行,Alignment设置TopCenter来实现字幕换行后居中对齐",
              "Alignment": "TopCenter",
              "FontSize": 26,
              "FontColorOpacity": 1,
              "FontColor": "#ff0000",
              "FontFace": {
                "Bold": true,
                "Italic": false,
                "Underline": false
              }
            },
            {
              "Type": "Text",
              "X": 100,
              "Y": 200,
              "Font": "WenQuanYi Zen Hei Mono",
              "Content": "在Content中添加\n来实现换行,Alignment设置TopLeft来实现字幕换行后左对齐",
              "Alignment": "TopLeft",
              "FontSize": 26,
              "FontColorOpacity": 0.8,
              "FontColor": "#ff0000"
            },
            {
              "Type": "Text",
              "X": 0.10,
              "Y": 0.1,
              "TimelineIn": 2,
              "TimelineOut": 15,
              "Font": "WenQuanYi Zen Hei Mono",
              "Content": "在Content中添加\n来实现换行,Alignment设置TopRight来实现字幕换行后右对齐",
              "Alignment": "TopRight",
              "FontSize": 26,
              "FontColor": "#000000"
            }
          ]
        }
      ]
    }
  ]
}

字幕特效+花字配置示例

花字效果:在设置花字时,您需要设置花字类型字段EffectColorStyle且需要设置描边和阴影的宽度和颜色。设置字段以及示例见花字示例文档

字幕特效:循环特效不可以与入场和出场特效共同存在,入场、出场特效优先级高于循环特效。

{
  "VideoTracks": [{
    "VideoTrackClips": [{
      "MediaId": "MediaId1",
      "Effects": [{
        "Type": "Text",
        "X": 33,
        "Y": 34,
        "Font": "WenQuanYi Zen Hei Mono",
        "Content": "brushed_aluminium花字,rotateflip_in入场特效,slide_down_out出场特效",
        "OutlineColour": "#4effcf",
        "BackColour": "#2effc6",
        "Outline": 2,
        "Shadow": 2,
        "EffectColorStyle": "brushed_aluminium",
        "FontSize": 42,
        "AaiMotionInEffect": "rotateflip_in",
        "AaiMotionIn": 1,
        "AaiMotionOutEffect": "slide_down_out",
        "AaiMotionOut": 1,
        "FontFace": {
          "Bold": true,
          "Italic": false,
          "Underline": false
        }
      },
        {
          "Type": "Text",
          "X": 66,
          "Y": 256,
          "Font": "WenQuanYi Zen Hei Mono",
          "Content": "deep_sea花字,rainbrush_display循环特效,快速循环",
          "EffectColorStyle": "deep_sea",
          "OutlineColour": "#e9e9e9",
          "BackColour": "#30335c",
          "Outline": 2,
          "Shadow": 2,
          "AaiMotionLoopEffect": "rainbrush_display",
          "Ratio": 2,
          "FontSize": 38,
          "FontColorOpacity": 0.8,
          "FontColor": "#d60e0e"
        }
      ]
    }]
  }]
}

直接使用字幕文件进行剪辑时间线示例

{
  "VideoTracks": [
    {
      "VideoTrackClips": [
        {
          "MediaId": "MediaId1"
        },
        {
          "MediaId": "MediaId3"
        }
      ]
    }
  ],
  "SubtitleTracks": [
    {
      "SubtitleTrackClips": [
        {
          "Type": "Subtitle",
          "SubType": "srt",
          "FileUrl": "http://your-bucket.oss-cn-shanghai.aliyuncs.com/your-subtitle.srt"
        }
      ]
    }
  ]
}

使用自有版权的字体进行字幕制作示例

当您使用FontUrl时,无需再设置字体名称Font字段,只需要在FontUrl字段传入您的字体文件OSS地址即可。字体格式支持ttf、otf、woff。当您同时设置字体Font和字体文件FontUrl时,会按照您的字体文件FontUrl来生成字幕。

{
 "VideoTracks": [{
  "VideoTrackClips": [{
   "MediaId": "MediaId1",
   "Effects": [{
    "Type": "Text",
    "X": 33,
    "Y": 34,
    "Content": "使用自定义字体",
    "FontSize": 42,
    "FontUrl": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_font.ttf"
   }]
  }]
 }]
}

智能字幕

智能字幕会提取您视频或者音频中声音来生成字幕。

{
  "VideoTracks": [{
    "VideoTrackClips": [{
      "MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video7.mp4",
      "Effects": [{
        "Type": "AI_ASR",
        "Font": "AlibabaPuHuiTi",
        "Alignment": "TopCenter",
        "Y": 910,
        "Outline": 10,
        "OutlineColour": "#ffffff",
        "FontSize": 60,
        "FontColor": "#000079",
        "FontFace": {
          "Bold": true,
          "Italic": false,
          "Underline": false
        }
      }]
    }]
  }]
}

字幕设置纯色背景

您可以通过设置字幕参数中BorderStyle = 3并设置字幕Outline(边框宽度)和OutlineColour(边框颜色)来实现字幕纯色背景设置。

{
 "VideoTracks": [{
  "VideoTrackClips": [{
   "MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video.mp4",
   "Effects": [{
    "Type": "Text",
    "X": 33,
    "Y": 34,
    "Content": "设置字幕纯色背景",
    "FontSize": 42,
    "BorderStyle": 3,
    "FontColor": "#4B0082",
    "Outline": 3,
    "OutlineColour": "#FFDEAD"
   }]
  }]
 }]
}

阿里云首页 智能媒体生产 相关技术圈