文档 / 示例 / 图生视频
图生视频
将一张静态图片转换为短视频。该图片作为 reference_image 放入 metadata.content[],并在 prompt 中用 @image1 引用它。
#流程
- 为你的图片获取一个 URL:通过
POST /v1/files上传图片,或使用任何你已托管的公开 URL - 提交
POST /v1/video/generations,将图片放入metadata.content[],并在 prompt 中用@image1引用 - 轮询
GET /v1/video/generations/{task_id}直到状态为succeeded,或设置metadata.callback_url等待 webhook 回调 - 从
url字段下载视频
#cURL
terminalbash
# 1) 提交任务
curl https://relaydance.com/v1/video/generations \
-H "Authorization: Bearer $RELAYDANCE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedance-1-5-pro-with-audio",
"prompt": "@image1 comes alive: gentle camera pull-back, hair moving in a soft breeze",
"seconds": "5",
"metadata": {
"ratio": "16:9",
"resolution": "720p",
"content": [
{
"type": "image_url",
"image_url": { "url": "https://example.com/portrait.jpg" },
"role": "reference_image"
}
]
}
}'
# -> { "task_id": "...", "status": "submitted" }
# 2) 轮询(替换 TASK_ID)
curl https://relaydance.com/v1/video/generations/TASK_ID \
-H "Authorization: Bearer $RELAYDANCE_API_KEY"#Python(上传 + 提交 + 轮询)
image_to_video.pypython
import requests, os, time
BASE = "https://relaydance.com/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['RELAYDANCE_API_KEY']}"}
# 1) 上传本地图片(若已有公开 URL 可跳过)
upload = requests.post(
f"{BASE}/files",
headers=HEADERS,
files={"file": open("portrait.jpg", "rb")},
)
image_url = upload.json()["url"]
# 2) 提交视频任务
submit = requests.post(
f"{BASE}/video/generations",
headers={**HEADERS, "Content-Type": "application/json"},
json={
"model": "seedance-1-5-pro-with-audio",
"prompt": "@image1 comes alive: gentle camera pull-back, soft natural light",
"seconds": "5",
"metadata": {
"ratio": "16:9",
"resolution": "720p",
"content": [
{
"type": "image_url",
"image_url": {"url": image_url},
"role": "reference_image",
}
],
},
},
)
task_id = submit.json()["task_id"]
# 3) 轮询直到视频生成完成
while True:
task = requests.get(f"{BASE}/video/generations/{task_id}", headers=HEADERS).json()
if task["status"] == "succeeded":
print("Video:", task["url"])
break
if task["status"] == "failed":
raise RuntimeError(task)
time.sleep(5)#Node.js / TypeScript
imageToVideo.tstypescript
const BASE = "https://relaydance.com/v1";
const KEY = process.env.RELAYDANCE_API_KEY;
// 1) 使用托管图片 URL 提交任务
const submit = await fetch(`${BASE}/video/generations`, {
method: "POST",
headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
model: "seedance-1-5-pro-with-audio",
prompt: "@image1 comes alive: gentle camera pull-back, soft natural light",
seconds: "5",
metadata: {
ratio: "16:9",
resolution: "720p",
content: [
{
type: "image_url",
image_url: { url: "https://example.com/portrait.jpg" },
role: "reference_image",
},
],
},
}),
});
const { task_id } = await submit.json();
// 2) 轮询
while (true) {
const r = await fetch(`${BASE}/video/generations/${task_id}`, {
headers: { Authorization: `Bearer ${KEY}` },
});
const task = await r.json();
if (task.status === "succeeded") { console.log("Video:", task.url); break; }
if (task.status === "failed") throw new Error(JSON.stringify(task));
await new Promise((s) => setTimeout(s, 5000));
}生产环境建议使用 webhook:在
metadata 内加上 callback_url,最终的任务 JSON 会 POST 给你,无需轮询循环。#模型选择
| 模型 | 选择理由 |
|---|---|
seedance-1-5-pro-with-audio | 图生视频,并生成配音 |
seedance-1-5-pro-no-audio | 同系列,无声输出 |
doubao-seedance-2-0-1080p | 最高保真度,多参考图融合 |
happyhorse-1.0-i2v | 专用图生视频模型 |
每个请求最多 9 张参考图,按
content[] 的顺序以 @image1 到 @imageN 引用。参考图与首尾帧模式互斥。完整结构见 视频生成。