> **Reading as an AI agent?** This is the Markdown version of https://docs.meshy.ai/api/v2/video-to-motion, part of the Meshy API v2 docs.
>
> - v2 docs index: https://docs.meshy.ai/api/v2/llms.txt
> - All v2 pages in one file: https://docs.meshy.ai/api/v2/llms-full.txt
> - OpenAPI spec for v2: https://docs.meshy.ai/api/v2/openapi.yaml

---

# Video to Motion API

Turn a video of a person moving into a motion clip, then play it on any two-legged character you rigged with the [Rigging API](https://docs.meshy.ai/api/v2/rigging.md).

> **Note:** Moving from v1? The request is the same. The main changes for Video to Motion:
>   * The create response is the [task object](https://docs.meshy.ai/api/v2/tasks.md#the-task-object) instead of an object with the task ID in `result`.
>   * Read the task through [Tasks](https://docs.meshy.ai/api/v2/tasks.md) instead of `GET /openapi/v1/video-to-motion/:id`.
>   * Results are in `output` instead of `result`, and `output` is `null` until the task succeeds.
>
>   See [what changed for the other endpoints](/api/migrate-to-v2/reference#other-endpoints).

---

## POST /openapi/v2/video-to-motion -- Create a Video to Motion task

Creates a Video to Motion task and returns the [task object](https://docs.meshy.ai/api/v2/tasks.md#the-task-object). The task reads the motion of the person in a video into a GLB clip as long as the video. It runs in the background. To read its result, see [Get the result](#get-the-result).

Meshy downloads and checks the video while it handles your request, so a video it can't use returns `400` before Meshy creates a task. The video must meet all of these requirements:
* **File**: an MP4, MOV, or AVI file of at most 200 MB (200,000,000 bytes)
* **Video codec**: H.264, HEVC, MPEG-4, or Motion JPEG
* **Length**: 2 to 60 seconds
* **Frame rate**: 24 to 120 frames per second
* **Resolution**: each side 300 to 4,096 pixels

For the best clip, film one person whose whole body stays in the frame.

A task costs 5 credits for each second of video, rounded to the nearest credit. For example, a 2.5-second video costs 13 credits. Meshy charges the credits when it creates the task, and refunds them if the task fails. See [Pricing](/api/pricing).

When the task succeeds or fails, Meshy deletes your video. The clip stays with the task, like other task files. See [Asset retention](https://docs.meshy.ai/api/v2/asset-retention.md).

To play the motion on a character, see [Apply the motion to a character](#apply-the-motion-to-a-character).

### Parameters

  - `video_url` · *string* · **required**

  The video, as a public `http` or `https` URL or a base64 data URI, such as `data:video/mp4;base64,...`. A data URI's media type must be `video/*` or `application/octet-stream`. Either way, the file can be at most 200 MB. A video that Meshy can't download, or that's outside the preceding requirements, returns `400`.

### Returns

`202 Accepted` with the [task object](https://docs.meshy.ai/api/v2/tasks.md#the-task-object). The task starts as `PENDING`, with your request in `input` and `output` set to `null`. When you send a data URI, `input.video_url` holds its header without the video, such as `data:video/mp4;base64,[omitted]`.

Two response headers help you read the task:
* `Location`: the task's URL on [Tasks](https://docs.meshy.ai/api/v2/tasks.md#how-a-task-runs)
* `Retry-After`: how many seconds to wait before you first read it

### Failure modes

  - `400 - Bad Request`

  The request can't run. For example:
  * `video_url` wasn't sent. The code is `parameter_missing`.
  * The request has a parameter the endpoint doesn't take, such as `prompt`. The code is `parameter_unknown`.
  * Meshy couldn't download `video_url`. The code is `input_download_failed`. Make the URL publicly readable, or send the file as a data URI.
  * The file isn't a video Meshy can use. The code is `input_file_invalid`, and the message names the problem, for example `video_url: the video runs 1.5 s; it must run 2 to 60 s`. Send a video that meets the requirements.

  The error message says which problem it found. See [Errors](https://docs.meshy.ai/api/v2/errors.md#request-errors).

  - `401 - Unauthorized`

  The API key is missing or invalid. Check the `Authorization` header.

  - `402 - Payment Required`

  One of these applies:
  * The account doesn't have enough credits for this video.
  * The account reached a credit limit.
  * The account is on the free plan.

  Check your credits and plan, then retry.

  - `403 - Forbidden`

  Content moderation blocked the video. The code is `moderation_blocked_nsfw`, and the message is `explicit content`. Send a different video.

  - `429 - Too Many Requests`

  One of these limits was reached:
  * Meshy is checking too many videos. The code is `rate_limit_exceeded`, and the message is `Video processing is busy; try again shortly`. Wait a few seconds, then retry.
  * You sent too many requests. Wait the number of seconds in `Retry-After`, then retry.
  * Too many of your tasks are queued or running. Wait for some to finish, then retry.
  * On an unlimited plan with no credits left, you reached the number of tasks that can run without credits. Wait for a task to finish, or add credits.

Meshy charges nothing for a request that returns an error.

**cURL**

```bash
# Read the motion from a video at a public URL
curl https://api.meshy.ai/openapi/v2/video-to-motion \
  -X POST \
  -H "Authorization: Bearer ${MESHY_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "video_url": "https://example.com/videos/dance.mp4"
  }'

# Send a local MP4 file as a data URI
{ printf '{"video_url": "data:video/mp4;base64,'; base64 < dance.mp4 | tr -d '\n'; printf '"}'; } |
  curl https://api.meshy.ai/openapi/v2/video-to-motion \
    -X POST \
    -H "Authorization: Bearer ${MESHY_API_KEY}" \
    -H 'Content-Type: application/json' \
    --data-binary @-
```

```javascript
import { readFile } from "node:fs/promises";

// Send a local MP4 file as a data URI
const video = await readFile("dance.mp4");
const response = await fetch("https://api.meshy.ai/openapi/v2/video-to-motion", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MESHY_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    video_url: `data:video/mp4;base64,${video.toString("base64")}`,
  }),
});
if (!response.ok) throw new Error(await response.text());
const task = await response.json();
console.log(task.id, task.status);
```

```python
import base64
import os
import requests

# Send a local MP4 file as a data URI
with open("dance.mp4", "rb") as f:
    video = base64.b64encode(f.read()).decode()

response = requests.post(
    "https://api.meshy.ai/openapi/v2/video-to-motion",
    headers={"Authorization": f"Bearer {os.environ['MESHY_API_KEY']}"},
    json={"video_url": f"data:video/mp4;base64,{video}"},
)
response.raise_for_status()
task = response.json()
print(task["id"], task["status"])
```

**Response**

```json
{
  "id": "019ad6a1-4c2e-7f38-b5d0-8e3f1a6c9b24",
  "type": "video-to-motion",
  "status": "PENDING",
  "progress": 0,
  "created_at": 1796083214512,
  "started_at": null,
  "finished_at": null,
  "expires_at": null,
  "preceding_tasks": 1,
  "consumed_credits": 21,
  "task_error": null,
  "input": {
    "video_url": "data:video/mp4;base64,[omitted]"
  },
  "output": null
}
```

---

## Apply the motion to a character

The clip in `output.motion_url` has the motion on its own, with no character. To play it on your character, wait until the Video to Motion task's status is `SUCCEEDED`. Then create an [Animation](https://docs.meshy.ai/api/v2/animation.md) task with these parameters:
* `motion_task_id`: the Video to Motion task's `id`
* `rig_task_id`: the `id` of one of your [Rigging](https://docs.meshy.ai/api/v2/rigging.md) tasks with a `biped` rig

Create the Animation task within 3 days after the Video to Motion task finishes. After that, Meshy deletes the clip, like other task files, and Animation returns `404`. Enterprise accounts keep their files.

Meshy charges for each task separately. See [Pricing](/api/pricing).

**cURL**

```bash
# 1. Read the motion from a video
curl https://api.meshy.ai/openapi/v2/video-to-motion \
  -X POST \
  -H "Authorization: Bearer ${MESHY_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "video_url": "https://example.com/videos/dance.mp4"
  }'

# 2. When it succeeds, play it on a rigged character
curl https://api.meshy.ai/openapi/v2/animations \
  -X POST \
  -H "Authorization: Bearer ${MESHY_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "rig_task_id": "<Rigging task ID>",
    "motion_task_id": "<Video to Motion task ID>"
  }'
```

```javascript
// The ID of one of your Rigging tasks with a biped rig
const rigTaskId = process.env.MESHY_RIG_TASK_ID;
if (!rigTaskId) {
  throw new Error("Set MESHY_RIG_TASK_ID to the ID of one of your Rigging tasks with a biped rig");
}

const API = "https://api.meshy.ai/openapi/v2";
const headers = {
  Authorization: `Bearer ${process.env.MESHY_API_KEY}`,
  "Content-Type": "application/json",
};

async function create(path, body) {
  const response = await fetch(`${API}/${path}`, {
    method: "POST",
    headers,
    body: JSON.stringify(body),
  });
  if (!response.ok) throw new Error(await response.text());
  return (await response.json()).id;
}

async function wait(id) {
  for (;;) {
    const response = await fetch(`${API}/tasks/${id}`, { headers });
    if (!response.ok) throw new Error(await response.text());
    const task = await response.json();
    if (task.status === "SUCCEEDED") return task;
    if (task.status === "FAILED" || task.status === "CANCELED") {
      throw new Error(JSON.stringify(task.task_error));
    }
    const seconds = Number(response.headers.get("Retry-After") ?? 5);
    await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
  }
}

// 1. Read the motion from a video, 2. play it on a rigged character
const motion = await wait(await create("video-to-motion", {
  video_url: "https://example.com/videos/dance.mp4",
}));
const animation = await wait(await create("animations", {
  rig_task_id: rigTaskId,
  motion_task_id: motion.id,
}));

console.log(animation.output.animation_glb_url);
```

```python
import os
import time
import requests

# The ID of one of your Rigging tasks with a biped rig
RIG_TASK_ID = os.environ.get("MESHY_RIG_TASK_ID")
if not RIG_TASK_ID:
    raise SystemExit("Set MESHY_RIG_TASK_ID to the ID of one of your Rigging tasks with a biped rig")

API = "https://api.meshy.ai/openapi/v2"
HEADERS = {"Authorization": f"Bearer {os.environ['MESHY_API_KEY']}"}

def create(path, body):
    response = requests.post(f"{API}/{path}", headers=HEADERS, json=body)
    response.raise_for_status()
    return response.json()["id"]

def wait(task_id):
    while True:
        response = requests.get(f"{API}/tasks/{task_id}", headers=HEADERS)
        response.raise_for_status()
        task = response.json()
        if task["status"] == "SUCCEEDED":
            return task
        if task["status"] in ("FAILED", "CANCELED"):
            raise RuntimeError(task["task_error"])
        time.sleep(int(response.headers.get("Retry-After", 5)))

# 1. Read the motion from a video, 2. play it on a rigged character
motion = wait(create("video-to-motion", {
    "video_url": "https://example.com/videos/dance.mp4",
}))
animation = wait(create("animations", {
    "rig_task_id": RIG_TASK_ID,
    "motion_task_id": motion["id"],
}))

print(animation["output"]["animation_glb_url"])
```

---

## Get the result
Read Video to Motion tasks the same way as every other v2 task, through the [Tasks](https://docs.meshy.ai/api/v2/tasks.md) routes. To list only Video to Motion tasks, filter by `type=video-to-motion`.

| To | Call |
| --- | --- |
| Get one task | [`GET /openapi/v2/tasks/{id}`](https://docs.meshy.ai/api/v2/tasks.md#get-a-task) |
| Wait for updates | [`GET /openapi/v2/tasks/{id}/stream`](https://docs.meshy.ai/api/v2/tasks.md#stream-a-task) or a [webhook](https://docs.meshy.ai/api/v2/webhooks.md) |
| List your tasks | [`GET /openapi/v2/tasks?type=video-to-motion`](https://docs.meshy.ai/api/v2/tasks.md#list-tasks) |
| Delete a task | [`DELETE /openapi/v2/tasks/{id}`](https://docs.meshy.ai/api/v2/tasks.md#delete-a-task) |

---

## Video to Motion output
When the task succeeds, `output` holds these fields. The rest of the [task object](https://docs.meshy.ai/api/v2/tasks.md#the-task-object) is the same for every task type. The URL in `output` stops working at `expires_at`.

  - `motion_url` · *string | null*

  Signed URL to the motion clip, a GLB file at 30 frames per second.

  - `motion_format` · *string*

  The clip's file format, always `glb`.

  - `duration_ms` · *integer*

  The clip length, in milliseconds. It's the length of the video, as Meshy measured it when you created the task.

**Succeeded Video to Motion task**

```json
{
  "id": "019ad6a1-4c2e-7f38-b5d0-8e3f1a6c9b24",
  "type": "video-to-motion",
  "status": "SUCCEEDED",
  "progress": 100,
  "created_at": 1796083214512,
  "started_at": 1796083216813,
  "finished_at": 1796083288293,
  "expires_at": 1796342488293,
  "preceding_tasks": 0,
  "consumed_credits": 21,
  "task_error": null,
  "input": {
    "video_url": "https://example.com/videos/dance.mp4"
  },
  "output": {
    "motion_url": "https://assets.meshy.ai/***/output/clip.glb?Expires=***",
    "motion_format": "glb",
    "duration_ms": 4200
  }
}
```
