Video Character Swap API Usage

Business Process

  • Description
  1. Using the API Video Character Swap, you can replace the character in a video with another one.
  • Process explanation
  1. Video character replacement consists of four steps in sequence: Video Process → Image Mask Drawing → Video Mask Drawing → Video Character Swap.
  2. The taskId generated in the first step (Video Process) will serve as the input parameter for the second and third steps. The taskId from the third step (Video Mask Drawing) will be used as the input parameter for the fourth step. Below is the flow chart:
╔═══════════════════════════ Step 1 ═══════════════════════════╗
║ Video Process                                                ║
║ in : inputVideoFileId                                        ║
║ out: taskId (vp), resizedVideoUrl                            ║
╚═══════════════════════════╦══════════════════════════════════╝
                            ║ videoProcessTaskId = vp.taskId
                            ▼
╔═══════════════════════════ Step 2 ═══════════════════════════╗
║ Image Mask Drawing                                           ║
║ in : videoProcessTaskId,                                     ║
║      inputInfo(index, protect/modify points)                 ║
║ out: taskId (imd), mask, protectMask                         ║
╚═══════════════════════════╦══════════════════════════════════╝
                            ║ videoProcessTaskId = vp.taskId
                            ▼
╔═══════════════════════════ Step 3 ═══════════════════════════╗
║ Video Mask Drawing                                           ║
║ in : videoProcessTaskId,                                     ║
║      inputInfos(list of same structure in Step 2)            ║
║ out: taskId (vmd), maskVideoPath, protectMaskVideoPath       ║
╚═══════════════════════════╦══════════════════════════════════╝
                            ║ videoMaskDrawingTaskId = vmd.taskId
                            ▼
╔═══════════════════════════ Step 4 ═══════════════════════════╗
║ Video Character Swap                                         ║
║ in : videoMaskDrawingTaskId, modelImageFileId                ║
║ out: final taskId (vcs), outputVideoUrl                      ║
╚══════════════════════════════════════════════════════════════╝

Usage Example

  • First, obtain Topview-Uid and Authorization as request header parameters. For details, see the documentation How To Get Topview Uid And Key. Assume Topview-Uid=NsDAaOPF4jLuAie4ewyg and Authorization=Bearer sk-vEsneECh1J5eKHUw4vxHI61e7FvXPnPE1625PmSt3HB【Note: Current account is unavailable ❌】.

Step1: Execute Video Process Submit Task

curl --location --request POST 'https://api.topview.ai/v1/video_process/task/submit' \
--header 'Topview-Uid: NsDAaOPF4jLuAie4ewyg' \
--header 'Authorization: Bearer sk-vEsneECh1J5eKHUw4vxHI61e7FvXPnPE1625PmSt3HB' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Host: api.topview.ai' \
--header 'Connection: keep-alive' \
--data-raw '{
  "inputVideoFileId":"e004a7db019444a9b30fdd0fa899409c",
  "noticeUrl":""
}'
  • response

Pay attention to taskId as a videoProcessTaskId parameter for the Step2、Step3.


{
    "code": "200",
    "message": "Success",
    "result": {
        "taskId": "fe0614636f70427780ab5aa87d9e5141",
        "status": "success",
        "errorMsg": null,
        "noticeUuid": ""
    }
}

Step2: Execute Image Mask Drawing Submit Task

curl --location --request POST 'https://api.topview.ai/v1/segment_anything/task/submit' \
--header 'Topview-Uid: NsDAaOPF4jLuAie4ewyg' \
--header 'Authorization: Bearer sk-vEsneECh1J5eKHUw4vxHI61e7FvXPnPE1625PmSt3HB' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Host: api.topview.ai' \
--header 'Connection: keep-alive' \
--data-raw '{
    "videoProcessTaskId": "fe0614636f70427780ab5aa87d9e5141",
    "inputInfo": {
        "index": 0,
        "modifyPoints": [
            [
                624.2696629213483,
                627.2320675105485
            ],
            [
                624.2696629213483,
                699.915611814346
            ]
        ],
        "protectPoints": [
            [
                233.25842696629212,
                411.873417721519
            ]
        ]
    },
    "noticeUrl":""
}'
  • response
{
    "code": "200",
    "message": "Success",
    "result": {
        "taskId": "2eafaa57d5ae4a60b9318af5a85c363c",
        "status": "success",
        "errorMsg": null,
        "noticeUuid": ""
    }
}

Step3: Execute Video Mask Drawing Submit Task

curl --location --request POST 'https://api.topview.ai/v1/video_tracking/task/submit' \
--header 'Topview-Uid: NsDAaOPF4jLuAie4ewyg' \
--header 'Authorization: Bearer sk-vEsneECh1J5eKHUw4vxHI61e7FvXPnPE1625PmSt3HB' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Host: api.topview.ai' \
--header 'Connection: keep-alive' \
--data-raw '{
    "videoProcessTaskId": "fe0614636f70427780ab5aa87d9e5141",
    "inputInfos": [
        {
            "modifyPoints": [
                [
                    560.3007518796992,
                    545.4852320675105
                ]
            ],
            "index": 0
        },
        {
            "protectPoints": [
                [
                    354.5864661654135,
                    718.3122362869199
                ],
                [
                    259.84962406015035,
                    739.915611814346
                ]
            ],
            "index": 30
        }
    ],
    "noticeUrl":""
}'
  • response

Pay attention to taskId as a videoMaskDrawingTaskId parameter for the Step4

{
    "code": "200",
    "message": "Success",
    "result": {
        "taskId": "206e77a13a284f7d9c995dc5349ca6e0",
        "status": "success",
        "errorMsg": null,
        "noticeUuid": ""
    }
}

Step4: Execute Video Character Swap Submit Task

curl --location --request POST 'https://api.topview.ai/v1/video_character_swap/task/submit' \
--header 'Topview-Uid: NsDAaOPF4jLuAie4ewyg' \
--header 'Authorization: Bearer sk-vEsneECh1J5eKHUw4vxHI61e7FvXPnPE1625PmSt3HB' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Host: api.topview.ai' \
--header 'Connection: keep-alive' \
--data-raw '{
    "modelImageFileId": "629816a027bd4b5b83ac3356b06c7c86",
    "videoMaskDrawingTaskId": "206e77a13a284f7d9c995dc5349ca6e0",
    "noticeUrl":""
}'
  • response
{
    "code": "200",
    "message": "Success",
    "result": {
        "taskId": "bc6ec884d26f4ba9a2e6b8ef5f8fd63a",
        "status": "success",
        "errorMsg": null,
        "noticeUuid": ""
    }
}