Meidede - Video Slicing
Description
This API slices videos in either GOP (Group of Pictures) mode or frame-index mode and returns the processed video segment.
Version
1.0
Media Requirements
The input media must be provided as a video URL. The original API specification does not state any restrictions on video format, dimensions, file size, or duration.
API URL
Production environment: https://openapi.meitu.com
Task submission endpoint: https://openapi.meitu.com/api/v1/sdk/sync/push
Task name (task): /v1/pvg_video_tc/491344
Task type (task_type): formulaMethod
POST
Content-Type: application/json
Authentication
Request Parameters
| Required | Parameter | Type | Description |
|---|---|---|---|
| Yes | params | string | Algorithm parameters (JSON string) |
| Yes | init_images | object[] | Input video list |
| Yes | task | string | Fixed value: /v1/pvg_video_tc/491344 |
| Yes | task_type | string | Fixed value: formula |
| No | sync_timeout | int | Defaults to 30, in seconds. Frame-index slicing supports asynchronous processing only; set this value to -1 for that mode. |
The structure of each multimedia file in init_images is described below.
| Required | Parameter | Type | Description |
|---|---|---|---|
| Yes | url | string | Video URL or base64-encoded video data |
| Yes | profile | object | Media attributes |
The structure of profile is described below.
| Required | Parameter | Type | Description |
|---|---|---|---|
| Yes | media_profiles | object | Media properties |
| Yes | version | string | Fixed value: v1 |
The structure of media_profiles is described below.
| Required | Parameter | Type | Description |
|---|---|---|---|
| Yes | media_data_type | string | url indicates a URL; use the corresponding video type for base64-encoded data. |
The params inference parameter is a JSON string with the following structure.
| Required | Field | Type | Description |
|---|---|---|---|
| No | rsp_media_type | string | Defaults to url; the original specification does not state any other supported values. |
| Yes | parameter | object | Core video-slicing algorithm parameters |
Details of the algorithm parameters in parameter are provided below.
GOP-based slicing:
| Required | Field | Type | Description |
|---|---|---|---|
| No | repost_url | string | POST callback URL provided by the client |
| Yes | tc_mode | string | Fixed value: gop_slice |
| Yes | start_gop_num | int | Starting GOP number |
| Yes | end_gop_num | int | Ending GOP number |
| No | output_sfs_path | string | If specified, saves the output audio to the designated shared-disk directory; otherwise, uploads it to the default or specified bucket. |
| No | output_sfs_key | string | File key used when saving to SFS; if omitted, the file is uploaded to the default or specified bucket. |
Frame-index slicing and transcoding (asynchronous API only):
| Required | Field | Type | Description |
|---|---|---|---|
| Yes | repost_url | string | POST callback URL provided by the client |
| Yes | start_frame_num | int | Starting frame index, beginning at 1; valid range: [1, max(video frames)] |
| Yes | end_frame_num | int | Ending frame index, beginning at 1; valid range: [1, max(video frames)] |
| Yes | encode_fps | int | Frame rate; defaults to 30. Passing the source video's original frame rate is recommended. |
| Yes | tc_mode | string | segment_abr_0 (average bitrate) or segment_crf_1 (variable bitrate); segment_abr_0 is recommended. |
Request Example
GOP-based slicing:
{
"task": "/v1/pvg_video_tc/491344",
"task_type": "formula",
"init_images": [
{
"url": "https://obs.mtlab.meitu.com/public/EtRGxLI8ulQ43pGhuZfym9aYUD2PUbMP/MTc3OTM2MTIwMA==/34252f68-76bc-4a31-6829-6981765af226.mp4",
"profile": {
"media_profiles": {
"media_data_type": "url"
},
"version": "v1"
}
}
],
"params": "{\"rsp_media_type\":\"url\",\"parameter\":{\"tc_mode\":\"gop_slice\",\"start_gop_num\":1,\"end_gop_num\":2}}",
"sync_timeout": 30
}Frame-index slicing and transcoding:
{
"task": "/v1/pvg_video_tc/491344",
"task_type": "formula",
"init_images": [
{
"url": "https://obs.mtlab.meitu.com/public/EtRGxLI8ulQ43pGhuZfym9aYUD2PUbMP/MTc3OTM2MTIwMA==/34252f68-76bc-4a31-6829-6981765af226.mp4",
"profile": {
"media_profiles": {
"media_data_type": "url"
},
"version": "v1"
}
}
],
"params": "{\"rsp_media_type\":\"url\",\"parameter\":{\"repost_url\":\"https://example.com/video-slice/callback\",\"start_frame_num\":1,\"end_frame_num\":120,\"encode_fps\":30,\"tc_mode\":\"segment_abr_0\"}}",
"sync_timeout": -1
}Response Fields
Generated results are periodically deleted. Download and save them promptly.| Field | Type | Description |
|---|---|---|
| request_id | string | Request identifier |
| trace_id | string | Trace identifier |
| code | int | Business status code; 0 indicates that the request was accepted successfully. |
| error_code | int | Error code; 0 indicates success. |
| message | string | Business message |
| tips | any | Additional information; may be null. |
| data | object | Task status and algorithm result |
Fields in data are described below.
| Field | Type | Description |
|---|---|---|
| status | int | Status code: -1 task not found; 0 created; 1 processing; 2 failed; 9 timed out—use the Query API; 10 succeeded. |
| result | object | Video-slicing algorithm result |
| progress | number | Task progress |
| predict_elapsed | int | Estimated processing time, in milliseconds |
| create_time | int64 | Creation timestamp, in milliseconds |
| task_id | string | Task ID |
| custom_task_id | string | Client-defined task ID |
| trace_id | string | Trace identifier within data |
| client_info | string | Client information |
| init_images | object[]/null | Input media echoed by the service |
Fields in result are described below.
| Field | Type | Description |
|---|---|---|
| id | string | Unique task identifier |
| urls | string[] | List of output media URLs |
| images | string[] | List of output media; equivalent to urls |
| parameters | object | Algorithm parameters and environment information |
| data | object | Detailed data returned by the algorithm |
| msg | string | Result message |
| msg_id | string | Message ID |
| mtlab_res | object | Underlying algorithm result |
| media_info_list | object[] | Output media information list |
Fields in result.data are described below.
| Field | Type | Description |
|---|---|---|
| duration | object | Processing-time statistics for each stage |
| error_code | int | Algorithm error code; 0 indicates success. |
| error_msg | string | Algorithm error message |
| extra | object | Extension fields |
| media_info_list | object[] | Media information list |
| msg_id | string | Message ID |
| parameter | object | Echoed parameters |
Fields in duration are described below.
| Field | Type | Description |
|---|---|---|
| alg_process_time | number | Algorithm processing time, in milliseconds |
| created_timestamp | number | Task creation timestamp, in seconds |
| pull_timestamp | number | Resource retrieval timestamp, in seconds |
| repost_time | number | Retry duration |
| upload_time | number | Upload duration, in milliseconds |
| waiting_time | number | Queue wait time, in milliseconds |
Elements of media_info_list are described below.
| Field | Type | Description |
|---|---|---|
| media_data | string | Media data URL |
| media_extra | object | Additional media information |
| media_profiles | object | Media properties |
Fields in media_profiles returned by GOP-based slicing are described below.
| Field | Type | Description |
|---|---|---|
| media_data_type | string | url indicates that the media data is a URL. |
| start_frame_num | number | Starting frame number |
| end_frame_num | number | Ending frame number |
| ret_frame_num | number | Number of output video frames |
| ret_gop_num | number | Number of output GOPs |
| ret_video_fps | number | Output video frame rate |
| ret_video_width | number | Output video width |
| ret_video_height | number | Output video height |
| ret_video_type | string | Video codec, such as h264 |
| fn_cost_time | number | Slicing duration, in seconds |
| fn_work_dir | string | Slicing working directory |
| ret_file_size | number | Output file size, in bytes |
| rsp_media_url_type | string | Returned media type, such as mp4 |
| upload_2_flag | string | Upload marker; tmp_upload indicates a temporary upload. |
| upload_cost | number | Upload duration, in seconds |
| upload_cost_frame | number | Per-frame upload duration, in seconds |
Fields in parameters and result.data.parameter are described below.
| Field | Type | Description |
|---|---|---|
| app_version | string | Application version |
| container_available_zone | string | Availability zone |
| download_cost | number | Download duration, in milliseconds |
| pvg_version | string | PVG version |
| rsp_media_type | string | Returned media type; url indicates a URL. |
Fields in mtlab_res are described below.
| Field | Type | Description |
|---|---|---|
| ErrorCode | number | Underlying error code |
| ErrorMsg | string | Underlying error message |
| error_code | number | Compatibility field for the error code |
| error_msg | string | Compatibility field for the error message |
| media_info_list | object[]/null | Media information list |
| msg_id | string | Message ID |
| parameter | object/null | Parameter information |
Error codes specific to this API:
| ErrorCode | Error Message | Description |
|---|---|---|
| 20001 | PROCESS_ERROR | Processing error |
Response Examples
Successful Response Example
{
"request_id": "",
"trace_id": "",
"code": 0,
"error_code": 0,
"message": "success",
"tips": null,
"data": {
"status": 10,
"result": {
"id": "t_mt1a3i5n7bb13bac96-0d76-4297-9bcb-c47403840e93",
"urls": [
"https://obs-large.mtlab.meitu.com/mtopen/ff56d688358849259556be0f50065a60/25fa22ba-8c0d-41fe-50a7-a978f38e5cee.mp4"
],
"images": [
"https://obs-large.mtlab.meitu.com/mtopen/ff56d688358849259556be0f50065a60/25fa22ba-8c0d-41fe-50a7-a978f38e5cee.mp4"
],
"parameters": {
"app_version": "1.1.23",
"container_available_zone": "bj-alibjop0",
"download_cost": 217,
"pvg_version": "10.0.0.2.213",
"rsp_media_type": "url"
},
"data": {
"duration": {
"alg_process_time": 281,
"created_timestamp": 1779445581,
"pull_timestamp": 1779445581,
"repost_time": 0,
"upload_time": 125,
"waiting_time": 32
},
"error_code": 0,
"error_msg": "success",
"extra": {},
"media_info_list": [
{
"media_data": "https://obs-large.mtlab.meitu.com/mtopen/ff56d688358849259556be0f50065a60/25fa22ba-8c0d-41fe-50a7-a978f38e5cee.mp4",
"media_extra": {},
"media_profiles": {
"end_frame_num": 2,
"fn_cost_time": 0.28,
"fn_work_dir": "/tmp/slice/f26a132f-daa7-4c6a-4e73-r009ce57aaa4",
"media_data_type": "url",
"ret_file_size": 2419909,
"ret_frame_num": 152,
"ret_gop_num": 1,
"ret_video_fps": 19,
"ret_video_height": 1280,
"ret_video_type": "h264",
"ret_video_width": 720,
"rsp_media_url_type": "mp4",
"start_frame_num": 1,
"upload_2_flag": "tmp_upload",
"upload_cost": 1,
"upload_cost_frame": 0
}
}
],
"msg_id": "f26a132f-daa7-4c6a-4e73-r009ce57aaa4",
"parameter": {
"app_version": "1.1.23",
"container_available_zone": "bj-alibjop0",
"download_cost": 217,
"pvg_version": "10.0.0.2.213",
"rsp_media_type": "url"
}
},
"msg": "success",
"msg_id": "f26a132f-daa7-4c6a-4e73-r009ce57aaa4",
"mtlab_res": {
"ErrorCode": 0,
"ErrorMsg": "",
"error_code": 0,
"error_msg": "",
"media_info_list": null,
"msg_id": "f26a132f-daa7-4c6a-4e73-r009ce57aaa4",
"parameter": null
},
"media_info_list": [
{
"media_data": "https://obs-large.mtlab.meitu.com/mtopen/ff56d688358849259556be0f50065a60/25fa22ba-8c0d-41fe-50a7-a978f38e5cee.mp4",
"media_extra": {},
"media_profiles": {
"end_frame_num": 2,
"fn_cost_time": 0.28,
"fn_work_dir": "/tmp/slice/f26a132f-daa7-4c6a-4e73-r009ce57aaa4",
"media_data_type": "url",
"ret_file_size": 2419909,
"ret_frame_num": 152,
"ret_gop_num": 1,
"ret_video_fps": 19,
"ret_video_height": 1280,
"ret_video_type": "h264",
"ret_video_width": 720,
"rsp_media_url_type": "mp4",
"start_frame_num": 1,
"upload_2_flag": "tmp_upload",
"upload_cost": 1,
"upload_cost_frame": 0
}
}
]
},
"progress": 1,
"predict_elapsed": 10000,
"create_time": 1779445581190,
"task_id": "t_mt1a3i5n7bb13bac96-0d76-4297-9bcb-c47403840e93",
"custom_task_id": "",
"trace_id": "",
"client_info": "",
"init_images": null
}
}Pending Response Example
Use the Query API to retrieve the result.
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": {},
"progress": 0,
"predict_elapsed": 10000,
"create_time": 1779445581190,
"task_id": "t_mt1a3i5n7bb13bac96-0d76-4297-9bcb-c47403840e93",
"custom_task_id": "",
"trace_id": "",
"client_info": "",
"init_images": null
}
}Failed Response Example
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": {
"error_code": 20001,
"error_msg": "PROCESS_ERROR"
},
"progress": 0,
"predict_elapsed": 0,
"create_time": 1779445581190,
"task_id": "t_mt1a3i5n7bb13bac96-0d76-4297-9bcb-c47403840e93",
"custom_task_id": "",
"trace_id": "",
"client_info": "",
"init_images": null
}
}General Error Codes
For details, see API Error Codes.
SDK Examples
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": {
"tc_mode": "gop_slice",
"start_gop_num": 1,
"end_gop_num": 2,
},
}
payload = {
"task": "/v1/pvg_video_tc/491344",
"task_type": "formula",
"init_images": [
{
"url": "https://obs.mtlab.meitu.com/public/EtRGxLI8ulQ43pGhuZfym9aYUD2PUbMP/MTc3OTM2MTIwMA==/34252f68-76bc-4a31-6829-6981765af226.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/pvg_video_tc/491344",
"task_type": "formula",
"init_images": [{
"url": "https://obs.mtlab.meitu.com/public/EtRGxLI8ulQ43pGhuZfym9aYUD2PUbMP/MTc3OTM2MTIwMA==/34252f68-76bc-4a31-6829-6981765af226.mp4",
"profile": {
"media_profiles": {"media_data_type": "url"},
"version": "v1"
}
}],
"params": "{\"rsp_media_type\":\"url\",\"parameter\":{\"tc_mode\":\"gop_slice\",\"start_gop_num\":1,\"end_gop_num\":2}}",
"sync_timeout": 30
}`
req, err := signObj.Sign(url, method, headers, body)
if err != nil {
fmt.Println("Failed to sign request:", err)
return
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println("Failed to send request:", err)
return
}
defer resp.Body.Close()
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Read response failed:", err)
return
}
fmt.Println("Response:", resp.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' => [
'tc_mode' => 'gop_slice',
'start_gop_num' => 1,
'end_gop_num' => 2,
],
]);
$body = json_encode([
'task' => '/v1/pvg_video_tc/491344',
'task_type' => 'formula',
'init_images' => [
[
'url' => 'https://obs.mtlab.meitu.com/public/EtRGxLI8ulQ43pGhuZfym9aYUD2PUbMP/MTc3OTM2MTIwMA==/34252f68-76bc-4a31-6829-6981765af226.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/pvg_video_tc/491344\",\n" +
" \"task_type\": \"formula\",\n" +
" \"init_images\": [{\n" +
" \"url\": \"https://obs.mtlab.meitu.com/public/EtRGxLI8ulQ43pGhuZfym9aYUD2PUbMP/MTc3OTM2MTIwMA==/34252f68-76bc-4a31-6829-6981765af226.mp4\",\n" +
" \"profile\": {\n" +
" \"media_profiles\": {\"media_data_type\": \"url\"},\n" +
" \"version\": \"v1\"\n" +
" }\n" +
" }],\n" +
" \"params\": \"{\\\"rsp_media_type\\\":\\\"url\\\",\\\"parameter\\\":{\\\"tc_mode\\\":\\\"gop_slice\\\",\\\"start_gop_num\\\":1,\\\"end_gop_num\\\":2}}\",\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);
}
}
}