视频-人像美化
描述
本接口用于调用视频人像美化功能,对视频中的人像进行美颜处理,支持磨皮、美白、滤镜、上妆等多种人像美化效果,并返回处理后的视频。
版本
1.0
图片要求
输入为通过 URL 提交的视频。原文示例使用 MP4 视频,成功响应也返回 MP4 视频。原文未说明文件大小、分辨率或视频时长限制。
调用 URL
正式环境:https://openapi.meitu.com
任务提交接口:https://openapi.meitu.com/api/v1/sdk/sync/push
任务名称(task):/v1/video_portrait_beauty/491342
任务类型(task_type):formula调用方法
POST
Content-Type: application/json
权限
请求参数
| 是否必选 | 参数名 | 类型 | 参数说明 |
|---|---|---|---|
| 必选 | params | string | 算法参数(JSON 字符串) |
| 必选 | init_images | object[] | 输入媒体文件列表 |
| 必选 | task | string | 固定 /v1/video_portrait_beauty/491342 |
| 必选 | task_type | string | 固定 formula |
| 可选 | sync_timeout | int | 默认 30,同步超时时间,单位为秒 |
旧版原文参数表与请求示例使用 sync_timeout: -1,表示立即异步返回;本统一网关示例使用规范默认值 30。
init_images 多媒体文件参数,结构说明如下
| 是否必选 | 参数名 | 类型 | 参数说明 |
|---|---|---|---|
| 必选 | url | string | 媒体 URL;原文示例使用 MP4 视频 URL |
| 必选 | profile | object | 媒体属性信息 |
profile 属性信息描述
| 是否必选 | 参数名 | 类型 | 参数说明 |
|---|---|---|---|
| 必选 | media_profiles | object | 媒体属性信息 |
| 必选 | version | string | 固定 v1 |
media_profiles 媒体属性信息
| 是否必选 | 参数名 | 类型 | 参数说明 |
|---|---|---|---|
| 必选 | media_data_type | string | url 表示 url 字段为媒体 URL |
params 推理参数是 JSON 字符串,其结构说明如下
| 是否必选 | 字段 | 类型 | 说明 |
|---|---|---|---|
| 可选 | rsp_media_type | string | 默认 url,控制结果媒体的返回形式 |
| 必选 | parameter | object | 算法核心参数对象 |
parameter 算法参数详情
| 是否必选 | 字段 | 类型 | 说明 |
|---|---|---|---|
| 原文未说明 | formula | object | 美颜配方配置 |
| 原文未说明 | repost_url | string | 回调地址;空字符串表示不回调 |
formula 字段说明
| 是否必选 | 字段 | 类型 | 说明 |
|---|---|---|---|
| 原文未说明 | app_version | string | App 版本号,如 2.10.6 |
| 原文未说明 | client_id | string | 客户端 ID |
| 原文未说明 | effects | object | 美颜效果配置 |
| 原文未说明 | minimum_supported_version | number | 支持的最低版本号 |
| 原文未说明 | platform | string | 平台类型,如 PC、iOS、Android |
| 原文未说明 | sdk_version | string | SDK 版本号 |
| 原文未说明 | version | number | 配方版本号 |
effects 字段说明
| 是否必选 | 字段 | 类型 | 说明 |
|---|---|---|---|
| 原文未说明 | auto_beauty | object | 自动美颜配置 |
auto_beauty 字段说明
| 是否必选 | 字段 | 类型 | 说明 |
|---|---|---|---|
| 原文未说明 | face_alpha | number | 人脸美化强度;-999 表示使用默认值;范围为 0~100 |
| 原文未说明 | filter_alpha | number | 滤镜强度;-999 表示使用默认值;范围为 0~100 |
| 原文未说明 | makeup_alpha | number | 上妆强度;-999 表示使用默认值;范围为 0~100 |
| 原文未说明 | material_id | number | 素材 ID,例如 615000003 表示指定美颜素材 |
| 原文未说明 | skin_alpha | number | 皮肤美化强度;-999 表示使用默认值;范围为 0~100 |
输入值示例
{
"task": "/v1/video_portrait_beauty/491342",
"task_type": "formula",
"init_images": [
{
"url": "https://vmake-neo.stariidata.com/roboneo/convert_save/C1D5EB65_ec03af2d-4ed4-45cd-44fe-4805d81b5bda.mp4?k=57ad4db79319604c95cdafa69e07dfbe&t=6a11ceff",
"profile": {
"media_profiles": {
"media_data_type": "url"
},
"version": "v1"
}
}
],
"params": "{\"rsp_media_type\":\"url\",\"parameter\":{\"formula\":{\"app_version\":\"2.10.6\",\"client_id\":\"1189857533\",\"effects\":{\"auto_beauty\":{\"face_alpha\":-999,\"filter_alpha\":-999,\"makeup_alpha\":-999,\"material_id\":615000003,\"skin_alpha\":-999}},\"minimum_supported_version\":247,\"platform\":\"PC\",\"sdk_version\":\"\",\"version\":247},\"repost_url\":\"\"}}",
"sync_timeout": 30
}返回值说明
注意,生成的结果,会定期清理,请及时下载保存| 字段 | 类型 | 说明 |
|---|---|---|
| request_id | string | 请求标识 |
| trace_id | string | 链路追踪标识 |
| code | int | 业务状态码,0 表示请求受理成功 |
| error_code | int | 错误码,成功时为 0 |
| message | string | 业务信息 |
| tips | any | 补充提示,可为 null |
| data | object | 任务状态和算法结果 |
data 中单个元素的字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| status | int | 状态码:-1 未找到任务;0 创建成功;1 执行中;2 失败;9 超时,需使用查询接口查询;10 成功 |
| result | object | 算法结果 |
| progress | number | 任务进度,范围为 0~1,1 表示完成 |
| predict_elapsed | int | 预计耗时,毫秒 |
| create_time | int64 | 创建时间戳,毫秒 |
| task_id | string | 任务 ID |
| custom_task_id | string | 客户自定义任务 ID |
| trace_id | string | data 内链路追踪标识 |
| client_info | string | 客户端信息 |
| init_images | object[]/null | 输入媒体回显 |
result 中单个元素的字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| id | string | 任务唯一标识 |
| urls | array | 输出媒体 URL 列表 |
| images | array | 输出媒体列表;原文响应中与 urls 含义一致 |
| parameters | object | 算法参数信息 |
| data | object | 算法返回的详细数据 |
| msg | string | 返回信息 |
| msg_id | string | 消息 ID |
| mtlab_res | object | 算法底层返回结果 |
| media_info_list | array | 输出媒体信息列表 |
result.data 字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| duration | object | 各阶段耗时和时间戳统计 |
| error_code | number | 算法错误码,0 表示成功 |
| error_msg | string | 算法错误信息 |
| media_info_list | array | 媒体信息列表 |
| msg_id | string | 消息 ID |
| parameter | object | 参数回显 |
duration 字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| alg_process_time | number | 算法处理耗时,毫秒 |
| created_timestamp | number | 任务创建时间戳,秒 |
| pull_timestamp | number | 拉取资源时间戳,秒 |
| repost_time | number | 重试耗时 |
| upload_time | number | 上传耗时,毫秒 |
| waiting_time | number | 排队等待耗时,毫秒 |
media_info_list 媒体信息说明
| 字段 | 类型 | 说明 |
|---|---|---|
| media_data | string | 媒体数据地址 |
| media_extra | object | 媒体扩展信息 |
| media_profiles | object | 媒体属性信息 |
media_profiles 字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| media_data_type | string | 媒体数据类型,如 MP4、url |
parameter / parameters 字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| version | string | 版本号 |
mtlab_res 字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| ErrorCode | number | 底层错误码 |
| ErrorMsg | string | 底层错误信息 |
| error_code | number | 错误码兼容字段 |
| error_msg | string | 错误信息兼容字段 |
| media_info_list | array/null | 媒体信息列表 |
| msg_id | string | 消息 ID |
| parameter | object/null | 参数信息 |
当前 API 特有的错误代码与信息
| ErrorCode | 错误信息 | 说明 |
|---|---|---|
| 20001 | PROCESS_ERROR | 处理错误 |
返回值示例
请求成功返回示例
{
"request_id": "",
"trace_id": "",
"code": 0,
"error_code": 0,
"message": "success",
"tips": null,
"data": {
"status": 10,
"result": {
"id": "t_mt1a3i5n7bf6b1d56d-20b2-4c44-a586-b05c82f69d4c",
"urls": [
"https://obs-large.mtlab.meitu.com/mtopen/ff56d688358849259556be0f50065a60/0518d384-063e-47ec-68b8-245f53d90ae3.mp4"
],
"parameters": {"version": "1.0.0"},
"data": {
"duration": {
"alg_process_time": 50000,
"created_timestamp": 1779441396,
"pull_timestamp": 1779441396,
"repost_time": 0,
"upload_time": 0,
"waiting_time": 0
},
"error_code": 0,
"error_msg": "success",
"media_info_list": [
{
"media_data": "https://obs-large.mtlab.meitu.com/mtopen/ff56d688358849259556be0f50065a60/0518d384-063e-47ec-68b8-245f53d90ae3.mp4",
"media_extra": {},
"media_profiles": {"media_data_type": "MP4"}
}
],
"msg_id": "146696ed-ea26-4cdc-964f-242e468c3cb8",
"parameter": {"version": "1.0.0"}
},
"msg": "success",
"msg_id": "146696ed-ea26-4cdc-964f-242e468c3cb8",
"images": [
"https://obs-large.mtlab.meitu.com/mtopen/ff56d688358849259556be0f50065a60/0518d384-063e-47ec-68b8-245f53d90ae3.mp4"
],
"mtlab_res": {
"ErrorCode": 0,
"ErrorMsg": "",
"error_code": 0,
"error_msg": "",
"media_info_list": null,
"msg_id": "146696ed-ea26-4cdc-964f-242e468c3cb8",
"parameter": null
},
"media_info_list": [
{
"media_data": "https://obs-large.mtlab.meitu.com/mtopen/ff56d688358849259556be0f50065a60/0518d384-063e-47ec-68b8-245f53d90ae3.mp4",
"media_extra": {},
"media_profiles": {"media_data_type": "MP4"}
}
]
},
"progress": 1,
"predict_elapsed": 10000,
"create_time": 1779441395925,
"task_id": "t_mt1a3i5n7bf6b1d56d-20b2-4c44-a586-b05c82f69d4c",
"custom_task_id": "",
"trace_id": "",
"client_info": "",
"init_images": null
}
}需要查询返回示例
使用查询接口查询任务结果。
Response Status:200
content-type 为 application/json; charset=utf-8
{
"request_id": "",
"trace_id": "",
"code": 0,
"error_code": 0,
"message": "success",
"tips": null,
"data": {
"status": 9,
"result": {
"id": "t_mt1a3i5n7bf6b1d56d-20b2-4c44-a586-b05c82f69d4c"
},
"progress": 0,
"predict_elapsed": 10000,
"create_time": 1779441395925,
"task_id": "t_mt1a3i5n7bf6b1d56d-20b2-4c44-a586-b05c82f69d4c",
"custom_task_id": "",
"trace_id": "",
"client_info": "",
"init_images": null
}
}请求失败返回示例
Response Status:400
content-type 为 application/json; charset=utf-8
{
"request_id": "",
"trace_id": "",
"code": 20001,
"error_code": 20001,
"message": "PROCESS_ERROR",
"tips": null,
"data": {
"status": 2,
"result": {
"id": "",
"data": {
"error_code": 20001,
"error_msg": "PROCESS_ERROR"
},
"msg": "PROCESS_ERROR",
"msg_id": ""
},
"progress": 0,
"predict_elapsed": 0,
"create_time": 0,
"task_id": "",
"custom_task_id": "",
"trace_id": "",
"client_info": "",
"init_images": null
}
}通用的错误代码与信息
详见 API 错误码
SDK 调用示例
Python
import json
import requests
from sign_sdk import sign
def api_call_example():
key = "your_api_key"
secret = "your_api_secret"
url = "https://openapi.meitu.com/api/v1/sdk/sync/push"
method = "POST"
headers = {"Content-Type": "application/json", sign.HeaderHost: "openapi.meitu.com"}
inner_params = {
"rsp_media_type": "url",
"parameter": {
"formula": {
"app_version": "2.10.6",
"client_id": "1189857533",
"effects": {"auto_beauty": {
"face_alpha": -999,
"filter_alpha": -999,
"makeup_alpha": -999,
"material_id": 615000003,
"skin_alpha": -999,
}},
"minimum_supported_version": 247,
"platform": "PC",
"sdk_version": "",
"version": 247,
},
"repost_url": "",
},
}
payload = {
"task": "/v1/video_portrait_beauty/491342",
"task_type": "formula",
"init_images": [{
"url": "https://example.com/input.mp4",
"profile": {
"media_profiles": {"media_data_type": "url"},
"version": "v1",
},
}],
"params": json.dumps(inner_params, ensure_ascii=False),
"sync_timeout": 30,
}
body = json.dumps(payload, ensure_ascii=False)
signer = sign.Signer(key, secret)
signed_request = signer.sign(url, method, headers, body)
response = requests.Session().send(signed_request)
print(f"Status: {response.status_code}")
print(f"Response: {response.text}")
if __name__ == "__main__":
api_call_example()Go
package main
import (
"fmt"
"io"
"net/http"
"github.com/mtlab/api/signer"
)
func main() {
key := "your_api_key"
secret := "your_api_secret"
signObj := signer.NewSigner(key, secret)
url := "https://openapi.meitu.com/api/v1/sdk/sync/push"
method := http.MethodPost
headers := make(http.Header)
headers.Set(signer.HeaderHost, "openapi.meitu.com")
headers.Set("Content-Type", "application/json")
body := `{
"task": "/v1/video_portrait_beauty/491342",
"task_type": "formula",
"init_images": [{
"url": "https://example.com/input.mp4",
"profile": {
"media_profiles": {"media_data_type": "url"},
"version": "v1"
}
}],
"params": "{\"rsp_media_type\":\"url\",\"parameter\":{\"formula\":{\"app_version\":\"2.10.6\",\"client_id\":\"1189857533\",\"effects\":{\"auto_beauty\":{\"face_alpha\":-999,\"filter_alpha\":-999,\"makeup_alpha\":-999,\"material_id\":615000003,\"skin_alpha\":-999}},\"minimum_supported_version\":247,\"platform\":\"PC\",\"sdk_version\":\"\",\"version\":247},\"repost_url\":\"\"}}",
"sync_timeout": 30
}`
request, err := signObj.Sign(url, method, headers, body)
if err != nil {
fmt.Println("Failed to sign request:", err)
return
}
response, err := http.DefaultClient.Do(request)
if err != nil {
fmt.Println("Failed to send request:", err)
return
}
defer response.Body.Close()
responseBody, err := io.ReadAll(response.Body)
if err != nil {
fmt.Println("Read response failed:", err)
return
}
fmt.Println("Response:", response.StatusCode, string(responseBody))
}PHP
<?php
require 'signer.php';
$key = 'your_api_key';
$secret = 'your_api_secret';
$signer = new Signer($key, $secret);
$url = 'https://openapi.meitu.com/api/v1/sdk/sync/push';
$method = 'POST';
$headers = ['Content-Type' => 'application/json'];
$innerParams = json_encode([
'rsp_media_type' => 'url',
'parameter' => [
'formula' => [
'app_version' => '2.10.6',
'client_id' => '1189857533',
'effects' => ['auto_beauty' => [
'face_alpha' => -999,
'filter_alpha' => -999,
'makeup_alpha' => -999,
'material_id' => 615000003,
'skin_alpha' => -999,
]],
'minimum_supported_version' => 247,
'platform' => 'PC',
'sdk_version' => '',
'version' => 247,
],
'repost_url' => '',
],
]);
$body = json_encode([
'task' => '/v1/video_portrait_beauty/491342',
'task_type' => 'formula',
'init_images' => [[
'url' => 'https://example.com/input.mp4',
'profile' => [
'media_profiles' => ['media_data_type' => 'url'],
'version' => 'v1',
],
]],
'params' => $innerParams,
'sync_timeout' => 30,
]);
$curl = $signer->sign($url, $method, $headers, $body);
$response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status === 0) {
echo 'Error: ' . curl_error($curl);
} else {
echo "Status: {$status}\n";
echo "Response: {$response}\n";
}
curl_close($curl);
?>Java
package com.meitu.openai.common;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) throws Exception {
Signer signer = new Signer("your_api_key", "your_api_secret");
String url = "https://openapi.meitu.com/api/v1/sdk/sync/push";
String method = "POST";
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put(Signer.HeaderHost, "openapi.meitu.com");
String body = "{\n" +
" \"task\": \"/v1/video_portrait_beauty/491342\",\n" +
" \"task_type\": \"formula\",\n" +
" \"init_images\": [{\n" +
" \"url\": \"https://example.com/input.mp4\",\n" +
" \"profile\": {\n" +
" \"media_profiles\": {\"media_data_type\": \"url\"},\n" +
" \"version\": \"v1\"\n" +
" }\n" +
" }],\n" +
" \"params\": \"{\\\"rsp_media_type\\\":\\\"url\\\",\\\"parameter\\\":{\\\"formula\\\":{\\\"app_version\\\":\\\"2.10.6\\\",\\\"client_id\\\":\\\"1189857533\\\",\\\"effects\\\":{\\\"auto_beauty\\\":{\\\"face_alpha\\\":-999,\\\"filter_alpha\\\":-999,\\\"makeup_alpha\\\":-999,\\\"material_id\\\":615000003,\\\"skin_alpha\\\":-999}},\\\"minimum_supported_version\\\":247,\\\"platform\\\":\\\"PC\\\",\\\"sdk_version\\\":\\\"\\\",\\\"version\\\":247},\\\"repost_url\\\":\\\"\\\"}}\",\n" +
" \"sync_timeout\": 30\n" +
"}";
Map<String, String> signedHeaders = signer.sign(url, method, headers, body);
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod(method);
for (Map.Entry<String, String> entry : signedHeaders.entrySet()) {
connection.setRequestProperty(entry.getKey(), entry.getValue());
}
connection.setDoOutput(true);
connection.getOutputStream().write(body.getBytes(StandardCharsets.UTF_8));
int status = connection.getResponseCode();
InputStream stream = status >= 400 ? connection.getErrorStream() : connection.getInputStream();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
System.out.println("Response: " + status + " " + response);
}
}
}