namifusion 画像/動画 フェイススワップ

namifusion/faceswap-video

NamiFusion ビデオ フェイススワップ モデル 1人または複数人の簡単換顔が可能。複数のmodel_styleスタイルに対応、リアルな結果かワンクリック美顔処理のどちらかを直接出力、自然で綺麗な仕上がり!

サンプル

namifusion 画像/動画 フェイススワップ example 1

パラメータ

名前既定制約説明
source_url *ソースフェイスimage_upload0–1 items入力面
single_face_mode片面スワップboolean一人の顔の交換に基づくタスクの実行
model_styleモデルスタイルselectrealisticrealistic | beautify | lossless換顔スタイル。Realistic:自然な肌色と質感。Beautify:美顔補正で滑らかに。Lossless:元の顔の細部を完全保持し最高の忠実度。
face_enhance顔の強調boolean顔の強調を有効にします。有効にすると、顔の解像度が高くなります。
face_mapping顔マッピングarray<object>[]複数人物の顔交換に必須のパラメータ。各要素はソース顔とターゲット顔のマッピングです。顔検出APIで顔情報を取得し、この配列に組み立てます。`source_face_info.face_url`は新しい顔、`target_face_info.face_url`は置き換え対象の顔です。
source_face_index顔インデックスを入力してくださいnumber≥ 0
target_face_index対象面のインデックスnumber≥ 0
source_face_infoソースの顔情報object
target_face_infoターゲットの顔情報object

出力フィールド

フィールド説明
videosarray<string>Face swap result video URLs

API

統一 REST API でこのモデルを呼び出せます。API Keys ページでキーを取得してください。

cURL
# 1) Submit — returns { "task_uuid": "..." }
curl -X POST "https://www.namifusion.com/api/v1/marketplace/run/namifusion/faceswap-video" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "input": {
    "source_url": [
      "https://assets-public.namifusion.com/marketplace/thumbnails/2026-01-27/d0328839a75f.png"
    ],
    "single_face_mode": true,
    "model_style": "realistic",
    "face_enhance": false,
    "face_mapping": []
  }
}'

# 2) Poll until status is "completed", then read the output URLs
curl "https://www.namifusion.com/api/v1/marketplace/run/tasks/TASK_UUID" \
  -H "Authorization: Bearer YOUR_API_KEY"
Python
import time, requests

API_KEY = "YOUR_API_KEY"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}

# 1) Submit
resp = requests.post(
    "https://www.namifusion.com/api/v1/marketplace/run/namifusion/faceswap-video",
    headers=HEADERS,
    json={
        "input": {
            "source_url": [
                "https://assets-public.namifusion.com/marketplace/thumbnails/2026-01-27/d0328839a75f.png"
            ],
            "single_face_mode": True,
            "model_style": "realistic",
            "face_enhance": False,
            "face_mapping": []
        }
    },
)
resp.raise_for_status()  # 401/402/429/5xx stop here instead of polling a bad task
task = resp.json()

# 2) Poll until a terminal state (completed / failed / cancelled).
#    This model is allowed up to 1800s server-side.
deadline = time.time() + 1860
while task.get("status") not in ("completed", "failed", "cancelled"):
    if time.time() > deadline:
        raise TimeoutError(f"still {task.get('status')} — keep the task_uuid and poll later")
    time.sleep(3)
    poll = requests.get(f"https://www.namifusion.com/api/v1/marketplace/run/tasks/{task['task_uuid']}", headers=HEADERS)
    poll.raise_for_status()
    task = poll.json()

print(task["status"], task.get("output"))
JavaScript
const API_KEY = "YOUR_API_KEY";
const HEADERS = { Authorization: `Bearer ${API_KEY}` };

// 1) Submit
const resp = await fetch("https://www.namifusion.com/api/v1/marketplace/run/namifusion/faceswap-video", {
  method: "POST",
  headers: { ...HEADERS, "Content-Type": "application/json" },
  body: JSON.stringify({
    "input": {
      "source_url": [
        "https://assets-public.namifusion.com/marketplace/thumbnails/2026-01-27/d0328839a75f.png"
      ],
      "single_face_mode": true,
      "model_style": "realistic",
      "face_enhance": false,
      "face_mapping": []
    }
  }),
});
if (!resp.ok) throw new Error(`submit failed: ${resp.status} ${await resp.text()}`);
let task = await resp.json();

// 2) Poll until a terminal state (completed / failed / cancelled).
//    This model is allowed up to 1800s server-side.
const deadline = Date.now() + 1860 * 1000;
while (!["completed", "failed", "cancelled"].includes(task.status)) {
  if (Date.now() > deadline) throw new Error(`still ${task.status} — keep the task_uuid and poll later`);
  await new Promise((r) => setTimeout(r, 3000));
  const poll = await fetch(`https://www.namifusion.com/api/v1/marketplace/run/tasks/${task.task_uuid}`, { headers: HEADERS });
  if (!poll.ok) throw new Error(`poll failed: ${poll.status}`);
  task = await poll.json();
}

console.log(task.status, task.output);

ドキュメント

NamiFusion Video FaceSwap

AI動画フェイススワップ:単一人物の自動フェイススワップと複数人物の精密マッピングに対応し、顔検出と組み合わせて完全な動画フェイススワップワークフローを実現。

NamiFusion Video FaceSwapは、高品質なAI動画フェイススワップサービスで、ソース顔をターゲット動画に置き換えることができます。単一人物フェイススワップ(自動モード)と複数人物フェイススワップ(精密マッピングモード)の2つのモードを提供し、NamiFusion Detect Facesと組み合わせることで、顔検出からフェイススワップまでの完全なワークフローを実現できます。


主な機能

  • 単一人物フェイススワップ: single_face_modeを有効にするだけで、追加設定なしに自動的にフェイススワップが完了します。
  • 複数人物精密マッピング: face_mappingを使用して、ソース顔とターゲット顔の対応関係を正確に指定でき、1対1および多対多のマッピングに対応しています。
  • 顔補正: オプションの高度な美顔機能で、自動的に肌を滑らかにし、顔の欠点を除去して、スワップ後の顔品質を向上させます。
  • 非同期タスク: 送信後にtask_uuidを返し、ポーリングまたはWebhookで結果を取得します。

技術仕様

パラメータ詳細
モデルIDnamifusion/faceswap-video
リクエスト方式非同期POST(タスク送信 + ポーリング/Webhookで結果取得)
入力ソース顔画像URL + ターゲット動画URL
出力フェイススワップ後の動画URL
処理時間通常30秒〜数分(動画の長さと解像度に依存)

クイックスタート

APIエンドポイント

エンドポイントメソッド説明
/api/v1/marketplace/run/namifusion/faceswap-videoPOST動画フェイススワップタスクを送信
/api/v1/marketplace/run/tasks/{task_uuid}GETタスクのステータスと結果を照会

認証

リクエストヘッダーにAPIキーを含めてください:

X-API-Key: sk-your-api-key

シナリオ1:単一人物フェイススワップ(最もシンプルな使い方)

ソース画像とターゲット動画の両方に顔が1つだけ含まれているシナリオに適しています。single_face_modeを有効にすると、face_mappingの設定は不要で、サービスが自動的にフェイススワップを完了します。

ステップ1:フェイススワップタスクを送信

curl -X POST "https://www.namifusion.com/api/v1/marketplace/run/namifusion/faceswap-video" \
  -H "X-API-Key: sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "input": {
      "source_url": "https://example.com/source_face.jpg",
      "target_url": "https://example.com/target_video.mp4",
      "single_face_mode": true
    }
  }'

レスポンス例:

{
  "task_uuid": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "pending",
  "cost_credits": 50
}

ステップ2:タスクステータスをポーリング

curl -X GET "https://www.namifusion.com/api/v1/marketplace/run/tasks/a1b2c3d4-e5f6-7890-abcd-ef1234567890" \
  -H "X-API-Key: sk-your-api-key"

処理中:

{
  "task_uuid": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "processing"
}

完了:

{
  "task_uuid": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "model_id": "namifusion/faceswap-video",
  "status": "completed",
  "output": {
    "videos": ["https://cdn.namifusion.com/result/faceswap_abc123.mp4"]
  },
  "cost_credits": 50,
  "created_at": "2026-02-27T10:00:00Z",
  "completed_at": "2026-02-27T10:01:30Z"
}

シナリオ2:複数人物フェイススワップ

ターゲット動画に複数の顔があり、「どのソース顔でどのターゲット顔を置き換えるか」を正確に制御する必要がある場合、まずDetect Facesを呼び出して動画から顔を検出し、次にface_mappingを構築してフェイススワップタスクを送信する必要があります。

ステップ1:ターゲット動画の顔を検出

NamiFusion Detect Faces(POST /api/v1/marketplace/run/namifusion/detect_faces)を呼び出して動画から直接顔検出を行い、ポーリングで結果を取得します。

検出タスクを送信:

curl -X POST "https://www.namifusion.com/api/v1/marketplace/run/namifusion/detect_faces" \
  -H "X-API-Key: sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "input": {
      "url": "https://example.com/target_video.mp4",
      "num_frames": 3,
      "return_face_url": true,
      "deduplicate": true
    }
  }'

タスク結果をポーリング:

curl -X GET "https://www.namifusion.com/api/v1/marketplace/run/tasks/{task_uuid}" \
  -H "X-API-Key: sk-your-api-key"

完了レスポンス(2人の人物が検出された場合):

{
  "task_uuid": "...",
  "status": "completed",
  "output": {
    "error_code": 0,
    "error_msg": "SUCCESS",
    "faces_obj": {
      "0": {
        "region": [[50, 80, 150, 200], [250, 70, 350, 190]],
        "face_urls": [
          "https://s3.amazonaws.com/faces/target_face_0.jpg",
          "https://s3.amazonaws.com/faces/target_face_1.jpg"
        ],
        "landmarks": [[[...]], [[...]]],
        "frame_time": null,
        "crop_region": [[...], [...]],
        "landmarks_str": ["...", "..."],
        "crop_landmarks": ["...", "..."]
      },
      "1": {
        "region": [],
        "face_urls": [],
        "landmarks": [],
        "frame_time": 1.0,
        "crop_region": [],
        "landmarks_str": [],
        "crop_landmarks": []
      },
      "2": {
        "region": [],
        "face_urls": [],
        "landmarks": [],
        "frame_time": 2.0,
        "crop_region": [],
        "landmarks_str": [],
        "crop_landmarks": []
      }
    }
  }
}

これでターゲット動画に2人の人物がいること(faces_obj["0"].regionの長さが2)と、それぞれのface_urlsがわかりました。

ステップ2:ソース顔画像を検出

同様にDetect Facesを呼び出して検出タスクを送信し、ポーリングで結果を取得します(複数のソース顔画像がある場合、または正確な顔座標情報を渡す必要がある場合)。

検出タスクを送信:

curl -X POST "https://www.namifusion.com/api/v1/marketplace/run/namifusion/detect_faces" \
  -H "X-API-Key: sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "input": {
      "url": "https://example.com/source_face.jpg",
      "return_face_url": true
    }
  }'

完了レスポンス:

{
  "task_uuid": "...",
  "status": "completed",
  "output": {
    "error_code": 0,
    "error_msg": "SUCCESS",
    "faces_obj": {
      "0": {
        "region": [[100, 50, 200, 180]],
        "face_urls": ["https://s3.amazonaws.com/faces/source_face_0.jpg"],
        "landmarks": [[[...]]],
        "frame_time": null,
        "crop_region": [[...]],
        "landmarks_str": ["..."],
        "crop_landmarks": ["..."]
      }
    }
  }
}

ステップ3:face_mappingを構築

検出結果に基づいて、ソース顔からターゲット顔へのマッピング関係を構築します。

Detect Facesが返したface_urlsface_mappingsource_face_info.face_urltarget_face_info.face_urlに設定します:

"face_mapping": [
  {
    "source_face_info": {
      "face_url": "https://s3.amazonaws.com/faces/source_face_0.jpg"
    },
    "target_face_info": {
      "face_url": "https://s3.amazonaws.com/faces/target_face_0.jpg"
    }
  }
]

face_urlの値は、ステップ1と2でDetect Facesが返したoutput.faces_obj["0"].face_urls[i]の値をそのまま使用します。

face_mappingsource_face_indextarget_face_indexbboxなどのパラメータもサポートしています。詳細は後述の「face_mapping詳細」セクションを参照してください。

ステップ4:複数人物フェイススワップタスクを送信

curl -X POST "https://www.namifusion.com/api/v1/marketplace/run/namifusion/faceswap-video" \
  -H "X-API-Key: sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "input": {
      "source_url": "https://example.com/source_face.jpg",
      "target_url": "https://example.com/target_video.mp4",
      "single_face_mode": false,
      "face_mapping": [
        {
          "source_face_info": {
            "face_url": "https://s3.amazonaws.com/faces/source_face_0.jpg"
          },
          "target_face_info": {
            "face_url": "https://s3.amazonaws.com/faces/target_face_0.jpg"
          }
        }
      ]
    }
  }'

レスポンス:

{
  "task_uuid": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
  "status": "pending",
  "cost_credits": 50
}

ステップ5:フェイススワップ結果を取得

statuscompletedになるまでタスクステータスをポーリングします:

curl -X GET "https://www.namifusion.com/api/v1/marketplace/run/tasks/b2c3d4e5-f6a7-8901-bcde-f12345678901" \
  -H "X-API-Key: sk-your-api-key"

完了レスポンス:

{
  "task_uuid": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
  "model_id": "namifusion/faceswap-video",
  "status": "completed",
  "output": {
    "videos": ["https://cdn.namifusion.com/result/faceswap_def456.mp4"]
  },
  "cost_credits": 50,
  "created_at": "2026-02-27T10:05:00Z",
  "completed_at": "2026-02-27T10:07:30Z"
}

Python完全サンプル:複数人物動画フェイススワップワークフロー

以下のサンプルは、顔検出から複数人物動画フェイススワップまでの完全なフローを示しています:

import requests
import time

API_KEY = "sk-your-api-key"
BASE_URL = "https://www.namifusion.com/api/v1/marketplace/run"
HEADERS = {
    "X-API-Key": API_KEY,
    "Content-Type": "application/json",
}

source_url = "https://example.com/source_face.jpg"
target_url = "https://example.com/target_video.mp4"


def detect_faces(media_url, num_frames=None):
    """Submit face detection task and poll for result."""
    input_params = {"url": media_url, "return_face_url": True}
    if num_frames:
        input_params["num_frames"] = num_frames
    task = requests.post(
        f"{BASE_URL}/namifusion/detect_faces",
        headers=HEADERS,
        json={"input": input_params},
    ).json()

    while True:
        resp = requests.get(
            f"{BASE_URL}/tasks/{task['task_uuid']}",
            headers=HEADERS,
        ).json()

        if resp["status"] == "completed":
            return resp["output"]
        elif resp["status"] == "failed":
            raise Exception(resp.get("error_message", "Unknown error"))

        time.sleep(3)


# Step 1: detect faces in target video
target_detect = detect_faces(target_url, num_frames=3)
target_frame = target_detect["faces_obj"]["0"]

print(f"Target has {len(target_frame['face_urls'])} faces")
for i, face_url in enumerate(target_frame["face_urls"]):
    print(f"  Face {i}: region={target_frame['region'][i]}")

# Step 2: detect faces in source image
source_detect = detect_faces(source_url)
source_frame = source_detect["faces_obj"]["0"]

# Step 3: build face_mapping (replace target face 0 with source face 0)
face_mapping = [
    {
        "source_face_info": {"face_url": source_frame["face_urls"][0]},
        "target_face_info": {"face_url": target_frame["face_urls"][0]},
    }
]

# Step 4: submit video faceswap task
task_resp = requests.post(
    f"{BASE_URL}/namifusion/faceswap-video",
    headers=HEADERS,
    json={
        "input": {
            "source_url": source_url,
            "target_url": target_url,
            "single_face_mode": False,
            "face_mapping": face_mapping,
        }
    },
).json()

task_uuid = task_resp["task_uuid"]
print(f"Task submitted: {task_uuid}")

# Step 5: poll for result
while True:
    status_resp = requests.get(
        f"{BASE_URL}/tasks/{task_uuid}",
        headers=HEADERS,
    ).json()

    status = status_resp["status"]
    print(f"Status: {status}")

    if status == "completed":
        result_url = status_resp["output"]["videos"][0]
        print(f"Result: {result_url}")
        break
    elif status == "failed":
        print(f"Failed: {status_resp.get('error_message', 'Unknown error')}")
        break

    time.sleep(10)

パラメータとレスポンスの詳細

リクエストパラメータ

リクエストボディはJSON形式で、すべてのパラメータはinputオブジェクト内に配置します:

{
  "input": {
    "source_url": "https://...",
    "target_url": "https://...",
    "single_face_mode": true,
    "face_enhance": false,
    "face_mapping": [],
    "model_style": "realistic"
  }
}
パラメータ必須デフォルト説明
source_urlstringはい-ソース顔画像URL(ターゲットに置き換える顔)。公開アクセス可能である必要があります。
target_urlstringはい-ターゲット動画URL(フェイススワップされる動画)。公開アクセス可能である必要があります。
single_face_modebooleanいいえtrue単一顔モード。有効にすると、face_mappingの設定なしに自動的にフェイススワップが完了します。
face_enhancebooleanいいえfalse顔補正を有効にするかどうか。有効にすると自動的に肌を滑らかにし、顔の欠点を除去して顔品質が向上しますが、処理時間が増加します。
face_mappingarrayいいえnull顔マッピング設定。single_face_mode: falseの場合のみ有効です。詳細は下記を参照。
model_stylestringいいえ"realistic"フェイススワップスタイル。選択肢:"realistic"(リアル)、"beautify"(美顔)、"lossless"(ロスレス)。「パラメータが出力結果に与える影響」セクションを参照。

face_mapping詳細

face_mappingは配列で、各要素はソース顔からターゲット顔へのマッピング関係を定義します:

フィールド必須説明
source_face_indexintegerはいソース画像内の顔のインデックス(0始まり、左から右にソート)。
target_face_indexintegerはいターゲット動画内の顔のインデックス(0始まり、左から右にソート)。
source_face_infoobjectいいえソース顔の座標情報。指定すると内部の再検出をスキップし、顔の順序の一貫性を保証します。
target_face_infoobjectいいえターゲット顔の座標情報。指定するとマッチング精度が向上します。

source_face_infoフィールド

フィールド説明
bboxnumber[]顔のバウンディングボックス [x1, y1, x2, y2]
kpsnumber[][]顔の5つのキーポイント座標。指定するとバックエンドが直接使用し、再検出をスキップします。

target_face_infoフィールド

フィールド説明
bboxnumber[]ターゲット顔のバウンディングボックス [x1, y1, x2, y2]

タスクステータス

タスク送信後、ポーリングでステータスを取得します。推奨ポーリング間隔:10秒。

ステータス説明
pendingタスクが作成され、処理待ちです。
processingタスクが処理中です。
completedタスクが完了しました。output.videosから結果URLを取得できます。
failedタスクが失敗しました。error_messageで原因を確認してください。

レスポンス構造

タスク送信レスポンス

フィールド説明
task_uuidstringタスクの一意識別子。後続のステータス照会に使用します。
statusstring初期ステータス。通常はpendingです。
cost_creditsnumberこのタスクで消費されたクレジット。

タスク完了レスポンス

フィールド説明
task_uuidstringタスクの一意識別子。
model_idstringモデルID(namifusion/faceswap-video)。
statusstringタスクステータス。
output.videosstring[]フェイススワップ結果の動画URLリスト。
cost_creditsnumber消費クレジット。
created_atstringタスク作成時間(ISO 8601)。
completed_atstringタスク完了時間(ISO 8601)。
error_messagestringエラーメッセージ(failedの場合のみ返されます)。

パラメータが出力結果に与える影響

パラメータ結果への影響
single_face_mode: true自動的にフェイススワップを完了します。単一人物シナリオに適しており、face_mappingの設定は不要です。
single_face_mode: false + face_mappingどの顔を置き換えるかを正確に制御します。マッピングで指定されていない顔はそのまま変更されません。
face_enhance: true顔補正を有効にし、自動的に肌を滑らかにして欠点を除去し、より洗練された自然な外観になりますが、処理時間が約20〜50%増加します。
face_enhance: falseデフォルトモード。追加の顔処理なし、処理速度が速くなります。
model_style: "realistic"リアルスタイル。実際の顔に近い自然な外観を生成し、生活感のある肌色と質感を保持します。
model_style: "beautify"美顔スタイル。自動的に肌を滑らかにし明るくして、洗練された滑らかな外観を実現します。
model_style: "lossless"ロスレススタイル。究極のロスレスモードで、元の顔のすべてのディテールを完璧に保持し、最高のリアリズムでほぼ見分けがつきません。

注意事項

  1. URLは公開アクセス可能である必要がありますsource_urltarget_urlはどちらも直接ダウンロード可能な公開URLである必要があります。
  2. 顔インデックスのソートルールsource_face_indextarget_face_indexはどちらも0から始まり、顔bboxの左上隅のx座標に基づいて左から右にソートされます。
  3. face_infoの受け渡しを強く推奨:Detect Facesを既に呼び出している場合、検出されたbboxface_mappingに渡すことで、フェイススワップサービス内部の再検出によるインデックスの不一致問題を回避できます。
  4. ポーリング間隔:10秒ごとにタスクステータスをポーリングすることを推奨します。動画フェイススワップは通常30秒〜数分で完了し、動画の長さと解像度に依存します。
  5. 結果フィールド名:出力フィールド名はoutput.videosで、フェイススワップ後の動画URLが返されます。