Video Face Swap
Overview
An advanced AI tool for face detection and face swapping in videos. This API allows you to replace faces in videos with source face images.
Process Flow
- Upload your source face image and target video
- Wait for the processing to complete
- Download your transformed video
1. Face Detection API
API Reference
- URL: https://api.maxstudio.ai/detect-face-video
- Method: POST
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
videoUrl | string | yes | URL of the image to detect faces in |
Note: Both source and target images must contain at least one clearly visible human face. Images without detectable faces will result in an error response.
Headers
Name | Type | Required | Description |
---|---|---|---|
x-api-key | string | yes | Your API key obtained from the MaxStudio APIs Dashboard (opens in a new tab). Generate this key by logging into your account and navigating to the API Keys section. |
Response Format
{
"swapId": "<swap_id>",
"detectedFaces": [
"<face_url>"
],
}
Code Examples
// TypeScript implementationinterface FaceDetection { swapId: string; detectedFaces: string[];}async function detectFaces(videoUrl: string): Promise<FaceDetection[]> { try { const response = await fetch('https://api.maxstudio.ai/detect-face-video', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ videoUrl }) }); const jobId = await response.json(); return jobId; } catch (error) { console.error('Error:', error); throw error; }}
2. Face Swap API for Videos
API Reference
- URL: https://api.maxstudio.ai/video-swap
- Method: POST
- Supported formats: MP4, MOV, AVI
Using the Results
After receiving the response, you can:
- Access the transformed video using the
mediaUrl
from the response - Preview the result using the
previewUrl
- View a thumbnail using the
thumbnailUrl
Example Usage
// Using the response
const response = await FaceSwap(sourceImage, targetVideo);
const videoUrl = response.mediaUrl;
const previewUrl = response.previewUrl;
const thumbnailUrl = response.thumbnailUrl;
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
mediaUrl | string | yes | URL of the target video |
faces | array | yes | Array of face swap operations |
swapId | string | yes | Swap ID |
Request Body Example
{
"mediaUrl": "https://example.com/target-video.mp4",
"faces": [
{
"originalFace": "https://example.com/source-face1.jpg",
"newFace": "https://example.com/target-face1.jpg"
}
],
"swapId": "1234567890",
}
Headers
Name | Type | Required | Description |
---|---|---|---|
x-api-key | string | yes | Your API key obtained from the MaxStudio APIs Dashboard (opens in a new tab). Generate this key by logging into your account and navigating to the API Keys section. |
Code Examples
// TypeScript implementationinterface FaceSwapOperation { originalFace: string; newFace: string;}interface VideoFaceSwapParams { mediaUrl: string; faces: FaceSwapOperation[]; swapId: string;}async function videoFaceSwap(params: VideoFaceSwapParams): Promise<any> { try { const response = await fetch('https://api.maxstudio.ai/video-swap', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(params) }); const jobId = await response.json(); return jobId; } catch (error) { console.error('Error:', error); throw error; }}
Important Notes
- Video processing time depends on the video length and quality settings
Success Response
{
"jobId": "<job_id>",
"status": "processing",
"estimatedTime": {
"min": 33, // Minimum estimated time in minutes
"max": 60 // Maximum estimated time in minutes
},
"progress": 0
}
Error Response Examples
// Rate Limit Error
{
"status": 429,
"error": "Rate limit exceeded. Please try again later."
}
// Insufficient Credits
{
"status": 402,
"error": "Insufficient credits. Please Buy credits."
}
// Invalid Input
{
"status": 400,
"error": "Image size must be less than 5MB"
}
Get Job Status
Important Notes
- For Video Face Swap, you need to get the job status in every 5 seconds
Headers
Name | Type | Required | Description |
---|---|---|---|
x-api-key | string | yes | Your API key obtained from the MaxStudio APIs Dashboard (opens in a new tab). Generate this key by logging into your account and navigating to the API Keys section. |
To check the status of your job, use the following examples:
// TypeScript implementationasync function getJobStatus(jobId: string): Promise<any> { const url = `https://api.maxstudio.ai/video-swap/${jobId}`; try { const response = await axios.get(url); const jobId = await response.json(); return jobId; } catch (error) { console.error('Error:', error); throw error; }}
Job Status Reference
Status | Description |
---|---|
creating | Job is being initialized |
pending | Job is in processing queue |
running | Job is actively processing |
completed | Processing finished successfully |
failed | Processing encountered an error |
not-found | Invalid or expired job ID |
Job Status Response
{
"status": "<status>", // One of the status values from the table above
"result": {
"mediaUrl": "<media_url>",
"previewUrl": "<preview_url>",
}
}