Video Face Swap

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

  1. Upload your source face image and target video
  2. Wait for the processing to complete
  3. Download your transformed video

1. Face Detection API

API Reference

  • URL: https://api.maxstudio.ai/detect-face-video
  • Method: POST

Request Parameters

NameTypeRequiredDescription
videoUrlstringyesURL 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

NameTypeRequiredDescription
x-api-keystringyesYour 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 implementation
interface 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:

  1. Access the transformed video using the mediaUrl from the response
  2. Preview the result using the previewUrl
  3. 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

NameTypeRequiredDescription
mediaUrlstringyesURL of the target video
facesarrayyesArray of face swap operations
swapIdstringyesSwap 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

NameTypeRequiredDescription
x-api-keystringyesYour 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 implementation
interface 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

NameTypeRequiredDescription
x-api-keystringyesYour 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 implementation
async 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

StatusDescription
creatingJob is being initialized
pendingJob is in processing queue
runningJob is actively processing
completedProcessing finished successfully
failedProcessing encountered an error
not-foundInvalid 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>",
  }
}