核心定位
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
- 访问 Google AI Studio
- 创建或获取 API Key
- 将 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"
参数说明
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
prompt | string | - | 文本提示词,描述想要生成的视频内容 |
image.bytesBase64Encoded | string | - | Base64 编码的图片(图生视频模式) |
sampleCount | number | 1 | 生成的视频数量(1-4) |
aspectRatio | string | ”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 竖屏比例,适合抖音/小红书 |
注意事项
- API Key 安全:不要将 API Key 硬编码在代码中
- 生成时间:视频生成通常需要 1-5 分钟
- 配额限制:Veo API 有每日请求限制
- 视频下载:使用
-L参数跟随重定向,视频 URI 有效期有限