Google Veo 视频生成技能手册

杰哥 AI TEAM 2026年3月20日 阅读 5 分钟

核心定位

Google Veo 是 Google DeepMind 推出的新一代 AI 视频生成模型,支持**文生视频(Text-to-Video)图生视频(Image-to-Video)**功能。输入文本提示词或图片,生成高质量、高分辨率的动态视频片段。

API 信息

  • 模型名称: veo-3.1-generate-preview
  • API Endpoint: https://generativelanguage.googleapis.com/v1beta/models/veo-3.1-generate-preview
  • API Key: GEMINI_API_KEY (存储在 .env.local)

环境配置

API Key 配置

在项目根目录 .env.local 文件中添加:

GEMINI_API_KEY=your_gemini_api_key_here

获取 API Key

  1. 访问 Google AI Studio
  2. 创建或获取 API Key
  3. 将 Key 添加到 .env.local 文件

⭐ 重要:API 流程

Veo API 采用异步长时运行任务模式,需要三步操作:

1. 创建任务 → 获得 operation name

2. 轮询状态 → 等待 done: true

3. 下载视频 → 使用 video_uri

快速开始

1. 生成视频(创建任务)

# 文生视频
curl -X POST \
  "https://generativelanguage.googleapis.com/v1beta/models/veo-3.1-generate-preview:predictLongRunning?key=$GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "instances": [
      {
        "prompt": "A cinematic aerial shot of a futuristic city at sunset, with flying cars and neon lights"
      }
    ],
    "parameters": {
      "sampleCount": 1,
      "aspectRatio": "16:9"
    }
  }'

响应示例:

{
  "name": "operations/veo-1234567890"
}

2. 查询任务状态(轮询)

OPERATION_NAME="operations/veo-1234567890"

curl -X GET \
  "https://generativelanguage.googleapis.com/v1beta/$OPERATION_NAME?key=$GEMINI_API_KEY"

3. 下载视频

VIDEO_URI="https://generativelanguage.googleapis.com/v1beta/files/abc123:download?alt=media"

curl -L -o output.mp4 "$VIDEO_URI&key=$GEMINI_API_KEY"

参数说明

参数类型默认值说明
promptstring-文本提示词,描述想要生成的视频内容
image.bytesBase64Encodedstring-Base64 编码的图片(图生视频模式)
sampleCountnumber1生成的视频数量(1-4)
aspectRatiostring”16:9”视频比例:16:9 / 9:16 / 1:1

Prompt 编写技巧

# 高质量 Prompt 模板
"[镜头运动], [主体描述], [环境氛围], [光影效果]"

# 示例:电影级航拍
"A cinematic drone shot flying over a misty mountain range at sunrise, golden light streaming through clouds"

# 示例:人物特写
"Close-up of a woman smiling, hair gently moving in the breeze, soft natural lighting"

# 示例:产品展示
"Product rotation on a white background, smooth lighting, professional commercial style"

适用场景

场景Prompt 建议
电影航拍A cinematic drone shot flying over [scene], golden hour lighting
产品展示Product rotation on clean background, smooth professional lighting
人物动画Close-up of person [action], soft natural lighting, subtle movement
风景动态Time-lapse of [scene], clouds moving, light changing from dawn to dusk
抽象艺术Abstract [concept], flowing colors, morphing shapes
社交媒体使用 9:16 竖屏比例,适合抖音/小红书

注意事项

  1. API Key 安全:不要将 API Key 硬编码在代码中
  2. 生成时间:视频生成通常需要 1-5 分钟
  3. 配额限制:Veo API 有每日请求限制
  4. 视频下载:使用 -L 参数跟随重定向,视频 URI 有效期有限

相关文档