Veo 3.0 & Veo 3.1视频生成
模型简介
Veo 系列是 Google 推出的新一代视频生成模型。该系列包含不同优化方向的模型,兼顾生成质量与速度,支持从文本、图片生成高质量视频内容。
核心特点
- 强大的视频生成能力: 能够生成长达数分钟的高分辨率视频,理解复杂的场景描述和动态动作,支持多种艺术风格和视觉特效
- 异步处理模式: 使用返回的任务ID进行查询
- 时效性: 生成的视频链接有效期为24小时,请尽快保存
API 端点
POST https://api.exchangetoken.ai/v1beta/models/veo-3.1-generate-preview:predictLongRunning模型版本选择
Veo 3.1 是 Google 最先进的模型,可生成高保真 8 秒 720p、1080p 的视频,具有惊人的逼真效果和原生生成的音频。您可以使用 Gemini API 以编程方式访问此模型。
Veo 3.1 系列 (推荐)
veo-3.1-generate-001
- 旗舰画质版: 提供目前最高水准的视频生成质量,适合对细节要求极高的生产环境
veo-3.1-fast-generate-001
- 极速预览版: 优化了生成速度,在保持较高画质的同时大幅降低延迟,适合快速原型开发
Veo 3.0 系列 (上一代)
veo-3.0-generate-001
- 标准版: 上一代稳定模型,平衡了质量与速度
veo-3.0-fast-generate-001
- 快速版: 上一代低延迟模型
建议: 新项目请优先使用 Veo 3.1 系列模型以获得最佳体验。
Veo 3.1 核心特性
Veo 3.1 擅长各种视觉和电影风格,并引入了多项新功能:
- 竖屏视频: 选择横屏 (
16:9) 视频或竖屏 (9:16) 视频 - 视频扩展: 扩展之前使用 Veo 生成的视频
- 指定帧生成: 通过指定第一帧和/或最后一帧来生成视频
- 基于图片的指导: 使用参考图片来指导生成的视频的内容
文本到视频
功能说明
了解如何生成从文字到视频,且包含对话的优质视频。代码中已包含处理异步操作。
Python 示例 - 对话和音效
python
import time
from google import genai
from google.genai import types
client = genai.Client(
http_options={
'base_url': 'https://api.exchangetoken.ai'
},
api_key='sk-xxx' # 替换为您的 API Key
)
prompt = """A close up of two people staring at a cryptic drawing on a wall, torchlight flickering.
A man murmurs, 'This must be it. That's the secret code.' The woman looks at him and whispering excitedly, 'What did you find?'"""
operation = client.models.generate_videos(
model="veo-3.1-fast-generate-001",
prompt=prompt,
config=types.GenerateVideosConfig(
number_of_videos=1,
resolution="1080p",
duration_seconds=4,
),
)
while not operation.done:
print("Waiting for video generation to complete...")
time.sleep(10)
operation = client.operations.get(operation)
if operation.error:
print(f"Task Failed with Error: {operation.error}")
else:
generated_video = operation.response.generated_videos[0]
client.files.download(file=generated_video.video)
generated_video.video.save("dialogue_example.mp4")
print("Generated video saved to dialogue_example.mp4")REST API 示例 - 对话和音效
bash
#!/bin/bash
API_KEY="sk-xxxx" # 替换为您的 API Key
BASE_URL="https://api.exchangetoken.ai/v1beta"
echo "Step 1: 发送生成视频请求..."
response=$(curl -s -X POST "${BASE_URL}/models/veo-3.1-fast-generate-001:predictLongRunning" \
-H "x-goog-api-key: ${API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"instances": [{
"prompt": "A close up of two people staring at a cryptic drawing on a wall, torchlight flickering. A man murmurs, \"This must be it. That'\''s the secret code.\" The woman looks at him and whispering excitedly, \"What did you find?\""
}
]
}')
operation_name=$(echo "${response}" | jq -r .name)
if [ "${operation_name}" == "null" ] || [ -z "${operation_name}" ]; then
echo "Error: 任务提交失败!服务器响应如下:"
echo "${response}"
exit 1
fi
echo "任务提交成功,Operation Name: ${operation_name}"
echo "Step 2: 开始轮询任务状态..."
while true; do
status_response=$(curl -s -H "x-goog-api-key: ${API_KEY}" "${BASE_URL}/${operation_name}")
is_done=$(echo "${status_response}" | jq -r .done 2>/dev/null)
if [ -z "$is_done" ]; then
echo "Error: 无法解析状态响应,可能网络错误或 API Key 无效。"
echo "服务器返回: ${status_response}"
exit 1
fi
if [ "${is_done}" = "true" ]; then
echo "任务已完成!"
video_uri=$(echo "${status_response}" | jq -r '.response.generateVideoResponse.generatedSamples[0].video.uri')
if [ "${video_uri}" != "null" ]; then
echo "正在下载视频: ${video_uri}"
curl -L -o dialogue_example.mp4 -H "x-goog-api-key: ${API_KEY}" "${video_uri}"
echo "下载完成:dialogue_example.mp4"
else
echo "Error: 未找到视频 URI,可能生成失败"
echo "${status_response}"
fi
break
else
echo "任务进行中... (等待 10 秒)"
fi
sleep 10
done图片转视频
功能说明
基于输入图片生成视频内容,支持从静态图片创建动态视频,可指定动作、风格和时长。代码中已包含处理异步操作。
Python 示例 - 基础图片转视频
python
import time
from google import genai
from google.genai import types
client = genai.Client(
http_options={
'base_url': 'https://api.exchangetoken.ai'
},
api_key='sk-xxx' # 替换为您的 API Key
)
prompt = "Panning wide shot of a calico kitten sleeping in the sunshine"
# 先使用 Gemini 生成一张图片作为输入
image = client.models.generate_content(
model="gemini-2.5-flash-image",
contents=prompt,
config={"response_modalities": ['IMAGE']}
)
operation = client.models.generate_videos(
model="veo-3.1-fast-generate-001",
prompt=prompt,
image=image.parts[0].as_image(),
config=types.GenerateVideosConfig(
number_of_videos=1,
resolution="1080p",
duration_seconds=4
),
)
while not operation.done:
print("Waiting for video generation to complete...")
time.sleep(10)
operation = client.operations.get(operation)
if operation.error:
print(f"Task Failed with Error: {operation.error}")
else:
video = operation.response.generated_videos[0]
client.files.download(file=video.video)
video.video.save("veo3_with_image_input.mp4")
print("Generated video saved to veo3_with_image_input.mp4")REST API 示例 - 基础图片转视频
bash
#!/bin/bash
API_KEY="sk-xxxx" # 替换为您的 API Key
BASE_URL="https://api.exchangetoken.ai/v1beta"
IMAGE_FILE="input_image.jpg" # 替换为您的图片文件路径
if ! [ -r "$IMAGE_FILE" ]; then
echo "错误: 找不到图片文件: $IMAGE_FILE"
exit 1
fi
echo "Step 1: 正在将图片文件编码为 Base64..."
image_base64=$(base64 -i "$IMAGE_FILE" | tr -d '\n')
echo "图片编码完成。"
echo "Step 2: 发送图片转视频请求..."
response=$(curl -s -X POST "${BASE_URL}/models/veo-3.1-fast-generate-001:predictLongRunning" \
-H "x-goog-api-key: ${API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"instances": [{
"prompt": "Panning wide shot of a calico kitten sleeping in the sunshine",
"image": {
"inlineData": {
"mimeType": "image/jpeg",
"data": "'"${image_base64}"'"
}
}
}
],
"parameters": {
"resolution": "1080p",
"durationSeconds": 4
}
}')
operation_name=$(echo "${response}" | jq -r .name)
if [ "${operation_name}" == "null" ] || [ -z "${operation_name}" ]; then
echo "Error: 任务提交失败!服务器响应如下:"
echo "${response}"
exit 1
fi
echo "任务提交成功,Operation Name: ${operation_name}"
echo "Step 3: 开始轮询任务状态..."
while true; do
status_response=$(curl -s -H "x-goog-api-key: ${API_KEY}" "${BASE_URL}/${operation_name}")
is_done=$(echo "${status_response}" | jq -r .done 2>/dev/null)
if [ -z "$is_done" ]; then
echo "Error: 无法解析状态响应。"
echo "服务器返回: ${status_response}"
exit 1
fi
if [ "${is_done}" = "true" ]; then
echo "任务已完成!"
video_uri=$(echo "${status_response}" | jq -r '.response.generateVideoResponse.generatedSamples[0].video.uri')
if [ "${video_uri}" != "null" ]; then
echo "正在下载视频: ${video_uri}"
curl -L -o veo3_with_image_input.mp4 -H "x-goog-api-key: ${API_KEY}" "${video_uri}"
echo "下载完成:veo3_with_image_input.mp4"
else
echo "Error: 未找到视频 URI。"
echo "${status_response}"
fi
break
else
echo "任务进行中... (等待 10 秒)"
fi
sleep 10
done首尾帧插值
功能说明
通过指定第一帧和最后一帧图片,让Veo自动生成中间过渡帧,创建平滑的视频效果。适合制作变形动画、场景转换等效果。代码中已包含处理异步操作。
Python 示例 - 基础插值
python
import time
from google import genai
from google.genai import types
client = genai.Client(
http_options={
'base_url': 'https://api.exchangetoken.ai'
},
api_key='sk-xxx' # 替换为您的 API Key
)
prompt = """A cinematic, haunting video. A ghostly woman with long white hair
appears on a rope swing, swaying rhythmically in the eerie silence."""
# 生成首帧图片
print("Step 1: 生成首帧图片...")
first_image_result = client.models.generate_content(
model="gemini-2.5-flash-image",
contents="A ghostly woman with long white hair sitting on a rope swing in a misty forest",
config={"response_modalities": ['IMAGE']}
)
first_image = first_image_result.parts[0].as_image()
# 生成末帧图片
print("Step 2: 生成末帧图片...")
last_image_result = client.models.generate_content(
model="gemini-2.5-flash-image",
contents="An empty rope swing swaying gently in a misty forest",
config={"response_modalities": ['IMAGE']}
)
last_image = last_image_result.parts[0].as_image()
# 使用首帧和末帧生成插值视频
print("Step 3: 使用首帧和末帧生成视频 (插值)...")
operation = client.models.generate_videos(
model="veo-3.1-generate-001",
prompt=prompt,
image=first_image,
config=types.GenerateVideosConfig(
last_frame=last_image,
number_of_videos=1,
duration_seconds=8
),
)
while not operation.done:
print("Waiting for video generation to complete...")
time.sleep(10)
operation = client.operations.get(operation)
if operation.error:
print(f"Task Failed with Error: {operation.error}")
else:
video = operation.response.generated_videos[0]
client.files.download(file=video.video)
video.video.save("veo3.1_with_interpolation.mp4")
print("Generated video saved to veo3.1_with_interpolation.mp4")REST API 示例 - 基础插值
bash
#!/bin/bash
API_KEY="sk-xxxx" # 替换为您的 API Key
BASE_URL="https://api.exchangetoken.ai/v1beta"
FIRST_IMAGE="first.jpg" # 首帧图片路径
LAST_IMAGE="last.jpg" # 末帧图片路径
if ! [ -r "$FIRST_IMAGE" ]; then echo "错误: 找不到起始帧图片: $FIRST_IMAGE"; exit 1; fi
if ! [ -r "$LAST_IMAGE" ]; then echo "错误: 找不到结束帧图片: $LAST_IMAGE"; exit 1; fi
echo "Step 1: 正在将图片文件编码为 Base64..."
first_image_base64=$(base64 -i "$FIRST_IMAGE" | tr -d '\n')
last_image_base64=$(base64 -i "$LAST_IMAGE" | tr -d '\n')
echo "图片编码完成。"
echo "Step 2: 发送插值视频生成请求..."
cat <<EOF > interpolation_payload.json
{
"instances": [{
"prompt": "A cinematic, haunting video. A ghostly woman with long white hair appears on a rope swing, swaying rhythmically in the eerie silence.",
"image": { "inlineData": { "mimeType": "image/jpeg", "data": "$first_image_base64" } }
}],
"parameters": {
"aspectRatio": "16:9",
"resolution": "720p",
"durationSeconds": 8,
"lastFrame": { "inlineData": { "mimeType": "image/jpeg", "data": "$last_image_base64" } }
}
}
EOF
response=$(curl -s -X POST "${BASE_URL}/models/veo-3.1-generate-001:predictLongRunning" \
-H "x-goog-api-key: ${API_KEY}" \
-H "Content-Type: application/json" \
-d @interpolation_payload.json)
rm interpolation_payload.json
operation_name=$(echo "$response" | jq -r .name)
if [ "${operation_name}" == "null" ] || [ -z "${operation_name}" ]; then
echo "Error: 任务提交失败!"
echo "$response"
exit 1
fi
echo "任务提交成功,Operation Name: ${operation_name}"
echo "Step 3: 开始轮询任务状态..."
while true; do
status_response=$(curl -s -H "x-goog-api-key: ${API_KEY}" "${BASE_URL}/${operation_name}")
is_done=$(echo "${status_response}" | jq -r .done 2>/dev/null)
if [ -z "$is_done" ]; then
echo "Error: 无法解析状态响应。"
echo "服务器返回: ${status_response}"
exit 1
fi
if [ "${is_done}" = "true" ]; then
echo "任务已完成!"
video_uri=$(echo "${status_response}" | jq -r '.response.generateVideoResponse.generatedSamples[0].video.uri')
if [ "${video_uri}" != "null" ] && [ -n "${video_uri}" ]; then
echo "正在下载视频: ${video_uri}"
curl -L -o veo3.1_with_interpolation.mp4 -H "x-goog-api-key: ${API_KEY}" "${video_uri}"
echo "下载完成:veo3.1_with_interpolation.mp4"
else
echo "Error: 未找到视频 URI。"
echo "${status_response}"
fi
break
else
echo "任务进行中... (等待 10 秒)"
fi
sleep 10
doneVeo API 参数和规范
您可以在 API 请求中设置以下参数来控制视频生成过程。
参数列表
| 参数 | 说明 | Veo 3.1 和 Veo 3.1 Fast | Veo 3 和 Veo 3 Fast |
|---|---|---|---|
prompt | 视频的文字说明。支持音频提示。 | string | string |
negativePrompt | 描述视频中不应包含的内容的文字。 | string | string |
image | 要制作动画的初始图片。 | Image 对象 | Image 对象 |
lastFrame | 插值视频要过渡到的最终图片。必须与 image 参数搭配使用。 | Image 对象 | Image 对象 |
aspectRatio | 视频的宽高比。 | "16:9" (默认值)"9:16" | "16:9" (默认值)"9:16" |
resolution | 视频的分辨率。 | "720p" (默认)"1080p" (仅支持 8 秒时长)"4k" (仅支持 8 秒时长) | "720p" (默认)"1080p" (仅支持 8 秒时长)"4k" (仅支持 8 秒时长) |
durationSeconds | 生成的视频的时长。 | "4", "6", "8"使用扩展功能或 1080p/4k 分辨率时,必须为 "8" | "4", "6", "8"使用扩展功能或 1080p/4k 分辨率时,必须为 "8" |
personGeneration | 控制人物生成。 | 文生视频和扩展功能: "allow_all"图生视频和插帧: "allow_adult" | 文生视频: "allow_all"图生视频: "allow_adult" |
注意事项
seed参数也适用于 Veo 3 模型。它不能保证确定性,但可以略微提高确定性。- 您可以在请求中设置参数,自定义视频生成。例如,您可以指定
negativePrompt来引导模型。
许可和使用条款
请确保遵守 Google 的使用条款和服务协议。生成的视频链接有效期为24小时,请及时下载保存。
