API For Face Swap Video
June 18, 2024About 2 min
API For Face Swap Video
AI Face Swap Video
The AI Face Swap API offers powerful functionality to intelligently detect faces within photos and seamlessly replace them with other faces of your choice. This advanced technology empowers users with unparalleled creative freedom, allowing effortless face swapping across a diverse range of photos.
Credits Consumption
Calculate based on the duration of the video, consuming credits per second. If face_enhance function is turned on,
Standard response
If the request is successful, the API will return OK (HTTP status code 200) and a JSON object, otherwise, it will return an HTTP status code that indicates the error and a JSON object that contains the error details.
Parameter | Description |
---|---|
code | The business code, 100000 indicates success, 300102 indicates progressing otherwise indicates error. In most cases, the error code will be equal to the HTTP status code (e.g. 400, 401, 404, 500, etc). Or else, it will be a custom error code defined by the API.. |
message | Description of the returned information |
result | The response data object only available when the request is successful . The data object will be different for each API. |
Considerations
- Before using the API, make sure you have obtained the API key. Refer to the link below for instructions on how to obtain it. API For API Key Settings
- All generated images will be automatically deleted after 24 hours. Please make sure to save the images you need to your local storage in a timely manner.
Header Attributes
Parameter | Description |
---|---|
Authorization | Your API Key used for request authorization. |
Create Job
Request Url
--request POST https://developer.remaker.ai/api/remaker/v1/face-swap-video/create-job
Body Attributes
Parameter | Type | Required | Description |
---|---|---|---|
swap_image | file[binary] | true | pictures with faces |
target_video_url | string | true | An accessible video URL. The video should be less than thirty minutes in length and smaller than 500MB. |
face_enhance | bool | false | (6credits/s)The face enhancement option will return a clearer face when turned on. |
Demo
::: tabs#face-swap-video
@tab python
import requests
url = "https://developer.remaker.ai/api/remaker/v1/face-swap-video/create-job"
payload = {'target_video_url': 'https://pai-data-5f568.oss-us-west-1.aliyuncs.com/test/mda-pi8ndtq6h3gkkic7.mp4'}
files=[
('swap_image',('images.jpg',open('/C:/Users/xxxxx/Desktop/tmp/images.jpg','rb'),'image/jpeg'))
]
headers = {
'Authorization': 'xxxxx your api key'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
@tab:active php
<?php
$curl = curl_init();
$postData = array(
'target_video_url' => 'https://xxxxx.com/test/mda-pi8ndtq6h3gkkic7.mp4',
'swap_image'=> new CURLFILE('/home/xxxxx/1111.png')
);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://developer.remaker.ai/api/remaker/v1/face-swap-video/create-job',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $postData,
CURLOPT_HTTPHEADER => array(
'Authorization: xxxxx your api key'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
:::
Response
{
"code": 100000,
"result": {
"job_id": "ac191c1c-6afd-427e-af1f-7fc2113ce80a"
},
"message": {
"en": "Request Success."
}
}
Fetch Job
Request Url
--request GET https://developer.remaker.ai/api/remaker/v1/face-swap-video/{job_id}
Body Attributes
Parameter | Description |
---|---|
job_id | job_id returned by create task |
::: tabs#face-swap-video
@tab:active python
import requests
url = "https://developer.remaker.ai/api/remaker/v1/face-swap-video/{your jon id}"
payload = {}
headers = {
'Authorization': 'xxxxx your api key'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
@tab php
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://developer.remaker.ai/api/remaker/v1/face-swap-video/{your api key}',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: xxxxx your api key'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
:::
Response
progress
{
"code": 300102,
"result": {
"user_credits": 6201,
"user_freeze_credits": 50,
"need_credits": 50,
"input": {
"video_urls": "https://pai-data-5f568.oss-us-west-1.aliyuncs.com/test/mda-pi8ndtq6h3gkkic7.mp4",
"mask_url": "https://image.remaker.ai/datarm30/api/face-video/input/2024-04-22/381d6dd4-4c41-449c-8bae-9aa8bd945914_mask_.png"
},
"output": [],
"thumbnail_path": "",
"progress": 7
},
"message": {
"en": "Image generation in progress."
}
}
Success
{
"code": 100000,
"result": {
"user_credits": 6201,
"user_freeze_credits": 0,
"need_credits": 0,
"input": {},
"output": [
"https://image.remaker.ai/datarm30/face-video/generate/2024-04-22/swapped-tmprvudor85mda-pi8ndtq6h3gkkic7.mp4"
],
"thumbnail_path": "https://image.remaker.ai/datarm30/face-video/output/2024-04-22/96b2740c-56e6-4443-806b-477918d5851f.png",
"progress": 100
},
"message": {
"en": "Request Success."
}
}