在 Gemini API 中使用 Veo 3 生成影片

Veo 3 是 Google 最先進的模型,可根據文字提示生成 8 秒的 720p 高畫質影片,並提供逼真的效果和原生生成的音訊。您可以使用 Gemini API,以程式輔助方式存取這個模型。Veo 3 擅長製作各種視覺和電影風格的影片,如要進一步瞭解可用的 Veo 模型變體,請參閱「模型版本」一節。

選擇範例,瞭解如何生成對話、電影寫實或創意動畫影片:

根據圖片生成影片

以下程式碼示範如何使用 Imagen 生成圖片,然後將該圖片做為起始影格,使用 Veo 3 生成影片。

Python

import time from google import genai  client = genai.Client()  prompt = "Panning wide shot of a calico kitten sleeping in the sunshine"  # Step 1: Generate an image with Imagen. imagen = client.models.generate_images(     model="imagen-3.0-generate-002",     prompt=prompt, )  # Step 2: Generate video with Veo 3 using the image. operation = client.models.generate_videos(     model="veo-3.0-generate-preview",     prompt=prompt,     image=imagen.generated_images[0].image, )  # 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 video. 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") 

JavaScript

import { GoogleGenAI } from "@google/genai";  const ai = new GoogleGenAI({});  const prompt = "Panning wide shot of a calico kitten sleeping in the sunshine";  // Step 1: Generate an image with Imagen. const imagenResponse = await ai.models.generateImages({   model: "imagen-3.0-generate-002",   prompt: prompt, });  // Step 2: Generate video with Veo 3 using the image. let operation = await ai.models.generateVideos({   model: "veo-3.0-generate-preview",   prompt: prompt,   image: {     imageBytes: imagenResponse.generatedImages[0].image.imageBytes,     mimeType: "image/png",   }, });  // 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 video. ai.files.download({     file: operation.response.generatedVideos[0].video,     downloadPath: "veo3_with_image_input.mp4", }); console.log(`Generated video saved to veo3_with_image_input.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 := "Panning wide shot of a calico kitten sleeping in the sunshine"      // Step 1: Generate an image with Imagen.     imagenResponse, err := client.Models.GenerateImages(         ctx,         "imagen-3.0-generate-002",         prompt,         nil, // GenerateImagesConfig     )     if err != nil {         log.Fatal(err)     }      // Step 2: Generate video with Veo 3 using the image.     operation, err := client.Models.GenerateVideos(         ctx,         "veo-3.0-generate-preview",         prompt,         imagenResponse.GeneratedImages[0].Image,         nil, // GenerateVideosConfig     )     if err != nil {         log.Fatal(err)     }      // 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 video.     video := operation.Response.GeneratedVideos[0]     client.Files.Download(ctx, video.Video, nil)     fname := "veo3_with_image_input.mp4"     _ = os.WriteFile(fname, video.Video.VideoBytes, 0644)     log.Printf("Generated video saved to %s\n", fname) } 

Veo API 參數和規格

您可以在 API 要求中設定這些參數,控管影片生成程序。

參數 說明 Veo 3 和 Veo 3 Fast (預先發布版) Veo 2 (穩定版)
prompt 影片的文字說明。支援音訊提示。 string string
negativePrompt 描述影片中不應包含的內容。 string string
image 要製作動畫的初始圖片。 Image 個物件 Image 個物件
aspectRatio 影片的顯示比例。 "16:9" "16:9""9:16"
personGeneration 控制人物的生成。
(如需區域限制,請參閱「限制」一節)
文字轉影片:
"allow_all" 僅限
圖片轉影片:
"allow_adult" 僅限
文字轉影片:
"allow_all""allow_adult""dont_allow"
圖片轉影片:
"allow_adult""dont_allow"

您可以在要求中設定參數,自訂影片生成方式。 舉例來說,您可以指定 negativePrompt 來引導模型。

Python

import time from google import genai from google.genai import types  client = genai.Client()  operation = client.models.generate_videos(     model="veo-3.0-generate-preview",     prompt="A cinematic shot of a majestic lion in the savannah.",     config=types.GenerateVideosConfig(negative_prompt="cartoon, drawing, low quality"), )  # 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("parameters_example.mp4") print("Generated video saved to parameters_example.mp4") 

JavaScript

import { GoogleGenAI } from "@google/genai";  const ai = new GoogleGenAI({});  let operation = await ai.models.generateVideos({   model: "veo-3.0-generate-preview",   prompt: "A cinematic shot of a majestic lion in the savannah.",   config: {     aspectRatio: "16:9",     negativePrompt: "cartoon, drawing, low quality"   }, });  // 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: "parameters_example.mp4", }); console.log(`Generated video saved to parameters_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)     }      videoConfig := &genai.GenerateVideosConfig{         AspectRatio: "16:9",         NegativePrompt: "cartoon, drawing, low quality",     }      operation, _ := client.Models.GenerateVideos(         ctx,         "veo-3.0-generate-preview",         "A cinematic shot of a majestic lion in the savannah.",         nil,         videoConfig,     )      // 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 := "parameters_example.mp4"     _ = os.WriteFile(fname, video.Video.VideoBytes, 0644)     log.Printf("Generated video saved to %s\n", fname) } 

REST

# Note: This script uses jq to parse the JSON response. # GEMINI API Base URL BASE_URL="https://generativelanguage.googleapis.com/v1beta"  # Send request to generate video and capture the operation name into a variable. operation_name=$(curl -s "${BASE_URL}/models/veo-3.0-generate-preview:predictLongRunning" \   -H "x-goog-api-key: $GEMINI_API_KEY" \   -H "Content-Type: application/json" \   -X "POST" \   -d '{     "instances": [{         "prompt": "A cinematic shot of a majestic lion in the savannah."       }     ],     "parameters": {       "aspectRatio": "16:9",       "negativePrompt": "cartoon, drawing, low quality"     }   }' | jq -r .name)  # Poll the operation status until the video is ready while true; do   # Get the full JSON status and store it in a variable.   status_response=$(curl -s -H "x-goog-api-key: $GEMINI_API_KEY" "${BASE_URL}/${operation_name}")    # Check the "done" field from the JSON stored in the variable.   is_done=$(echo "${status_response}" | jq .done)    if [ "${is_done}" = "true" ]; then     # Extract the download URI from the final response.     video_uri=$(echo "${status_response}" | jq -r '.response.generateVideoResponse.generatedSamples[0].video.uri')     echo "Downloading video from: ${video_uri}"      # Download the video using the URI and API key and follow redirects.     curl -L -o parameters_example.mp4 -H "x-goog-api-key: $GEMINI_API_KEY" "${video_uri}"     break   fi   # Wait for 5 seconds before checking again.   sleep 10 done 

處理非同步作業

生成影片需要大量運算資源,當您向 API 傳送要求時,系統會啟動長時間執行的工作,並立即傳回 operation 物件。接著,您必須輪詢,直到影片準備就緒 (以 done 狀態為 true 表示)。

這項程序的中心是輪詢迴圈,會定期檢查工作狀態。

Python

import time from google import genai from google.genai import types  client = genai.Client()  # After starting the job, you get an operation object. operation = client.models.generate_videos(     model="veo-3.0-generate-preview",     prompt="A cinematic shot of a majestic lion in the savannah.", )  # Alternatively, you can use operation.name to get the operation. operation = types.GenerateVideosOperation(name=operation.name)  # This loop checks the job status every 10 seconds. while not operation.done:     time.sleep(10)     # Refresh the operation object to get the latest status.     operation = client.operations.get(operation)  # Once done, the result is in operation.response. # ... process and download your video ... 

JavaScript

import { GoogleGenAI } from "@google/genai";  const ai = new GoogleGenAI({});  // After starting the job, you get an operation object. let operation = await ai.models.generateVideos({   model: "veo-3.0-generate-preview",   prompt: "A cinematic shot of a majestic lion in the savannah.", });  // Alternatively, you can use operation.name to get the operation. // operation = types.GenerateVideosOperation(name=operation.name)  // This loop checks the job status every 10 seconds. while (!operation.done) {     await new Promise((resolve) => setTimeout(resolve, 1000));     // Refresh the operation object to get the latest status.     operation = await ai.operations.getVideosOperation({ operation }); }  // Once done, the result is in operation.response. // ... process and download your video ... 

模型功能

功能 說明 Veo 3 和 Veo 3 Fast (預先發布版) Veo 2 (穩定版)
音訊 原生生成影片音訊。 ✔️ 一律開啟 ❌ 僅限靜音
輸入模態 用於生成的輸入類型。 文字轉影片、圖片轉影片 文字轉影片、圖片轉影片
解決方法 影片的輸出解析度。 720p 720p
影格速率 影片的輸出影格速率。 24fps 24fps
影片長度 生成的影片長度。 8 秒 5 到 8 秒
單次要求可取得的影片數量 每個要求產生的影片數量。 1 1 或 2
狀態與詳細資料 型號供應情形和詳細資訊。 預覽 穩定版

如要進一步瞭解 Veo 的使用詳情,請參閱「模型版本」一節,以及「定價」和「速率限制」頁面。

Veo 提示指南

本節提供使用 Veo 製作的影片範例,並說明如何修改提示來產生不同結果。

安全篩選機制

Veo 會在 Gemini 中套用安全篩選器,確保生成的影片和上傳的相片不含冒犯內容。系統會封鎖違反條款和規範的提示。

提示撰寫基本知識

好的提示應清楚描述想法,如要充分發揮 Veo 的功能,請先找出核心概念,然後加入關鍵字和修飾符來修正概念,並在提示中加入影片專用術語。

提示應包含下列元素:

  • 主題:影片中要出現的物體、人物、動物或風景,例如城市景觀自然車輛小狗
  • 動作:主體正在執行的動作 (例如走路跑步轉頭)。
  • 風格:使用特定電影風格關鍵字指定創意方向,例如科幻恐怖片黑色電影,或是卡通等動畫風格。
  • 攝影機位置和動作:[選用] 使用「鳥瞰」、「平視」、「俯拍」、「推軌鏡頭」或「仰角」等詞彙,控制攝影機的位置和動作。
  • 構圖:[選用] 鏡頭的取景方式,例如廣角鏡頭特寫單人鏡頭雙人鏡頭
  • 對焦和鏡頭效果:[選用] 使用「淺景深」、「深景深」、「柔焦」、「微距鏡頭」和「廣角鏡頭」等詞彙,達到特定視覺效果。
  • 氛圍:[選填] 顏色和光線對場景的影響,例如藍色調夜晚暖色調

撰寫提示的更多訣竅

  • 使用描述性語言:使用形容詞和副詞,讓 Veo 清楚瞭解你的需求。
  • 強化臉部細節:在提示中加入「肖像」等字詞,將臉部細節設為相片焦點。

如需更全面的提示策略,請參閱「提示設計簡介」一文。

提示音訊

使用 Veo 3 時,你可以提供音效、環境噪音和對話的提示。 模型會擷取這些提示的細微差異,生成同步配樂。

  • 對話:使用引號標示特定語音。(例如:「這一定是鑰匙,」他喃喃自語。)
  • 音效 (SFX):明確描述聲音。(例如:輪胎發出尖銳的摩擦聲、引擎轟隆作響)。
  • 環境噪音:描述環境的聲音。(例如:背景中傳來微弱的詭異嗡嗡聲。)

這些影片會逐步詳細說明如何提示 Veo 3 生成音訊。

提示 生成內容
更多細節 (對話和環境)
兩個人盯著牆上難以解讀的圖案,火把的光線閃爍不定。「這一定是鑰匙,」他喃喃自語,同時描繪著圖案。「但這是什麼意思?」她困惑地問道,並歪著頭。潮濕的石頭、精細的雕刻、隱藏的符號。背景中傳來微弱的詭異嗡鳴聲。
洞穴中的尋寶者。
較不詳細 (對話)
露營 (定格動畫):露營者:「我現在與大自然融為一體了!」Bear:「Nature would prefer some personal space」(Nature 喜歡個人空間)。
洞穴中的尋寶者。

請自行試用這些提示,聽聽音訊! 試用 Veo 3

使用參考圖片生成影片

透過 Veo 的圖片轉影片功能,你可以為日常物品加上動畫、讓繪畫作品活靈活現,以及為自然場景加入動態和聲音。

提示 生成內容
輸入圖片 (由 Imagen 生成)
拿著巧克力棒的兔子。
兔子要逃跑了。
輸出影片 (由 Veo 3 生成)
兔子逃跑。
兔子要逃跑了。

提示和輸出內容範例

本節提供多個提示,著重說明詳細的描述性細節如何提升每部影片的成果。

冰柱

這部影片將示範如何在提示中使用提示撰寫基本概念的元素。

提示 生成內容
特寫鏡頭 (構圖) 拍攝冰凍岩壁 (背景) 上融化的冰柱 (主體),呈現冷調藍色 (氛圍),並放大 (鏡頭移動) 畫面,維持水滴 (動作) 的特寫細節。 藍色背景上滴著水珠的冰柱。

男子講電話

這些影片會示範如何使用越來越具體的詳細資料修訂提示,讓 Veo 根據你的喜好調整輸出內容。

提示 生成內容
細節較少
:攝影機緩慢移動,特寫一名身穿綠色風衣的絕望男子。他正在撥打老式轉盤壁掛電話,電話旁有綠色霓虹燈。就像電影場景。
男子講電話。
更多詳細資料
:特寫電影鏡頭跟著一名身穿褪色綠色風衣的絕望男子,他正在撥打安裝在粗糙磚牆上的轉盤電話,牆上綠色霓虹燈散發出詭異的光芒。鏡頭拉近,顯示他下顎的緊繃感,以及臉上因努力撥打電話而顯露的絕望。淺景深效果著重於他緊皺的眉頭和黑色旋轉式電話,背景則模糊成一片霓虹色和模糊陰影,營造出緊急和孤立感。
男子講電話

雪豹

提示 生成內容
簡單提示:
一隻毛皮類似雪豹的可愛生物在冬季森林中行走,3D 卡通風格的算繪圖。
雪豹無精打采。
詳細提示:
以歡樂的卡通風格製作短片 3D 動畫場景。這隻可愛的生物有著雪豹般的皮毛、大而有神的眼睛,以及圓潤友善的體態,在充滿奇幻感的冬季森林中歡快地跳躍。場景應有圓潤的樹木,樹上覆蓋白雪,雪花緩緩飄落,溫暖的陽光穿透樹枝灑落。生物的彈跳動作和開懷笑容應傳達純粹的喜悅。使用明亮歡快的色彩和活潑的動畫,營造溫暖歡樂的氛圍。
雪豹跑得更快。

依撰寫元素分類的範例

這些範例會依據每個基本元素,說明如何調整提示。

主題和背景資訊

指定主要焦點 (主體) 和背景或環境 (脈絡)。

提示 生成內容
白色混凝土公寓大樓的建築彩現圖,具有流動的有機形狀,與茂密的綠色植物和未來元素完美融合 預留位置。
衛星漂浮在外太空,背景是月球和一些星星。 漂浮在大氣層中的衛星。

動作

指定主體執行的動作 (例如走路、跑步或轉頭)。

提示 生成內容
廣角鏡頭拍攝的畫面:一名女子在海灘上散步,夕陽西下時,她望向地平線,神情滿足放鬆。 日落美景令人驚豔。

樣式

加入關鍵字,引導生成特定美學風格的圖片 (例如超現實、復古、未來主義、黑色電影)。

提示 生成內容
黑色電影風格,一男一女走在街上,懸疑,電影感,黑白。 黑色電影風格絕對美不勝收。

攝影機移動和構圖

指定攝影機的移動方式 (主觀鏡頭、空拍、追蹤無人機視角),以及鏡頭的取景方式 (廣角、特寫、低角度)。

提示 生成內容
POV 鏡頭:復古車輛在雨中行駛,加拿大夜景,電影感。 日落美景令人驚豔。
極度特寫的眼睛,反映出城市景象。 日落美景令人驚豔。

類別

調色盤和燈光會影響情緒。你可以試試「柔和的橘色暖色調」、「自然光」、「日出」或「冷色調藍色」等詞彙。

提示 生成內容
特寫:女孩在公園裡抱著可愛的黃金獵犬幼犬,陽光灑落。 小女孩抱著小狗。
電影風格的特寫鏡頭:一名悲傷的女子在雨中搭乘公車,冷色調,悲傷的氛圍。 一名女子坐在公車上,看起來很難過。

負面提示

負面提示會指定您不希望影片中出現的元素。

  • ❌ 請勿使用「否」或「不要」等指示性用語。(例如:「沒有牆壁」)。
  • ✅ 描述您不想看見的內容。(例如:「牆面、框架」)。
提示 生成內容
不使用負面提示:
生成一段簡短的風格化動畫,內容是強風吹拂下,一棵巨大的孤立橡樹的樹葉劇烈搖曳... [truncated]
樹狀結構,內含使用字詞。
使用負面提示:
[相同提示]

負面提示:都市背景、人造結構、 黑暗、暴風雨或威脅氛圍。
樹狀結構,沒有負面字詞。

顯示比例

Veo 可讓你指定影片的顯示比例。

提示 生成內容
寬螢幕 (16:9)
:製作影片,以追蹤無人機視角拍攝 1970 年代棕櫚泉的場景,一位男士駕駛紅色敞篷車,陽光溫暖,陰影拉長。
一名男子在棕櫚泉駕駛紅色敞篷車,風格為 1970 年代。
直向 (9:16 - 僅限 Veo 2)
:在茂密的雨林中,製作影片凸顯夏威夷壯觀瀑布的流暢動態。著重於逼真的水流、細緻的樹葉和自然光線,營造寧靜的氛圍。捕捉奔騰的水流、霧氣瀰漫的氛圍,以及穿過茂密樹冠的點點陽光。使用流暢的電影運鏡,呈現瀑布和周遭環境。請盡量使用平靜寫實的語氣,讓觀眾彷彿置身於夏威夷雨林的寧靜美景。
夏威夷的雄偉瀑布,位於茂密的雨林中。

限制

  • 要求延遲時間:最短 11 秒;最長 6 分鐘 (高峰時段)。
  • 地區限制:在歐盟、英國、瑞士和中東與北非地區,personGeneration 的允許值如下:
    • Veo 3:僅支援 allow_adult
    • Veo 2:dont_allowallow_adult。預設值為 dont_allow
  • 影片保留期限:生成的影片會在伺服器上保留 2 天,之後就會移除。如要儲存本機副本,請在影片生成後的 2 天內下載。
  • 浮水印:Veo 製作的影片會使用 SynthID 加上浮水印。SynthID 是我們的工具,可辨識 AI 生成內容並加上浮水印。
  • 安全性:系統會透過安全篩選器和記憶檢查程序,降低隱私權、著作權和偏見風險。
  • 音訊錯誤:有時 Veo 3 會因為安全篩選器或音訊的其他處理問題,而無法生成影片。如果影片無法生成,系統不會向你收費。

模型版本

Veo 3 預先發布版

屬性 說明
模型代碼

Gemini API

veo-3.0-generate-preview

支援的資料類型

輸入功率

文字、圖片

輸出內容

含有音訊的影片

限制

文字輸入

1,024 個權杖

輸出影片

1

最新更新 2025 年 7 月

Veo 3 Fast 預先發布版

開發人員可使用 Veo 3 Fast 製作有聲影片,同時維持高畫質,並針對速度和商務用途進行最佳化。這項功能非常適合用於以程式輔助生成廣告的後端服務、快速對創意概念進行 A/B 測試的工具,或是需要快速製作社群媒體內容的應用程式。
屬性 說明
模型代碼

Gemini API

veo-3.0-fast-generate-preview

支援的資料類型

輸入功率

文字、圖片

輸出內容

含有音訊的影片

限制

文字輸入

1,024 個權杖

輸出影片

1

最新更新 2025 年 7 月

Veo 2

屬性 說明
模型代碼

Gemini API

veo-2.0-generate-001

支援的資料類型

輸入功率

文字、圖片

輸出內容

影片

限制

文字輸入

不適用

圖片輸入

任何解析度和顯示比例的圖片,檔案大小上限為 20 MB

輸出影片

最多 2 個

最新更新 2025 年 4 月

後續步驟