通过配置Timeline提交剪辑合成作业时,您需要根据实际业务需求配置此参数。通过阅读本文,您可以了解视频混剪、字幕制作和图片相册的Timeline示例。

属性说明

以下示例中的属性详情,请参见Timeline配置说明

视频混剪

视频添加居中字幕

通过设置"Alignment": "TopCenter"实现顶部居中,同时设置Y值指定字幕和屏幕上侧距离。

{
  "VideoTracks": [
    {
      "VideoTrackClips": [
        {
          "MediaId": "MediaId3",
          "Effects": [
            {
              "Type": "Text",
              "X": 20,
              "Y": 34,
              "Font": "WenQuanYi Zen Hei Mono",
              "Content": "Top Center 时间线是将素材按照视频创意进行编排和特效设计的产物",
              "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": "Center Center -时间线主要包含轨道、素材、效果3种对象",
              "Alignment": "CenterCenter",
              "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": "Bottom Center - 时间线是将素材按照视频创意进行编排和特效设计的产物。时间线主要包含轨道、素材、效果3种对象",
              "Alignment": "BottomCenter",
              "FontSize": 26,
              "FontColor": "#000000"
            }
          ]
        }
      ]
    }
  ]
}
说明
  • Alignment取值:BottomLeft、BottomCenter、BottomRight、CenterLeft、CenterCenter、CenterRight、TopLeft、TopCenter、TopRight。
  • 当Effects中包含Alignment属性时,字幕的X、Y坐标表示margin。

视频加水印——指定水印位置、开始和结束时间

{
    "VideoTracks":[
        {
            "VideoTrackClips":[
                {
                    "MediaId":"****756620ed48c9af022c66ee2e****",
                    "Type":"Video",
                    "TimelineIn":0,
                    "TimelineOut":140,
                    "Duration":140
                }
            ]
        },
        {
            "VideoTrackClips":[
                {
                    "Effects":[
                        {
                            "Type":"Scale",
                            "TimelineIn":0,
                            "TimelineOut":100,
                            "Width":0.416,
                            "Height":0.2347
                        }
                    ],
                    "MediaId":"****8f5cdf044b059b3adc7967ba****",
                    "Type":"Image",
                    "TimelineIn":0,
                    "TimelineOut":100,
                    "Duration":100,
                    "X":0.584,
                    "Y":0
                }
            ]
        }
    ]
}

视频加水印——无需设置Duration(水印时长自适应)

通过使用ImageTracks方式设置水印,无需设置Duration,水印时长自适应。

{
    "VideoTracks":[
        {
            "Count":3,
            "VideoTrackClips":[
                {
                    "MediaId":"****8f5cdf044b059b3adc7967ba****",
                    "Type":"Image",
                    "Duration":5
                },
                {
                    "MediaId":"****756620ed48c9af022c66ee2e****",
                    "Type":"Image",
                    "Duration":5
                },
                {
                    "MediaId":"****8f5cdf044b059b3adc7967ba****",
                    "Type":"Image",
                    "Duration":5
                }
            ]
        }
    ],
    "ImageTracks": [
        {
            "ImageTrackClips": [
                {
                    "ImageId": "****756620ed48c9af022c66ee2e****",
                    "Width" : 200,
                    "Height" : 100,
                    "X" : 100,
                    "Y" : 100
                }
            ]
        }
    ]
}

视频画中画

{
    "VideoTracks":[
        {
            "VideoTrackClips":[
                {
                    "MediaId":"****756620ed48c9af022c66ee2e****",
                    "Type":"Video"
                }
            ]
        },
        {
            "VideoTrackClips":[
                {
                    "Effects":[
                        {
                            "Type":"Scale",
                            "TimelineIn":0,
                            "TimelineOut":100,
                            "Width":0.3,
                            "Height":0.4
                        }
                    ],
                    "MediaId":"****8f5cdf044b059b3adc7967ba****",
                    "Type":"Video",
                    "Duration":100,
                    "X":0.5,
                    "Y":0
                }
            ]
        }
    ]
}

多视频合成并添加转场和背景音乐

{
    "VideoTracks":[
        {
            "VideoTrackClips":[
                {
                    "MediaId":"****8f5cdf044b059b3adc7967ba****",
                    "Effects":[
                        {
                            "Type":"Transition",
                            "SubType":"directional",
                            "Duration":2
                        }
                    ]
                },
                {
                    "MediaId":"****756620ed48c9af022c66ee2e****",
                    "Effects":[
                        {
                            "Type":"Transition",
                            "SubType":"waterdrop",
                            "Duration":1
                        }
                    ]
                },
                {
                    "MediaId":"****8f5cdf044b059b3adc7967ba****"
                }
            ]
        }
    ],
    "AudioTracks":[
        {
            "AudioTrackClips":[
                {
                    "MediaId":"****756620ed48c9af022c66ee2e****"
                }
            ]
        }
    ]
}

图片相册叠加两个音频,音频同时播放

{
    "VideoTracks":[
        {
            "VideoTrackClips":[
                {
                    "Type":"Image",
                    "MediaId":"****8f5cdf044b059b3adc7967ba****",
                    "Duration":10
                },
                {
                    "Type":"Image",
                    "MediaId":"****756620ed48c9af022c66ee2e****",
                    "Duration":10
                },
                {
                    "Type":"Image",
                    "MediaId":"****8f5cdf044b059b3adc7967ba****",
                    "Duration":10
                },
                {
                    "Type":"Image",
                    "MediaId":"****756620ed48c9af022c66ee2e****",
                    "Duration":10
                }
            ]
        }
    ],
    "AudioTracks":[
        {
            "AudioTrackClips":[
                {
                    "MediaId":"****8f5cdf044b059b3adc7967ba****"
                }
            ]
        },
        {
            "AudioTrackClips":[
                {
                    "MediaId":"****756620ed48c9af022c66ee2e****",
                   
                }
            ]
        }
    ]
}

音频循环播放

{
    "VideoTracks": [
        {
            "VideoTrackClips": [
                {
                    "MediaId":"****756620ed48c9af022c66ee2e****",
                }
            ]
        }
    ],
    "AudioTracks": [
        {
            "AudioTrackClips": [
                {
                    "MediaId":"****756620ed48c9af022c66ee2e****",
                    "LoopMode": true,
                    "In": 42,
                    "Out": 58,
                    "TimelineIn": 5,
                    "TimelineOut": 30,
                    "Comment": "将音频42s~58s剪辑出来,在时间线5s~30s上循环播放"
                }
            ]
        }
    ]
}

视频裁剪——去掉上下黑边

此处以将分辨率为1920×1080的视频剪掉上下黑边(黑边高130)并叠加字幕为例介绍。

{
    "VideoTracks":[
        {
            "VideoTrackClips":[
                {
                    "MediaId":"****756620ed48c9af022c66ee2e****",
                    "X":0,
                    "Y":0,
                    "Effects":[
                        {
                            "Type":"Crop",
                            "X":0,
                            "Width":1920,
                            "Height":820,
                            "Y":130
                        }
                    ]
                }
            ]
        }
    ],
    "SubtitleTracks":[
        {
            "SubtitleTrackClips":[
                {
                    "Type":"Subtitle",
                    "SubType":"srt",
                    "FileURL":"https://your-bucket.oss-cn-shanghai.aliyuncs.com/object.srt"
                }
            ]
        }
    ]
}
注意 需要指定输出尺寸OutputConfig
{
    "MediaURL":"https://your-bucket.oss-cn-shanghai.aliyuncs.com/object.mp4",
    "Width":1920,
    "Height":820
}

使用GIF贴纸

使用GIF贴纸时需要设置DyncFrames(动图帧率)。

{
    "VideoTracks": [{
        "VideoTrackClips": [{
            "MediaURL": "http://example-bucket.oss-cn-shanghai.aliyuncs.com/example.mp4"
        }]
    }, {
        "VideoTrackClips": [{
            "MediaURL": "http://example-bucket.oss-cn-shanghai.aliyuncs.com/example.gif",
            "Type": "Image",
            "DyncFrames": 8,
            "TimelIneIn": 0.0,
            "TimelIneOut": 50.0,
            "X": 50,
            "Y": 50,
            "Effects": [{
                "Type": "Scale",
                "Height": 100,
                "Width": 100
            }]
    }]
}

调色滤镜

{
  "VideoTracks": [{
    "VideoTrackClips": [{
      "TimelineIn": 0,
      "Type": "Video",
      "Out": 10,
      "MediaId": "MediaId1",
      "Effects": [{
        "SubType": "color",
        "ExtParams": "effect=color,brightness=80,contrast=0,saturation=0,kelvin_temperature=6000,temperature_ratio=0,tint=0,dark_corner_ratio=0",
        "Type": "Filter",
        "TimelineIn": 0,
        "TimelineOut": 10
      }]
    }]
  }]
}

音视频变速

Clip中使用Speed属性可以修改音视频播放速率,变速后会修改Clip的时长。例如,Clip中Out为10s,Speed为2时,Clip在Timeline中的实际时长为5s,则TimelineOut应修改为5。如果TimelineIn、TimelineOut未设置,合成时会根据In、Out、Speed自动计算Clip在时间线中的位置。

{
  "VideoTracks": [{
    "VideoTrackClips": [{
      "MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your-video.mp4",
      "Speed": 2,
      "Out": 10,
      "TimelineIn": 0,
      "TimelineOut": 5
    }, {
      "MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your-video.mp4",
      "Speed": 0.5,
      "In": 10,
      "Out": 20
    }]
  }],
  "AudioTracks": [{
    "AudioTrackClips": [{
      "MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your-audio.mp3",
      "Speed": 2
    }]
  }]
}

素材旋转

通过设置"Type": "Rotate"旋转素材一定角度,目前仅支持旋转90°、180°、270°。

  • 视频轨素材旋转
    {
      "VideoTracks": [
        {
          "VideoTrackClips": [
            {
              "MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your-video.mp4",
              "In": 0,
              "Out": 5,
              "Effects": [
                {
                  "Type": "Rotate",
                  "Degree": 90
                }
              ]
            }
          ]
        }
      ]
    }
  • 图片轨素材旋转
    {
      "VideoTracks": [
        {
          "VideoTrackClips": [
            {
              "MediaId": "MediaId1",
              "In": 0,
              "Out": 15
            }
          ]
        }
      ],
      "ImageTracks": [
        {
          "ImageTrackClips": [
            {
              "ImageId": "ImageId1",
              "Width": 0.9,
              "Height": 0.9,
              "X": 0.15,
              "Y": 0.15,
              "Effects": [
                {
                  "Type": "Rotate",
                  "Degree": 90
                }
              ]
            }
          ]
        }
      ]
    }

绿幕抠图

将被摄物体从绿幕背景色中抠出,叠加到指定的背景视频或图片上。

{
    "VideoTracks": [
        {
            "VideoTrackClips": [
                {
                    "MediaId": "MediaId1",
                    "Type": "Image",
                }
            ]
        },
        {
            "VideoTrackClips": [
                {
                    "MediaId": "MediaId2",
                    "Y": 0.4,
                    "Width": 0.7,
                    "Height": 0.7,
                    "Effects": [
                        {
                            "Type": "AI_Matting",
                            "Color": "green",
                            "Auto": 1,
                            "Thres": 10
                        },
                        {
                            "Type": "Volume",
                            "Gain": "0"
                        }
                    ]
                }
            ]
        },
        {
            "VideoTrackClips": [
                {
                    "MediaId": "MediaId3",
                    "X": 0.5,
                    "Y": 0.1,
                    "Width": 0.45,
                    "Height": 0.45
                }
            ]
        }
    ]
}

去台标

{
    "VideoTracks": [
        {
            "VideoTrackClips": [
                {
                    "MediaId": "MediaId3",
                    "Effects": [
                        {
                            "Type": "AI_Delogo"
                        }
                    ]
                }
            ]
        }
    ]
}

视频轨道中使用全局图片

在视频轨中使用全局图片GlobalImage时,不需要设置图片时长,默认所有视频轨合并后的时长,可以用来在时间线中设置全局背景或全局水印。

  • 设置全局水印
    {
        "VideoTracks": [
            {
                "VideoTrackClips": [
                    {
                        "MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your-video/1.mp4"
                    }
                ]
            },
            {
                "VideoTrackClips": [
                    {
                        "MediaURL": "https://oushu-test-shanghai.oss-cn-shanghai.aliyuncs.com/test_media/doc_video/aliyun_logo_white.png",
                        "Type": "GlobalImage",
                        "X": 0.1,
                        "Y": 0.1,
                        "Width": 247,
                        "Height": 74
                    }
                ]
            }
        ]
    }
  • 设置全局背景
    {
        "VideoTracks": [
            {
                "VideoTrackClips": [
                    {
                        "MediaURL": "https://your.oss-cn-shanghai.aliyuncs.com/your-video/720P_background.jpg",
                        "Type": "GlobalImage"
                    }
                ]
            },
            {
                "VideoTrackClips": [
                    {
                        "MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your-video/1.mp4",
                        "Effects": [
                            {
                                "Type": "Volume",
                                "Gain": 0
                            }
                        ]
                    }
                ]
            }
        ]
    }

视频轨中设置出点MaxOut

通过设置出点MaxOut截取视频,规则如下:

  • 如果MaxOut值小于素材原时长,素材片段相对于素材的出点将被设置为MaxOut,用于截取素材。
  • 如果MaxOut值大于素材原时长,素材片段相对于素材的出点将被设置为素材原时长,用于自适应素材出点。
{
    "VideoTracks": [
        {
            "VideoTrackClips": [
            {
                "MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your-video/1.mp4",
                "MaxOut": 10
            },{
                "MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your-video/1.mp4",
                "Effects": [{
                "Type": "Scale",
                "Width": 0.8,
                "Height": 0.8
            }]
        }]
    }]
}
注意
  • 和设置MaxOut不同,如果通过设置Out截取视频且Out值大于素材原时长时,会出现静帧。
  • 如果同时设置MaxOutOut,实际效果会以Out为准,MaxOut的值会失效。

随机效果

Timeline中支持设置多种随机效果,例如:随机截取、随机滤镜、随机特效、随机转场。

  • 随机截取:从原始素材中随机截取一个指定时长的片段插入到时间线中。
  • 随机滤镜:从指定范围滤镜或所有滤镜效果中随机选取一个。
  • 随机特效:从指定范围特效或所有特效效果中随机选取一个。
  • 随机转场:从指定范围转场或所有转场效果中随机选取一个。
{
    "VideoTracks": [
        {
            "VideoTrackClips": [
                {
                    "MediaId": "******e25a5d47498672f7a2f7******",
                    "TimelineIn": 0,
                    "Effects": [
                        {
                            "Comment": "从所有转场类型中随机选取一个",
                            "Type": "Transition",
                            "SubType": "random",
                            "Duration": 1
                        },
                        {
                            "Comment": "从该素材中随机截取5s的素材片段",
                            "Type": "Clip",
                            "SubType": "RandomClip",
                            "ClipDuration": 5
                        }
                    ]
                },
                {
                    "MediaId": "******e25a5d47498672f7a2f7******",
                    "TimelineIn": 5,
                    "Effects": [
                        {
                            "Comment": "从open,zoom,disappear中随机选取一个特效",
                            "Type": "VFX",
                            "SubType": "open,zoom,disappear"
                        }
                    ]
                },
                {
                    "MediaId": "******e25a5d47498672f7a2f7******",
                    "TimelineIn": 10,
                    "Effects": [
                        {
                            "Comment": "pl4,colorfulstarry,flyfire中随机选取一个滤镜",
                            "Type": "Filter",
                            "SubType": "pl4,colorfulstarry,flyfire"
                        }
                    ]
                }
            ]
        }
    ]
}

字幕制作

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

通过添加\n\\n实现换行,添加Alignment属性设置对齐方式。

{
  "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属性添加自有版权的字体文件OSS地址,支持TTF、OTF、WOFF格式。

{
 "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"
   }]
  }]
 }]
}
说明 设置自有版权字体时,无需再设置字体Font属性。如果同时设置,系统会按照自有版权字体设置字幕。

智能字幕

通过设置"Type": "AI_ASR",系统会根据视频或音频中的声音生成字幕。

{
  "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"
   }]
  }]
 }]
}

图片相册

制作不带字幕的图片相册

设置图片展示顺序和每张图片的持续时长Duration创建图片幻灯片视频。

{
  "VideoTracks": [
      {
          "VideoTrackClips": [
              {
                "Type": "image",
                "MediaId": "****756620ed48c9af022c66ee2e****",
                "Duration": 3
              },
              {
                "Type": "image",
                "MediaId": "****3a6df8cb4b6fa2faeb9ad094****",
                "Duration": 3
              },
              {
                "Type": "image",
                "MediaId": "****c44c6b574f14859f51beca10****",
                "Duration": 3
              }
          ]
      }
  ]
}

制作带字幕的图片相册

设置图片展示顺序和每张图片的持续时长Duration,同时设置Effects属性,创建带字幕的图片幻灯片视频。

{
    "VideoTracks": [{
      "VideoTrackClips": [{
        "Type": "image",
        "MediaId": "****756620ed48c9af022c66ee2e****",
        "Effects": [
          {
            "Type": "Text",
            "X": 33,
            "Y": 34,
            "Font": "WenQuanYi Zen Hei Mono",
            "Content": "测试文字",
            "FontSize": 26,
            "FontColorOpacity": 1,
            "FontColor": "#000000",
            "FontFace": {
              "Bold": true,
              "Italic": false,
              "Underline": false
            }
          }
        ],
          "Duration": 5
      }, {
        "Type": "image",
        "MediaId": "****3a6df8cb4b6fa2faeb9ad094****",
        "Duration": 5
      }, {
        "Type": "image",
        "MediaId": "****c44c6b574f14859f51beca10****",
        "Effects": [
          {
            "Type": "Text",
            "X": 0.7123,
            "Y": 0.7896,
            "TimelineIn": 11,
            "TimelineOut": 13,
            "Font": "WenQuanYi Zen Hei Mono",
            "Content": "测试文字",
            "FontSize": 26,
            "FontColor": "#000000"
          }
        ],
        "Duration": 5
      }]
    }]
  }