> ## Documentation Index
> Fetch the complete documentation index at: https://docs.viggle.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 参考生视频

> 用最多 6 张参考图和 1 个参考视频引导 Viggle H3，把主体或风格带入新镜头。

参考生视频会生成一个新镜头，并沿用你自己素材中的主体、服装或风格。你给 Viggle H3 提供参考视频、参考图或两者，再加上描述新镜头的提示词。与帧画面模式不同，参考素材不会被固定到某一帧。输出为 5–15 秒、带原生音频的 MP4。

可以用它在多个镜头之间保持角色一致，或把照片中的产品或人物放进你描述的场景中。如果要替换现有视频中的人物并保留其动作，请改用 [Viggle Remake](https://docs.viggle.ai/zh/v1/video/remake.md)。

## 请求内容

以 `multipart/form-data` 调用 `POST /v1/videos`。发送任意参考字段即选择此模式。

| 参数 | 必填 | 说明 |
| - | - | - |
| `prompt` | 是 | 新镜头的内容，以及要从参考素材中保留什么 |
| `quality` | 是 | `low`（更快）或 `high`（保真度更高），价格相同。也可以用 [`ultrafast`](https://docs.viggle.ai/zh/v1/video/generate-video#ultrafast)，最快的档位，单独定价 |
| `reference_video` 或 `reference_video_url` | 至少一个参考 | 总共最多 1 个参考视频，以文件或 URL 发送 |
| `reference_image` 或 `reference_image_url` | 至少一个参考 | 总共最多 6 张参考图。每张图重复一次该字段；文件和 URL 可以混用 |
| `duration_s` | 否 | 5–15 秒，默认 `5`。与参考视频的时长无关 |

`resolution`、`aspect_ratio`、`enhance`、`seed` 和 `watermark` 的用法与其他模式相同，见[通用参数](https://docs.viggle.ai/zh/v1/video/generate-video#common-parameters)。

> [!NOTE]
>
> 参考素材不能与 `first_frame_image` 或 `last_frame_image` 字段同时使用（`400`）。发送 `driving_video` 或 `character_image` 字段会将请求切换到 [Viggle Remake](https://docs.viggle.ai/zh/v1/video/remake.md)。

### 素材限制

| 输入 | 限制 |
| - | - |
| 参考视频 | 最大 100 MiB，0.5–600 秒，至少 64×64 像素，宽和高均为偶数 |
| 参考图上传 | 每张最大 20 MiB |
| 参考图 URL 或 `data:` URI | 每张最大 30 MiB |
| 图片格式 | JPEG、PNG、WebP、GIF、BMP、TIFF、HEIC |
| URL | 公开的 `http(s)://` URL，或 base64 `data:` URI |

## 价格

与所有 Viggle H3 模式相同：按输出秒数和 `resolution` 计费，开启 `enhance` 时每秒另加 $0.01。使用 `low` 或 `high` 时，参考素材免费，长参考视频与短参考视频价格相同。使用 [`ultrafast`](https://docs.viggle.ai/zh/v1/video/generate-video#ultrafast) 时，参考视频的每一秒都计费，参考视频必须为 2–15 秒，且第 5 张之后的参考图额外计费。下面的示例（5 秒，768p，开启 enhance）消耗 10 积分（$0.10）。见[单价表](https://docs.viggle.ai/zh/v1/video/generate-video#price)。

## 生成视频

导出 `VIGGLE_API_KEY`，然后直接运行以下任一脚本。脚本把 Viggle 托管的一张示例角色图作为唯一的参考；准备好后换成你自己的素材即可。每个脚本每 5 秒轮询一次，并打印视频 URL。cURL 版本需要 `jq`。

```bash cURL theme={null}
#!/usr/bin/env bash
set -euo pipefail
API="https://apis.viggle.ai/v1"

video_id=$(curl -sS --fail-with-body "$API/videos" \
  -H "Authorization: Bearer $VIGGLE_API_KEY" \
  -F prompt="this character skateboarding down a sunny hill, same outfit and colors" \
  -F quality="high" \
  -F reference_image_url="https://assets.viggle.ai/pub/www/developers/threed-source-image-3f2f6787.webp" \
  -F duration_s="5" | jq -er '.id')
echo "Submitted $video_id"

for _ in $(seq 1 1440); do
  video=$(curl -sS --fail-with-body "$API/videos/$video_id" \
    -H "Authorization: Bearer $VIGGLE_API_KEY")
  case $(echo "$video" | jq -r '.status') in
    ready) echo "$video" | jq -r '.video_url'; exit 0 ;;
    failed|cancelled) echo "$video" | jq -c '.error' >&2; exit 1 ;;
  esac
  sleep 5
done
echo "Timed out waiting for $video_id" >&2; exit 1
```

```javascript Node.js theme={null}
// Node.js 20+。保存为 reference-to-video.mjs，然后运行：node reference-to-video.mjs
const API = "https://apis.viggle.ai/v1";
const headers = { Authorization: `Bearer ${process.env.VIGGLE_API_KEY}` };

async function call(path, init = {}) {
  const res = await fetch(`${API}${path}`, { ...init, headers });
  const body = await res.json();
  if (!res.ok) throw new Error(`HTTP ${res.status}: ${JSON.stringify(body.error)}`);
  return body;
}

const form = new FormData();
form.append("prompt", "this character skateboarding down a sunny hill, same outfit and colors");
form.append("quality", "high");
form.append("reference_image_url", "https://assets.viggle.ai/pub/www/developers/threed-source-image-3f2f6787.webp");
form.append("duration_s", "5");
const { id } = await call("/videos", { method: "POST", body: form });
console.log(`Submitted ${id}`);

for (let i = 0; i < 1440; i++) {
  const video = await call(`/videos/${id}`);
  if (video.status === "ready") {
    console.log(video.video_url);
    process.exit(0);
  }
  if (video.status === "failed" || video.status === "cancelled") {
    throw new Error(`${video.status}: ${JSON.stringify(video.error)}`);
  }
  await new Promise((resolve) => setTimeout(resolve, 5000));
}
throw new Error(`Timed out waiting for ${id}`);
```

```python Python theme={null}
import os
import time

import requests

API = "https://apis.viggle.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['VIGGLE_API_KEY']}"}


def check(resp):
    if not resp.ok:
        raise RuntimeError(f"HTTP {resp.status_code}: {resp.text}")
    return resp.json()


# 通过 files= 传字段，requests 会以 multipart/form-data 发送。
video = check(requests.post(f"{API}/videos", headers=HEADERS, timeout=300, files={
    "prompt": (None, "this character skateboarding down a sunny hill, same outfit and colors"),
    "quality": (None, "high"),
    "reference_image_url": (None, "https://assets.viggle.ai/pub/www/developers/threed-source-image-3f2f6787.webp"),
    "duration_s": (None, "5"),
}))
print("Submitted", video["id"])

for _ in range(1440):
    video = check(requests.get(f"{API}/videos/{video['id']}", headers=HEADERS))
    if video["status"] == "ready":
        print(video["video_url"])
        break
    if video["status"] in ("failed", "cancelled"):
        raise RuntimeError(f"{video['status']}: {video['error']}")
    time.sleep(5)
else:
    raise TimeoutError(f"Timed out waiting for {video['id']}")
```

> [!WARNING]
>
> 如果余额不足以支付该任务，请求仍会被接受，随后任务以 `failed` 结束，`error.code: "INSUFFICIENT_CREDITS"`。大批量提交前请先调用 `GET /v1/credits` 查看余额。

## 发送参考素材的其他方式

重复某个字段即可发送多个值。文件和 URL 可以混用，只要总数不超过 1 个视频和 6 张图片。

```bash 视频文件 theme={null}
curl https://apis.viggle.ai/v1/videos \
  -H "Authorization: Bearer $VIGGLE_API_KEY" \
  -F prompt="keep the same outfit and walk forward through a neon-lit street" \
  -F quality=low \
  -F reference_video=@reference.mp4
```

```bash 视频和图片 theme={null}
curl https://apis.viggle.ai/v1/videos \
  -H "Authorization: Bearer $VIGGLE_API_KEY" \
  -F prompt="the character from the photos performing the dance from the clip" \
  -F quality=low \
  -F reference_video_url=https://assets.viggle.ai/pub/www/developers/sample-motion-97bb074a.mp4 \
  -F reference_image=@character-front.png \
  -F reference_image=@character-side.png
```

## 获取结果

创建请求返回一个 `vid_` ID 和 `status: "queued"`。轮询 `GET /v1/videos/{video_id}`，直到 `status` 为 `ready`，然后下载 `video_url`。

* 链接有效期为一小时，每次读取都会返回新链接。
* 视频在任务结束 24 小时后删除，请复制到你自己的存储中。
* 只有创建该任务的 API 密钥才能读取它。

超过 1 个参考视频或 6 张参考图，或参考素材与帧画面字段混用，会在创建时被拒绝，返回 `400 INVALID_REQUEST`。见[任务生命周期](https://docs.viggle.ai/zh/v1/concepts/task-lifecycle.md)和[错误](https://docs.viggle.ai/zh/v1/production/errors.md)。

## 后续步骤

> [card] [Viggle Remake](https://docs.viggle.ai/zh/v1/video/remake.md)
>
> 保留视频的动作，替换其中的人物。

> [card] [首帧生视频](https://docs.viggle.ai/zh/v1/video/first-frame-to-video.md)
>
> 把开场帧固定为指定的图片。

> [card] [Viggle H3 概览](https://docs.viggle.ai/zh/v1/video/generate-video)
>
> 四种模式、通用参数和价格。

> [card] [创建视频（API 参考）](https://docs.viggle.ai/zh/v1/api-reference/videos/create-a-video.md)
>
> `POST /v1/videos` 的全部字段、限制和错误。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.