mcpField
A
ai-video-gen

ai-video-gen

github.com/calesthio创意与媒体72.7k1.3k 次安装今天更新
代码仓库

关于 ai-video-gen

ai-video-gen 是一项技能,可通过多个 API 网关和视频提供商根据文本提示生成视频。它要求通过 video_selector 路由请求,以检查可用性、比较成本并自动回退。

主要功能

  1. 01根据文本提示生成视频
  2. 02使用参考图进行图生视频
  3. 03支持多个网关和视频提供商
  4. 04通过 Gemini Omni 多轮编辑
  5. 05选择提供商并自动回退

适用场景

  1. 01根据文字描述生成短片
  2. 02将产品照片制作成动态视频
  3. 03制作竖屏社交媒体视频
  4. 04通过对话修改已有片段

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/calesthio/openmontage --skill ai-video-gen

安装后在 Claude Code 中输入/ai-video-gen确认已加载。

详细介绍

视频生成(多网关)

根据文本提示词生成 AI 视频。通过 4 个 API 路径支持多个提供商:

网关环境变量提供商工具
fal.aiFAL_KEYSeedance 2.0(标准版 + 快速版)、Kling v3/v2.1、MiniMax、VEOseedance_video、kling_video、minimax_video、veo_video
HeyGenHEYGEN_API_KEYVEO 3.1、Kling Pro、Sora v2、Runway Gen-4、Seedance Pro / Lite(1.x)heygen_video
Kling OfficialKLING_API_KEYKling 官方 Classic、Turbo 和基础 Omni 视频kling_official_video
Gemini APIGEMINI_API_KEY / GOOGLE_API_KEYGemini Omni Flash(生成 + 对话式编辑)gemini_omni_video

迭代编辑 — Gemini Omni。 如果需求是优化现有片段(添加 / 移除对象、改变风格、调整光线或屏幕文字),而不是重新生成,Gemini Omni Flash 是整个服务阵列中唯一支持有状态多轮编辑的提供商。为它编写任何提示词之前,请参阅 Layer 3 gemini-omni 中的权威提示指南(参考图像标签、时间码语法、编辑提示词规则)。

首选高端默认选项 — Seedance 2.0。 配置了任意高端网关时(FAL_KEY → seedance_video,或 HeyGen 的 Video Agent / Avatar Shots 路径),Seedance 2.0 是电影感、预告片和高保真片段制作的首选默认选项。它是整个服务阵列中唯一支持单次生成原生同步音频、多镜头生成、导演级摄像机控制,以及根据引用的对白进行唇形同步的模型;截至 2026 年初,它在 Artificial Analysis Elo 排名中位列第 1。仅当用户有明确理由时才切换(预算、提供商偏好、风格匹配,例如写实风景选 VEO,特定动漫风格选 Kling)。请参阅 Layer 3 seedance-2-0 中的权威提示词和参数指南。

重要: 始终使用 video_selector,不要直接调用提供商工具。选择器会检查可用性、比较成本并自动回退,其评分引擎已会在电影感需求下优先倾向 Seedance 2.0。

身份验证

根据用户可用的提供商以及成本 / 质量目标,使用最合适的已配置网关。

  • HeyGen: 设置 HEYGEN_API_KEY,以使用多模型网关。
  • fal.ai: 设置 FAL_KEY,以通过 fal.ai 使用 Kling、MiniMax 和 Veo。
  • Kling Official: 设置 KLING_API_KEY,通过 provider="kling_official" 使用 Kling 官方直连接口。
  • Gemini API: 设置 GEMINI_API_KEY 或 GOOGLE_API_KEY,以使用 Gemini Omni 视频生成和对话式编辑。

未检查注册表和当前任务的适配情况之前,不要将任何网关描述为默认或首选。

fal.ai Kling(kling_video、provider="kling")与 Kling Official(kling_official_video、provider="kling_official")是不同的路径。选择官方提供商时,不要复用 fal.ai 队列 URL、FAL_KEY 或图像上传行为。

curl -X POST "https://api.heygen.com/v1/workflows/executions" \
  -H "X-Api-Key: $HEYGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"workflow_type": "GenerateVideoNode", "input": {"prompt": "A drone shot flying over a coastal city at sunset"}}'

默认工作流

  1. 调用 POST /v1/workflows/executions,并传入 workflow_type: "GenerateVideoNode" 和提示词
  2. 从响应中获取 execution_id
  3. 每隔 10 秒轮询 GET /v1/workflows/executions/{id},直到状态为 completed
  4. 使用输出中返回的 video_url

执行视频生成

端点

POST https://api.heygen.com/v1/workflows/executions

请求字段
字段类型必填描述
workflow_typestringY必须为 "GenerateVideoNode"
input.promptstringY要生成的视频的文字描述
input.providerstring视频生成提供方(默认值:"veo_3_1")。请参阅下方的提供方。
input.aspect_ratiostring宽高比(默认值:"16:9")。常见值:"16:9"、"9:16"、"1:1"
input.reference_image_urlstring用于图像转视频生成的参考图像 URL
input.tail_image_urlstring用于引导最后一帧的尾帧图像 URL
input.configobject提供方专属的配置覆盖项
提供方
提供方值描述
VEO 3.1"veo_3_1"Google VEO 3.1(默认,质量最高)
VEO 3.1 Fast"veo_3_1_fast"更快的 VEO 3.1 版本
VEO 3"veo3"Google VEO 3
VEO 3 Fast"veo3_fast"更快的 VEO 3 版本
VEO 2"veo2"Google VEO 2
Kling Pro"kling_pro"Kling Pro 模型
Kling V2"kling_v2"Kling V2 模型
Sora V2"sora_v2"OpenAI Sora V2
Sora V2 Pro"sora_v2_pro"OpenAI Sora V2 Pro
Runway Gen-4"runway_gen4"Runway Gen-4
Seedance Lite"seedance_lite"Seedance Lite
Seedance Pro"seedance_pro"Seedance Pro
LTX Distilled"ltx_distilled"LTX Distilled(速度最快)
curl
curl -X POST "https://api.heygen.com/v1/workflows/executions" \
  -H "X-Api-Key: $HEYGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "workflow_type": "GenerateVideoNode",
    "input": {
      "prompt": "A drone shot flying over a coastal city at golden hour, cinematic lighting",
      "provider": "veo_3_1",
      "aspect_ratio": "16:9"
    }
  }'
TypeScript
interface GenerateVideoInput {
  prompt: string;
  provider?: string;
  aspect_ratio?: string;
  reference_image_url?: string;
  tail_image_url?: string;
  config?: Record<string, any>;
}

interface ExecuteResponse {
  data: {
    execution_id: string;
    status: "submitted";
  };
}

async function generateVideo(input: GenerateVideoInput): Promise<string> {
  const response = await fetch("https://api.heygen.com/v1/workflows/executions", {
    method: "POST",
    headers: {
      "X-Api-Key": process.env.HEYGEN_API_KEY!,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      workflow_type: "GenerateVideoNode",
      input,
    }),
  });

  const json: ExecuteResponse = await response.json();
  return json.data.execution_id;
}
Python
import requests
import os

def generate_video(
    prompt: str,
    provider: str = "veo_3_1",
    aspect_ratio: str = "16:9",
    reference_image_url: str | None = None,
    tail_image_url: str | None = None,
) -> str:
    payload = {
        "workflow_type": "GenerateVideoNode",
        "input": {
            "prompt": prompt,
            "provider": provider,
            "aspect_ratio": aspect_ratio,
        },
    }

    if reference_image_url:
        payload["input"]["reference_image_url"] = reference_image_url
    if tail_image_url:
        payload["input"]["tail_image_url"] = tail_image_url

    response = requests.post(
        "https://api.heygen.com/v1/workflows/executions",
        headers={
            "X-Api-Key": os.environ["HEYGEN_API_KEY"],
            "Content-Type": "application/json",
        },
        json=payload,
    )

    data = response.json()
    return data["data"]["execution_id"]
响应格式
{
  "data": {
    "execution_id": "node-gw-v1d2e3o4",
    "status": "submitted"
  }
}

检查状态

端点

GET https://api.heygen.com/v1/workflows/executions/{execution_id}

curl
curl -X GET "https://api.heygen.com/v1/workflows/executions/node-gw-v1d2e3o4" \
  -H "X-Api-Key: $HEYGEN_API_KEY"
响应格式(已完成)
{
  "data": {
    "execution_id": "node-gw-v1d2e3o4",
    "status": "completed",
    "output": {
      "video": {
        "video_url": "https://resource.heygen.ai/generated/video.mp4",
        "video_id": "abc123"
      },
      "asset_id": "asset-xyz789"
    }
  }
}

轮询直至完成

async function generateVideoAndWait(
  input: GenerateVideoInput,
  maxWaitMs = 600000,
  pollIntervalMs = 10000
): Promise<{ video_url: string; video_id: string; asset_id: string }> {
  const executionId = await generateVideo(input);
  console.log(`Submitted video generation: ${executionId}`);

  const startTime = Date.now();
  while (Date.now() - startTime < maxWaitMs) {
    const response = await fetch(
      `https://api.heygen.com/v1/workflows/executions/${executionId}`,
      { headers: { "X-Api-Key": process.env.HEYGEN_API_KEY! } }
    );
    const { data } = await response.json();

    switch (data.status) {
      case "completed":
        return {
          video_url: data.output.video.video_url,
          video_id: data.output.video.video_id,
          asset_id: data.output.asset_id,
        };
      case "failed":
        throw new Error(data.error?.message || "Video generation failed");
      case "not_found":
        throw new Error("Workflow not found");
      default:
        await new Promise((r) => setTimeout(r, pollIntervalMs));
    }
  }

  throw new Error("Video generation timed out");
}

使用示例

简单的文本转视频
curl -X POST "https://api.heygen.com/v1/workflows/executions" \
  -H "X-Api-Key: $HEYGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "workflow_type": "GenerateVideoNode",
    "input": {
      "prompt": "A person walking through a sunlit park, shallow depth of field"
    }
  }'
图像转视频
{
  "workflow_type": "GenerateVideoNode",
  "input": {
    "prompt": "Animate this product photo with a slow zoom and soft particle effects",
    "reference_image_url": "https://example.com/product-photo.png",
    "provider": "kling_pro"
  }
}
适用于社交媒体的竖屏格式
{
  "workflow_type": "GenerateVideoNode",
  "input": {
    "prompt": "A trendy coffee shop interior, camera slowly panning across the counter",
    "aspect_ratio": "9:16",
    "provider": "veo_3_1"
  }
}
使用 LTX 快速生成
{
  "workflow_type": "GenerateVideoNode",
  "input": {
    "prompt": "Abstract colorful shapes morphing and flowing",
    "provider": "ltx_distilled"
  }
}

最佳实践

  1. 在提示词中提供详细描述 — 包括摄像机运动、灯光、风格和氛围细节
  2. 当设置了 FAL_KEY 时,电影感和动作为主的内容默认使用 Seedance 2.0(通过 seedance_video) — 支持单次生成同步音频、多镜头、唇形同步和导演级运镜。用户明确希望采用 Google 或 OpenAI 的动作角色表现时,使用 VEO 3.1 / Sora V2 Pro;仅在速度是硬性要求时才使用 ltx_distilled 或 veo3_fast
  3. 使用参考图像进行图像转视频生成 — 非常适合为产品照片或静态图像添加动画
  4. 视频生成是最慢的工作流 — 最多预留 5 分钟,每 10 秒轮询一次
  5. 宽高比很重要 — 社交媒体快拍/短视频使用 9:16,横屏使用 16:9,正方形使用 1:1
  6. 输出包含 asset_id — 使用它在其他 HeyGen 工作流中引用生成的视频
  7. 输出 URL 是临时的 — 请及时下载或保存生成的视频

评论

支持 Markdown