常见Timeline示例

本文向您介绍多视频混剪timeline。使用timeline合成请参考提交剪辑合成作业

本文介绍一些稍微复杂的时间线使用场景,开发指南中也包含了时间线基本功能的使用示例,方便客户对视频进行简单的处理:

  • 剪切合并:实现整段视频合成、保留片头剪切、保留片尾剪切、掐头去尾、多段视频截取任意区间合并、视频与图片混剪等。

  • 音频处理:实现音频处理的各种场景,如静音、混音、音频提取、音量调节、配音等。

  • 图片叠加:实现全程叠加图片、指定区域叠加图片等,包括单视频叠加和多视频叠加。

  • 文字叠加:实现全程叠加文字、指定区域叠加文字、外挂字幕、花字效果配置等。

  • 转场、特效、滤镜:实现视频片段间转场,特效、滤镜效果配置等。

视频添加居中字幕

可以通过设置 "Alignment": "TopCenter" 来顶部居中, 同时设置 字幕的Y值指定跟屏幕上侧的距离。

Alignment取值:BottomLeft,BottomCenter,BottomRight,CenterLeft,CenterCenter,CenterRight,TopLeft,TopCenter,TopRight。

当指定了Alignment时,x,y 值被当做 margin。

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

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

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

视频加水印2:无需设置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****",
                   
                }
            ]
        }
    ]
}

视频裁剪-去掉电影上下黑边

将1920 * 1080视频剪掉上下黑边(黑边高130),并叠加字幕。

注意需要指定输出尺寸。

OutputConfig:

{
    "MediaURL":"https://your-bucket.oss-cn-shanghai.aliyuncs.com/object.mp4",
    "Width":1920,
    "Height":820
}

Timeline

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

使用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
            }]
    }]
}

颜色滤镜

注意要调整ExtParams来实现调色滤镜。

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

ExtParams参数说明:

参数

类型

取值范围

说明

默认值

brightness

int

[-255,255]

亮度

0

contrast

int

[-100,100]

对比度

0

saturation

int

[-100,100]

饱和度

0

kelvin_temperature

int

[1000,40000]

温度,配合

temperature_ratio生效

6000

temperature_ratio

int

[0,100]

温度比例

0

tint

int

[-100,100]

色调

0

dark_corner_ratio

int

[0,100]

暗角比例

0

音视频变速

Clip中使用Speed可修改音视频播放速率,变速后会修改Clip的时长,如:

Clip Out为10s,Speed为2时,Clip在Timeline中的实际时长为5s,对应TimelineOut应做对应修改,当未填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
    }]
  }]
}

素材旋转

视频轨和图片轨中的Clip中可添加Rotate Effect,使素材旋转一定角度,目前仅支持旋转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"
                        }
                    ]
                }
            ]
        }
    ]
}

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