编辑视频

最近更新时间:2024-11-06 01:53:46

我的收藏

1. 接口描述

接口请求域名: mps.tencentcloudapi.com 。

对视频进行编辑,生成一个新的视频。编辑的功能包括:

一、剪辑任务:简单的视频剪辑,如剪辑、拼接等

  1. 对一个文件进行剪辑,生成一个新的视频;
  2. 对多个文件进行拼接,生成一个新的视频;
  3. 对多个文件进行剪辑,然后再拼接,生成一个新的视频。

二、合成任务:通过接口描述信息,合成一个新的视频。

  1. 多轨道(视频、音频、字幕)、多类型元素(视频、图片、音频、文字、空)
  2. 图像级别:贴图、缩放、任意角度旋转、镜像等
  3. 音频级别:音量控制、淡入淡出、混音等
  4. 视频级别:转场、倍数播放、拼接、剪切、字幕、画中画、音画分离、出入场动效等

默认接口请求频率限制:20次/秒。

推荐使用 API Explorer
点击调试
API Explorer 提供了在线调用、签名验证、SDK 代码生成和快速检索接口等能力。您可查看每次调用的请求内容和返回结果以及自动生成 SDK 调用示例。

2. 输入参数

以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数

参数名称 必选 类型 描述
Action String 公共参数,本接口取值:EditMedia。
Version String 公共参数,本接口取值:2019-06-12。
Region String 公共参数,本接口不需要传递此参数。
FileInfos.N Array of EditMediaFileInfo 输入的视频文件信息。
OutputStorage TaskOutputStorage 媒体处理输出文件的目标存储。
OutputObjectPath String 媒体处理输出文件的目标路径。

注意:对于复杂合成任务,路径中的文件名只可为数字、字母、-、_ 的组合,最长 64 个字符。

示例值:/clip_result/clip_WildAnimal.{format}
OutputConfig EditMediaOutputConfig 【剪辑】任务生成的文件配置。
ComposeConfig ComposeMediaConfig 【合成】任务配置。

注意:当其不为空时,认为是合成任务,否则按剪辑任务处理。
TaskNotifyConfig TaskNotifyConfig 任务的事件通知信息,不填代表不获取事件通知。
TasksPriority Integer 任务优先级,数值越大优先级越高,取值范围是-10到 10,不填代表0。
SessionId String 用于去重的识别码,如果三天内曾有过相同的识别码的请求,则本次的请求会返回错误。最长 50 个字符,不带或者带空字符串表示不做去重。
SessionContext String 来源上下文,用于透传用户请求信息,任务流状态变更回调将返回该字段值,最长 1000 个字符。

3. 输出参数

参数名称 类型 描述
TaskId String 编辑视频的任务 ID,可以通过该 ID 查询编辑任务的状态。
示例值:125xxx88-EditMedia-bffb15f07530b57bc1aabb01fac74bca
RequestId String 唯一请求 ID,由服务端生成,每次请求都会返回(若请求因其他原因未能抵达服务端,则该次请求不会获得 RequestId)。定位问题时需要提供该次请求的 RequestId。

4. 示例

示例1 【剪辑任务】对一个文件进行剪辑,生成一个新的视频

输入示例

https://mps.tencentcloudapi.com/?Action=EditMedia
&FileInfos.0.InputInfo.Type=COS
&FileInfos.0.InputInfo.CosInputInfo.Bucket=TopRankVideo-125xxx88
&FileInfos.0.InputInfo.CosInputInfo.Region=ap-chongqing
&FileInfos.0.InputInfo.CosInputInfo.Object=/movie/201907/WildAnimal.mov
&FileInfos.0.StartTimeOffset=60.0
&FileInfos.0.EndTimeOffset=120.0
&OutputStorage.Type=COS
&OutputStorage.CosOutputStorage.Bucket=TopRankVideo-125xxx88
&OutputStorage.CosOutputStorage.Region=ap-chongqing
&OutputObjectPath=/clip_result/clip_WildAnimal.{format}
&<公共请求参数>

输出示例

{
    "Response": {
        "RequestId": "6ca31e3a-6b8e-4b4e-9256-fdc700064ef3",
        "TaskId": "125xxx88-EditMedia-bffb15f07530b57bc1aabb01fac74bca"
    }
}

示例2 【合成任务】图片&音频合成视频

将一组图片和背景音乐拼接成一个视频,图片之间添加转场效果。轨道形式如下:

效果示例

注:转场会消耗前后元素的轨道时长,如果一个元素前后有转场,则需要保证给元素的轨道时长大于前后两个转场的时间和。

输入示例

POST / HTTP/1.1
Host: mps.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: EditMedia
<公共请求参数>

{
    "FileInfos": [
        {
            "Id": "img01",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../1.jpg"
                }
            }
        },
        {
            "Id": "img02",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../2.jpg"
                }
            }
        },
        {
            "Id": "img03",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../3.jpg"
                }
            }
        },
        {
            "Id": "img04",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../4.jpg"
                }
            }
        },
        {
            "Id": "img05",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../5.jpg"
                }
            }
        },
        {
            "Id": "img06",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../6.jpg"
                }
            }
        },
        {
            "Id": "img07",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../7.jpg"
                }
            }
        },
        {
            "Id": "img08",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../8.jpg"
                }
            }
        },
        {
            "Id": "img09",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../9.jpg"
                }
            }
        },
        {
            "Id": "img10",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../10.jpg"
                }
            }
        },
        {
            "Id": "adu",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../back_music.mp3"
                }
            }
        }
    ],
    "OutputStorage": {
        "Type": "COS",
        "CosOutputStorage": {
            "Bucket": "your_bucket",
            "Region": "your_bucket_region"
        }
    },
    "OutputObjectPath": "/your/output/dir/",
    "ComposeConfig": {
        "TargetInfo": {
            "Container": "mp4",
            "VideoStream": {
                "Fps": 30
            }
        },
        "Tracks": [
            {
                "Type": "Video",
                "Items": [
                    {
                        "Type": "Image",
                        "Image": {
                            "SourceMedia": {
                                "FileId": "img01"
                            },
                            "TrackTime": {
                                "Duration": "3s"
                            }
                        }
                    },
                    {
                        "Type": "Transition",
                        "Transition": {
                            "Transitions": [
                                {
                                    "Type": "Dreamy"
                                }
                            ]
                        }
                    },
                    {
                        "Type": "Image",
                        "Image": {
                            "SourceMedia": {
                                "FileId": "img02"
                            },
                            "TrackTime": {
                                "Duration": "3s"
                            }
                        }
                    },
                    {
                        "Type": "Transition",
                        "Transition": {
                            "Transitions": [
                                {
                                    "Type": "Circleopen"
                                }
                            ]
                        }
                    },
                    {
                        "Type": "Image",
                        "Image": {
                            "SourceMedia": {
                                "FileId": "img03"
                            },
                            "TrackTime": {
                                "Duration": "3s"
                            }
                        }
                    },
                    {
                        "Type": "Transition",
                        "Transition": {
                            "Transitions": [
                                {
                                    "Type": "Heart"
                                }
                            ]
                        }
                    },
                    {
                        "Type": "Image",
                        "Image": {
                            "SourceMedia": {
                                "FileId": "img04"
                            },
                            "TrackTime": {
                                "Duration": "3s"
                            }
                        }
                    },
                    {
                        "Type": "Transition",
                        "Transition": {
                            "Transitions": [
                                {
                                    "Type": "PolarFunction"
                                }
                            ]
                        }
                    },
                    {
                        "Type": "Image",
                        "Image": {
                            "SourceMedia": {
                                "FileId": "img05"
                            },
                            "TrackTime": {
                                "Duration": "3s"
                            }
                        }
                    },
                    {
                        "Type": "Transition",
                        "Transition": {
                            "Transitions": [
                                {
                                    "Type": "Swirl"
                                }
                            ]
                        }
                    },
                    {
                        "Type": "Image",
                        "Image": {
                            "SourceMedia": {
                                "FileId": "img06"
                            },
                            "TrackTime": {
                                "Duration": "3s"
                            }
                        }
                    },
                    {
                        "Type": "Transition",
                        "Transition": {
                            "Transitions": [
                                {
                                    "Type": "WipeRight"
                                }
                            ]
                        }
                    },
                    {
                        "Type": "Image",
                        "Image": {
                            "SourceMedia": {
                                "FileId": "img07"
                            },
                            "TrackTime": {
                                "Duration": "3s"
                            }
                        }
                    },
                    {
                        "Type": "Transition",
                        "Transition": {
                            "Transitions": [
                                {
                                    "Type": "ZoomInCircles"
                                }
                            ]
                        }
                    },
                    {
                        "Type": "Image",
                        "Image": {
                            "SourceMedia": {
                                "FileId": "img08"
                            },
                            "TrackTime": {
                                "Duration": "3s"
                            }
                        }
                    },
                    {
                        "Type": "Transition",
                        "Transition": {
                            "Transitions": [
                                {
                                    "Type": "ImageFadeInFadeOut"
                                }
                            ]
                        }
                    },
                    {
                        "Type": "Image",
                        "Image": {
                            "SourceMedia": {
                                "FileId": "img09"
                            },
                            "TrackTime": {
                                "Duration": "3s"
                            }
                        }
                    },
                    {
                        "Type": "Transition",
                        "Transition": {
                            "Transitions": [
                                {
                                    "Type": "ButterflyWaveScrawler"
                                }
                            ]
                        }
                    },
                    {
                        "Type": "Image",
                        "Image": {
                            "SourceMedia": {
                                "FileId": "img10"
                            },
                            "TrackTime": {
                                "Duration": "3s"
                            }
                        }
                    }
                ]
            },
            {
                "Type": "Audio",
                "Items": [
                    {
                        "Type": "Audio",
                        "Audio": {
                            "SourceMedia": {
                                "FileId": "adu"
                            },
                            "TrackTime": {
                                "Duration": "21s"
                            }
                        }
                    }
                ]
            }
        ]
    }
}

输出示例

{
    "Response": {
        "RequestId": "6ca31e3a-6b8e-4b4e-9256-fdc700064ef3",
        "TaskId": "125xxx88-EditMedia-bffb15f07530b57bc1aabb01fac74bca"
    }
}

示例3 【合成任务】剪辑&片头&片尾&水印图片&文字&音频替换

剪辑一个视频,并给视频添加片头、片尾、水印图片、说明文字、替换音频,合成一个新的视频。轨道形式如下:

效果示例

注:片头和片尾可以是视频,也可以是图片。
注:Canvas 参数用于指定输出视频大小,如果不填将默认使用第一个视频大小,所以建议将正品视频放在素材列表的第一个。

输入示例

POST / HTTP/1.1
Host: mps.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: EditMedia
<公共请求参数>

{
    "FileInfos": [
        {
            "Id": "start",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../start.mp4"
                }
            }
        },
        {
            "Id": "video",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../video.mp4"
                }
            }
        },
        {
            "Id": "end",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../end.png"
                }
            }
        },
        {
            "Id": "img",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../logo.png"
                }
            }
        },
        {
            "Id": "aud",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": ".../back_music.mp3"
                }
            }
        }
    ],
    "OutputStorage": {
        "Type": "COS",
        "CosOutputStorage": {
            "Bucket": "your_bucket",
            "Region": "your_bucket_region"
        }
    },
    "OutputObjectPath": "/your/output/dir/",
    "ComposeConfig": {
        "TargetInfo": {
            "Container": "mp4",
            "VideoStream": {
                "Fps": 30
            }
        },
        "Styles": [
            {
                "Id": "ss",
                "Type": "Subtitle",
                "Subtitle": {
                    "MarginBottom": "50%",
                    "FontType": "SimHei",
                    "FontSize": "8%",
                    "FontBold": 1,
                    "FontColor": "#FF0000FF",
                    "BorderWidth": "2px",
                    "BorderColor": "#00FF00FF",
                    "BottomColor": "#0000FFFF"
                }
            }
        ],
        "Tracks": [
            {
                "Type": "Title",
                "Items": [
                    {
                        "Type": "Subtitle",
                        "Subtitle": {
                            "StyleId": "ss",
                            "TrackTime": {
                                "Start": "0s",
                                "Duration": "2s"
                            },
                            "Text": "片头-示例"
                        }
                    },
                    {
                        "Type": "Subtitle",
                        "Subtitle": {
                            "StyleId": "ss",
                            "TrackTime": {
                                "Start": "2s",
                                "Duration": "8s"
                            },
                            "Text": "正片-示例"
                        }
                    },
                    {
                        "Type": "Subtitle",
                        "Subtitle": {
                            "StyleId": "ss",
                            "TrackTime": {
                                "Start": "12s",
                                "Duration": "2s"
                            },
                            "Text": "片尾-示例"
                        }
                    }
                ]
            },
            {
                "Type": "Video",
                "Items": [
                    {
                        "Type": "Image",
                        "Image": {
                            "SourceMedia": {
                                "FileId": "img"
                            },
                            "TrackTime": {
                                "Duration": "14s"
                            },
                            "XPos": "85%",
                            "YPos": "10%",
                            "Width": "15%"
                        }
                    }
                ]
            },
            {
                "Type": "Video",
                "Items": [
                    {
                        "Type": "Video",
                        "Video": {
                            "SourceMedia": {
                                "FileId": "start"
                            },
                            "AudioOperations": [
                                {
                                    "Type": "Volume",
                                    "Volume": 0.0
                                }
                            ]
                        }
                    },
                    {
                        "Type": "Video",
                        "Video": {
                            "SourceMedia": {
                                "FileId": "video",
                                "StartTime": "10s",
                                "EndTime": "20s"
                            },
                            "AudioOperations": [
                                {
                                    "Type": "Volume",
                                    "Volume": 0.0
                                }
                            ]
                        }
                    },
                    {
                        "Type": "Transition",
                        "Transition": {
                            "Transitions": [
                                {
                                    "Type": "Heart"
                                }
                            ]
                        }
                    },
                    {
                        "Type": "Image",
                        "Image": {
                            "SourceMedia": {
                                "FileId": "end"
                            },
                            "TrackTime": {
                                "Duration": "3s"
                            }
                        }
                    }
                ]
            },
            {
                "Type": "Audio",
                "Items": [
                    {
                        "Type": "Audio",
                        "Audio": {
                            "SourceMedia": {
                                "FileId": "aud"
                            },
                            "TrackTime": {
                                "Duration": "14s"
                            }
                        }
                    }
                ]
            }
        ]
    }
}

输出示例

{
    "Response": {
        "RequestId": "6ca31e3a-6b8e-4b4e-9256-fdc700064ef3",
        "TaskId": "125xxx88-EditMedia-bffb15f07530b57bc1aabb01fac74bca"
    }
}

示例4 【合成任务】画中画

将一个视频缩放,贴在另一个视频上面,合成一个新的视频。轨道形式如下:

效果示例

输入示例

POST / HTTP/1.1
Host: mps.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: EditMedia
<公共请求参数>

{
    "FileInfos": [
        {
            "Id": "back",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../video.mp4"
                }
            }
        },
        {
            "Id": "over",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../over.mp4"
                }
            }
        }
    ],
    "OutputStorage": {
        "Type": "COS",
        "CosOutputStorage": {
            "Bucket": "your_bucket",
            "Region": "your_bucket_region"
        }
    },
    "OutputObjectPath": "/your/output/dir/",
    "ComposeConfig": {
        "Tracks": [
            {
                "Type": "Video",
                "Items": [
                    {
                        "Type": "Video",
                        "Video": {
                            "SourceMedia": {
                                "FileId": "over",
                                "StartTime": "30s",
                                "EndTime": "40s"
                            },
                            "AudioOperations": [
                                {
                                    "Type": "Volume",
                                    "Volume": 0.0
                                }
                            ],
                            "XPos": "60%",
                            "YPos": "30%",
                            "Width": "300px"
                        }
                    }
                ]
            },
            {
                "Type": "Video",
                "Items": [
                    {
                        "Type": "Video",
                        "Video": {
                            "SourceMedia": {
                                "FileId": "back",
                                "StartTime": "10s",
                                "EndTime": "20s"
                            }
                        }
                    }
                ]
            }
        ]
    }
}

输出示例

{
    "Response": {
        "RequestId": "6ca31e3a-6b8e-4b4e-9256-fdc700064ef3",
        "TaskId": "125xxx88-EditMedia-bffb15f07530b57bc1aabb01fac74bca"
    }
}

示例5 【合成任务】视频倍速

剪辑一个视频,前10s 两倍速播放,后10s 0.8倍数播放,合成一个新的视频。轨道形式如下:

效果示例

注:当元素 SourceMedia 里的素材时长和 TrackTime 时长不一致时,就能实现倍数。
注:倍速不能和转场同时使用。

输入示例

POST / HTTP/1.1
Host: mps.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: EditMedia
<公共请求参数>

{
    "FileInfos": [
        {
            "Id": "vod",
            "InputInfo": {
                "Type": "URL",
                "UrlInputInfo": {
                    "Url": "https://.../video.mp4"
                }
            }
        }
    ],
    "OutputStorage": {
        "Type": "COS",
        "CosOutputStorage": {
            "Bucket": "your_bucket",
            "Region": "your_bucket_region"
        }
    },
    "OutputObjectPath": "/your/output/dir/",
    "ComposeConfig": {
        "Tracks": [
            {
                "Type": "Video",
                "Items": [
                    {
                        "Type": "Video",
                        "Video": {
                            "SourceMedia": {
                                "FileId": "vod",
                                "StartTime": "10s",
                                "EndTime": "20s"
                            },
                            "TrackTime": {
                                "Duration": "5s"
                            }
                        }
                    }
                ]
            },
            {
                "Type": "Video",
                "Items": [
                    {
                        "Type": "Video",
                        "Video": {
                            "SourceMedia": {
                                "FileId": "vod",
                                "StartTime": "20s",
                                "EndTime": "30s"
                            },
                            "TrackTime": {
                                "Duration": "12.5s"
                            }
                        }
                    }
                ]
            }
        ]
    }
}

输出示例

{
    "Response": {
        "RequestId": "6ca31e3a-6b8e-4b4e-9256-fdc700064ef3",
        "TaskId": "125xxx88-EditMedia-bffb15f07530b57bc1aabb01fac74bca"
    }
}

5. 开发者资源

腾讯云 API 平台

腾讯云 API 平台 是综合 API 文档、错误码、API Explorer 及 SDK 等资源的统一查询平台,方便您从同一入口查询及使用腾讯云提供的所有 API 服务。

API Inspector

用户可通过 API Inspector 查看控制台每一步操作关联的 API 调用情况,并自动生成各语言版本的 API 代码,也可前往 API Explorer 进行在线调试。

SDK

云 API 3.0 提供了配套的开发工具集(SDK),支持多种编程语言,能更方便的调用 API。

命令行工具

6. 错误码

以下仅列出了接口业务逻辑相关的错误码,其他错误码详见 公共错误码

错误码 描述
FailedOperation.GenerateResource 生成资源失败。
FailedOperation.InvalidMpsUser 操作失败:非法 mps 用户。
InternalError 内部错误。
InvalidParameter 参数错误。