Documentation Index
Fetch the complete documentation index at: https://docs-model.skyengine.com.cn/llms.txt
Use this file to discover all available pages before exploring further.
豆包 Seedance 视频生成示例
以下示例展示如何使用豆包(Doubao)Seedance 视频生成模型通过 OpenAI 兼容接口生成高质量的视频内容。
支持的模型
| 模型 ID | 能力 | 时长 | 分辨率 | 帧率 |
|---|
| doubao-seedance-1-5-pro-251215 | 音画同生(有声视频)、图生视频-首尾帧、图生视频-首帧、文生视频 | 4~12 秒 | 480p, 720p, 1080p | 24 fps |
| doubao-seedance-1-0-pro-250528 | 图生视频-首尾帧、图生视频-首帧、文生视频 | 2~12 秒 | 480p, 720p, 1080p | 24 fps |
注意: doubao-seedance-1-5-pro-251215 支持生成带音频的有声视频,通过 generate_audio 参数启用。
豆包视频生成分为三个步骤:
- 创建视频生成任务 - 提交生成请求,获得任务ID
- 查询任务状态 - 定期检查任务进度
- 下载生成的视频 - 任务完成后下载视频文件
步骤1:创建视频生成任务
curl --request POST \
--url https://model-api.skyengine.com.cn/v1/videos \
--header 'Authorization: Bearer <API-KEY>' \
--header 'Content-Type: application/json' \
--data '{
"model": "doubao-seedance-1.0-pro-250528",
"content": [
{
"type": "text",
"text": "多个镜头。一名侦探进入一间光线昏暗的房间。他检查桌上的线索,手里拿起桌上的某个物品。镜头转向他正在思索。 --ratio 16:9"
}
]
}'
响应示例
{
"id": "cgt-20251110203910-nmfp7",
"object": "video",
"status": "in_queue"
}
步骤2:查询任务状态
# 查询任务状态
curl -X GET "https://model-api.skyengine.com.cn/v1/videos/cgt-20251110203910-nmfp7" \
--header 'Authorization: Bearer <API-KEY>'
状态响应示例
排队中:
{
"id": "cgt-20251110203910-nmfp7",
"object": "video",
"status": "in_queue"
}
已完成:
{
"id": "cgt-20251110203910-nmfp7",
"object": "video",
"created_at": 1762778350,
"model": "doubao-seedance-1-0-pro-250528",
"status": "completed",
"usage": {
"completion_tokens": 246840,
"total_tokens": 246840
}
}
步骤3:下载生成的视频
# 下载视频文件
curl -X GET "https://model-api.skyengine.com.cn/v1/videos/cgt-20251110203910-nmfp7/content" \
--header 'Authorization: Bearer <API-KEY>' \
--output doubao_video.mp4
完整流程示例
import requests
import time
API_KEY = "<API-KEY>"
BASE_URL = "https://model-api.skyengine.com.cn/v1"
def complete_doubao_video_generation(content, **kwargs):
"""
完整的豆包视频生成流程
"""
# 步骤1: 创建任务
print("步骤1: 创建视频生成任务...")
create_result = create_doubao_video(content, **kwargs)
if not create_result:
return False
video_id = create_result['id']
print(f"任务ID: {video_id}")
# 步骤2: 等待任务完成
print("步骤2: 等待任务完成...")
max_wait_time = 900 # 15分钟
start_time = time.time()
while time.time() - start_time < max_wait_time:
status_info = check_video_status(video_id)
if not status_info:
break
status = status_info.get('status')
print(f"当前状态: {status}")
if status == 'completed':
print("视频生成完成!")
break
elif status == 'failed':
error_info = status_info.get('error', {})
print(f"视频生成失败: {error_info.get('message', '未知错误')}")
return False
time.sleep(20) # 每20秒检查一次
else:
print("等待超时")
return False
# 步骤3: 下载视频
print("步骤3: 下载视频...")
output_path = f"doubao_video_{video_id}.mp4"
if download_video(video_id, output_path):
print(f"视频生成完成: {output_path}")
return True
return False
# 使用示例
if __name__ == "__main__":
# 示例1: 基础文本到视频生成
text_content = [
{
"type": "text",
"text": "多个镜头。一名侦探进入一间光线昏暗的房间。他检查桌上的线索,手里拿起桌上的某个物品。镜头转向他正在思索。 --ratio 16:9"
}
]
success = complete_doubao_video_generation(content=text_content)
if success:
print("✅ 视频生成成功!")
else:
print("❌ 视频生成失败!")
支持的参数
基础参数
| 参数名 | 类型 | 必填 | 描述 |
|---|
| model | String | 是 | 使用的模型名称,如 doubao-seedance-1.0-pro-250528 |
| content | Array | 是 | 内容数组,支持文本和图片信息 |
内容类型 (content 数组元素)
| 参数名 | 类型 | 必填 | 描述 |
|---|
| type | String | 是 | 内容类型:text(文本)或 image_url(图片) |
| text | String | 条件必填 | 文本内容(当 type=text 时必填) |
| image_url | Object | 条件必填 | 图片信息对象(当 type=image_url 时必填),包含 url 字段 |
| role | String | 否 | 图片角色:first_frame(首帧)、last_frame(尾帧)、reference_image(参考图片) |
视频生成参数
| 参数名 | 类型 | 必填 | 描述 |
|---|
| size | String | 否 | 视频尺寸,格式为 宽x高(如 1920x1088),系统会自动转换为对应的宽高比 |
| ratio | String | 否 | 宽高比,可选值:16:9、4:3、1:1、3:4、9:16、21:9、keep_ratio、adaptive。可通过 size 参数自动推导 |
| seconds | String | 否 | 视频时长(秒),范围取决于模型:doubao-seedance-1-0-pro-250528 支持 212秒,doubao-seedance-1-5-pro-251215 支持 412秒 |
| framespersecond | Integer | 否 | 帧率,支持值:24 |
| camerafixed | Boolean | 否 | 是否固定摄像头 |
| watermark | Boolean | 否 | 是否包含水印 |
| return_last_frame | Boolean | 否 | 是否返回生成视频的尾帧图像 |
| generate_audio | Boolean | 否 | 是否生成有声视频(仅 doubao-seedance-1-5-pro-251215 支持) |
Size 参数映射表
通过 size 参数可以自动设置宽高比,不同模型版本支持的尺寸有所不同。
doubao-seedance-1-5-pro-251215 支持的尺寸
480p:
| Size (宽x高) | 宽高比 |
|---|
| 864x496 | 16:9 |
| 752x560 | 4:3 |
| 640x640 | 1:1 |
| 560x752 | 3:4 |
| 496x864 | 9:16 |
| 992x432 | 21:9 |
720p:
| Size (宽x高) | 宽高比 |
|---|
| 1280x720 | 16:9 |
| 1112x834 | 4:3 |
| 960x960 | 1:1 |
| 834x1112 | 3:4 |
| 720x1280 | 9:16 |
| 1470x630 | 21:9 |
1080p:
| Size (宽x高) | 宽高比 |
|---|
| 1920x1080 | 16:9 |
| 1664x1248 | 4:3 |
| 1440x1440 | 1:1 |
| 1248x1664 | 3:4 |
| 1080x1920 | 9:16 |
| 2206x946 | 21:9 |
doubao-seedance-1-0-pro-250528 支持的尺寸
480p:
| Size (宽x高) | 宽高比 |
|---|
| 864x480 | 16:9 |
| 736x544 | 4:3 |
| 640x640 | 1:1 |
| 544x736 | 3:4 |
| 480x864 | 9:16 |
| 960x416 | 21:9 |
720p:
| Size (宽x高) | 宽高比 |
|---|
| 1248x704 | 16:9 |
| 1120x832 | 4:3 |
| 960x960 | 1:1 |
| 832x1120 | 3:4 |
| 704x1248 | 9:16 |
| 1504x640 | 21:9 |
1080p:
| Size (宽x高) | 宽高比 |
|---|
| 1920x1088 | 16:9 |
| 1664x1248 | 4:3 |
| 1440x1440 | 1:1 |
| 1248x1664 | 3:4 |
| 1088x1920 | 9:16 |
| 2176x928 | 21:9 |
任务状态说明
- in_queue: 任务已提交,正在排队等待处理
- running: 任务正在处理中
- completed: 任务已完成,可以下载视频
- failed: 任务失败
内容格式示例
纯文本输入(使用命令参数)
{
"content": [
{
"type": "text",
"text": "一只猫在阳光下睡觉,微风轻抚,画面温馨 --ratio 16:9 --duration 6"
}
]
}
使用 size 参数设置分辨率
{
"model": "doubao-seedance-1.0-pro-250528",
"content": [
{
"type": "text",
"text": "一只猫在阳光下睡觉,微风轻抚,画面温馨"
}
],
"size": "1920x1088",
"seconds": "6"
}
使用 size: "1920x1088" 会自动设置为 1080p 分辨率和 16:9 宽高比
文本+参考图片
{
"content": [
{
"type": "text",
"text": "基于这张图片生成一段动态视频"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.jpg"
},
"role": "reference_image"
}
]
}
首帧指定
{
"content": [
{
"type": "text",
"text": "从这个场景开始,展现一个故事"
},
{
"type": "image_url",
"image_url": {
"url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ..."
},
"role": "first_frame"
}
]
}