在 Gemini API 中使用 Veo 3.1 生成视频

如需了解视频理解,请参阅视频理解指南。

Veo 3.1 是一种用于生成 8 秒视频(720p、1080p 或 4k)的模型,可原生生成音频。您可以使用 Gemini API 以编程方式访问此模型。如需详细了解可用的 Veo 模型变体,请参阅模型版本部分。

Veo 3.1 在各种视觉和电影风格方面表现出色,并引入了多项新功能:

  • 竖屏视频:选择横屏 (16:9) 视频或竖屏 (9:16) 视频。
  • 视频扩展:扩展之前使用 Veo 生成的视频。
  • 指定帧生成:通过指定第一帧和最后一帧来生成视频。
  • 基于图片的指导:使用最多三张参考图片来指导生成的视频的内容。

如需详细了解如何编写有效的文本提示来生成视频,请参阅 Veo 提示指南

文生视频

以下示例展示了如何生成包含对话电影级真实感创意动画的视频:

对话和音效

Python

import time
from google import genai
from google.genai import types

client = genai.Client()

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-generate-preview",
    prompt=prompt,
)

# Poll the operation status until the video is ready.
while not operation.done:
    print("Waiting for video generation to complete...")
    time.sleep(10)
    operation = client.operations.get(operation)

# Download the generated video.
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")

JavaScript

import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI