สร้างวิดีโอด้วย Veo 3.1 ใน Gemini API

ดูข้อมูลเกี่ยวกับการทำความเข้าใจวิดีโอได้ที่คู่มือการทำความเข้าใจวิดีโอ

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"
    "os"
    "time"

    "google.golang.org/genai"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    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.GenerateVideos(
        ctx,
        "veo-3.1-generate-preview",
        prompt,
        nil,
        nil,
    )

    // Poll the operation status until the video is ready.
    for !operation.Done {
    log.Println("Waiting for video generation to complete...")
        time.Sleep(10 * time.Second)
        operation, _ = client.Operations.GetVideosOperation(ctx, operation, nil)
    }

    // Download the generated video.
    video := operation.Response.GeneratedVideos[0]
    client.Files.Download(ctx, video.Video, nil)
    fname := "dialogue_example.mp4"
    _ = os