Gemini API の Veo 3.1 で動画を生成する

動画理解については、動画理解ガイドをご覧ください。

Veo 3.1 は、ネイティブに生成された音声を含む 8 秒間の動画(720p、1080p、4k)を生成するモデルです。このモデルには、Gemini API を使用してプログラムでアクセスできます。使用可能な Veo モデル バリエーションの詳細については、モデルのバージョンをご覧ください。

Veo 3.1 は、幅広い視覚的および映画的なスタイルに優れており、いくつかの新機能が導入されています。

  • 縦向き動画: 横向き(16:9)と縦向き(9:16)の動画を選択します。
  • 動画の拡張: 以前に Veo を使用して生成された動画を拡張します。
  • フレーム固有の生成: 最初と最後のフレームを指定して動画を生成します。
  • 画像ベースの指示: 生成する動画の内容を示すため、参照画像を 3 枚まで使用できます。

動画生成用の効果的なテキスト プロンプトの作成方法については、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({});

const 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?'`;

let operation = await ai.models.generateVideos({
    model: "veo-3.1-generate-preview",
    prompt: prompt,
});

// Poll the operation status until the video is ready.
while (!operation.done) {
    console.log("Waiting for video generation to complete...")
    await new Promise((resolve) => setTimeout(resolve, 10000));
    operation = await ai.operations.getVideosOperation({
        operation: operation,
    });
}

// Download the generated video.
ai.files.download({
    file: operation.response.generatedVideos[0].video,
    downloadPath: "dialogue_example.mp4",
});
console.log(`Generated video saved to dialogue_example.mp4`);

Go

package main

import (
    "context"
    "log"