Video Matting

Green-screen-free human video matting: auto-detect the subject in the first frame (or specify it), then cut it out frame by frame, producing a temporally stable WebM/VP9 transparent video with an alpha channel and hair-level soft edges.

Examples

Original
Foreground (checkerboard = transparent)
Background (subject removed)

The checkerboard indicates transparent areas (for visualization only). Foreground and background are complementary and reconstruct the original when stacked. The API actually returns a transparent WebM (VP9 / yuva420p) — overlay it with an alpha-aware tool (CapCut / Premiere / After Effects, or ffmpeg overlay). ⚠️ When re-encoding, keep the alpha (VP9 / yuva420p); converting to AV1 or yuv420p drops the alpha channel.

Usage Limits

  • Input video duration must be within 10 minutes (10 minutes inclusive). Longer videos are rejected by the server with error code 6019 and no task is created. Trim or compress to within 10 minutes before submitting.

Create Task

Basic Information

ItemValue
Request MethodPOST
Request Path/task/video_matting
Content-Typeapplication/json
AuthenticationRaw API key in the Authorization header

Request Body

ParameterTypeRequiredDefaultDescription
file_idstringYes-Uploaded video file ID
target_modestringNoautoFirst-frame subject selection: auto detects the subject; mask uses mask_file_id
mask_file_idstringConditional-First-frame binary mask image file ID (required when target_mode=mask)
output_formatstringNowebmTransparent output container; currently webm (VP9 alpha)
max_sizeintegerNo-Long-edge downscale cap (VRAM/speed); original resolution if omitted
output_backgroundbooleanNofalseAlso output the background video after matting (subject transparent, complementary to the foreground)

Request Example

curl -X POST https://api.ai-mcn.tv:10000/task/video_matting \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"file_id": "537489015178246", "target_mode": "auto"}'

Success Example

{
  "code": 200,
  "msg": "success",
  "data": {
    "task_id": "537489015178247",
    "task_type": "video_matting",
    "status": "queued"
  }
}

Query Task Result

Basic Information

ItemValue
Request MethodGET
Request Path/task/video_matting/{task_id}
AuthenticationRaw API key in the Authorization header

Output Result (output_result)

ParameterTypeDescription
file_idstringTransparent matting video file ID (WebM/VP9 with alpha)
background_file_idstringBackground video file ID (returned when output_background=true; subject transparent, complementary to the foreground)

Success Example

{
  "code": 200,
  "msg": "success",
  "data": {
    "task_id": "537489015178247",
    "status": "completed",
    "progress": 100,
    "output_result": {
      "file_id": "537489015178248"
    }
  }
}

Error Codes

Error CodeHTTP StatusDescriptionResolution
6013400Missing file_id or mask_file_idProvide the required fields
6014400File type does not match the taskUpload a video file
6016400Invalid business params (target_mode / output_format / max_size / output_background)Check the parameter ranges
6019400Video duration exceeds the 10-minute limitTrim / compress to within 10 minutes
6004404File not foundVerify the file_id
6502401Authentication failedCheck the Authorization header