generate_video
Generate videos from text prompts, images, or reference images using Doubao Seedance models. Create custom videos by specifying duration, frame rate, and resolution.
Instructions
使用豆包 Seedance 模型生成视频
支持功能:
文生视频: 使用文本提示词生成视频
图生视频: 使用首帧图片和提示词生成视频
参考图生视频: 使用参考图片增强视频风格一致性
参数说明:
prompt: 视频描述文本 (必需,最大 500 字符)
model: 模型选择 (可选,默认: doubao-seedance-1.0-lite-t2v)
doubao-seedance-1.0-pro: 专业版,高质量视频生成
doubao-seedance-1.0-pro-fast: 专业版快速生成
doubao-seedance-1.0-lite-t2v: 轻量版,快速生成
video_duration: 视频时长 (可选,默认 5) 支持的时长: 3, 4, 5, 6
fps: 冔率 (可选,默认 24) 支持的帧率: 24, 30
resolution: 分辨率 (可选,默认 1080p) 支持的分辨率: 480p, 720p, 1080p
first_frame_image_url: 首帧图片 URL (可选,用于图生视频)
ref_image_urls: 参考图片 URL 数组 (可选)
req_key: 请求标识 (可选)
返回: 任务 ID,需要使用 query_video_task 查询结果
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | 视频描述文本 (最大 500 字符) | |
| model | No | 模型选择,默认: doubao-seedance-1.0-lite-t2v | |
| video_duration | No | 视频时长 (秒),默认: 5 | |
| fps | No | 帧率,默认: 24 | |
| resolution | No | 分辨率,默认: 1080p | |
| first_frame_image_url | No | 首帧图片 URL (图生视频) | |
| ref_image_urls | No | 参考图片 URL 数组 | |
| req_key | No | 请求标识 |
Implementation Reference
- src/tools/generateVideo.ts:40-153 (handler)Core handler function implementing the generate_video tool logic: validates inputs, constructs API request to Doubao/Volcengine video generation endpoint, handles images, and returns task response.export async function generateVideo( apiKey: string, options: GenerateVideoOptions ): Promise<VideoGenerationResponse> { const { prompt, model, endpoint_id, video_duration = 5, fps = 24, resolution = "720p", first_frame_image_url, ref_image_urls, req_key, } = options; // 验证 prompt 长度 if (prompt.length > 500) { throw new Error("prompt 长度不能超过 500 字符"); } // 优先使用 endpoint_id,如果没有则使用 model const modelOrEndpoint = endpoint_id || model || "doubao-seedance-1.0-lite-t2v"; // 计算宽高比 const ratio = resolution === "720p" ? "16:9" : "adaptive"; // 构建带参数的文本 let textWithParams = prompt; // 如果 prompt 中没有 --dur 参数,添加默认时长 if (!prompt.includes("--dur")) { textWithParams += ` --dur ${video_duration}`; } // 如果 prompt 中没有 --fps 参数,添加默认帧率 if (!prompt.includes("--fps")) { textWithParams += ` --fps ${fps}`; } // 如果 prompt 中没有 --rs 参数,添加默认分辨率 if (!prompt.includes("--rs")) { textWithParams += ` --rs ${resolution}`; } // 如果 prompt 中没有 --ratio 参数,添加默认宽高比 if (!prompt.includes("--ratio")) { textWithParams += ` --ratio ${ratio}`; } // 构建 content 数组 const content: ContentItem[] = [ { type: "text", text: textWithParams, }, ]; // 添加首帧图片(图生视频) if (first_frame_image_url) { content.push({ type: "image_url", image_url: { url: first_frame_image_url, }, }); } // 添加参考图片(多图融合) if (ref_image_urls && ref_image_urls.length > 0) { for (const imageUrl of ref_image_urls) { content.push({ type: "image_url", image_url: { url: imageUrl, }, role: "reference_image", }); } } // 构建请求体 const requestBody: Record<string, any> = { model: modelOrEndpoint, content, }; try { const response = await fetch(`${BASE_URL}/contents/generations/tasks`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify(requestBody), }); const result: VideoGenerationResponse = await response.json(); // 检查是否有错误 if (result.error) { throw new Error( `视频生成失败: ${result.error.message || "未知错误"}` ); } // 检查 HTTP 状态码 if (!response.ok) { throw new Error(`HTTP 错误: ${response.statusText}`); } return result; } catch (error) { throw new Error( `视频生成请求失败: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:126-199 (registration)MCP tool registration for 'generate_video': defines name, description, and detailed inputSchema for ListToolsRequest.name: "generate_video", description: `使用豆包 Seedance 模型生成视频 支持功能: - 文生视频: 使用文本提示词生成视频 - 图生视频: 使用首帧图片和提示词生成视频 - 参考图生视频: 使用参考图片增强视频风格一致性 参数说明: - prompt: 视频描述文本 (必需,最大 500 字符) - model: 模型选择 (可选,默认: ${DEFAULT_VIDEO_MODEL}) * doubao-seedance-1.0-pro: 专业版,高质量视频生成 * doubao-seedance-1.0-pro-fast: 专业版快速生成 * doubao-seedance-1.0-lite-t2v: 轻量版,快速生成 - video_duration: 视频时长 (可选,默认 5) 支持的时长: 3, 4, 5, 6 - fps: 冔率 (可选,默认 24) 支持的帧率: 24, 30 - resolution: 分辨率 (可选,默认 1080p) 支持的分辨率: 480p, 720p, 1080p - first_frame_image_url: 首帧图片 URL (可选,用于图生视频) - ref_image_urls: 参考图片 URL 数组 (可选) - req_key: 请求标识 (可选) 返回: 任务 ID,需要使用 query_video_task 查询结果`, inputSchema: { type: "object", properties: { prompt: { type: "string", description: "视频描述文本 (最大 500 字符)", maxLength: 500, }, model: { type: "string", description: `模型选择,默认: ${DEFAULT_VIDEO_MODEL}`, enum: [ "doubao-seedance-1.0-pro", "doubao-seedance-1.0-pro-fast", "doubao-seedance-1.0-lite-t2v", ], }, video_duration: { type: "number", description: "视频时长 (秒),默认: 5", enum: [3, 4, 5, 6], }, fps: { type: "number", description: "帧率,默认: 24", enum: [24, 30], }, resolution: { type: "string", description: "分辨率,默认: 1080p", enum: ["480p", "720p", "1080p"], }, first_frame_image_url: { type: "string", description: "首帧图片 URL (图生视频)", }, ref_image_urls: { type: "array", items: { type: "string" }, description: "参考图片 URL 数组", }, req_key: { type: "string", description: "请求标识", }, }, required: ["prompt"], }, },
- src/index.ts:257-272 (handler)Dispatch handler in MCP CallToolRequest that invokes the generateVideo function with API key and arguments.case "generate_video": { // 如果没有提供 endpoint_id 且环境变量中有,则使用环境变量的值 const videoArgs = { ...args }; if (!videoArgs.endpoint_id && DEFAULT_VIDEO_ENDPOINT_ID) { videoArgs.endpoint_id = DEFAULT_VIDEO_ENDPOINT_ID; } const result = await generateVideo(API_KEY, videoArgs as any); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; }
- src/tools/generateVideo.ts:6-16 (schema)TypeScript interface defining input options for the generateVideo handler.interface GenerateVideoOptions { prompt: string; model?: string; endpoint_id?: string; video_duration?: number; fps?: number; resolution?: string; first_frame_image_url?: string; ref_image_urls?: string[]; req_key?: string; }
- src/index.ts:15-15 (registration)Import statement registering the generateVideo handler for use in the MCP server.import { generateVideo } from "./tools/generateVideo.js";