您可以使用 Vertex AI 的 Veo,從生成的影片中移除物件。您提供遮罩和影片物件,然後使用文字提示描述所需輸出內容。預先發布版期間支援 Vertex AI API。支援的介面包括 Google Cloud 控制台和 Vertex AI API。
如要進一步瞭解如何撰寫有效的文字提示來生成影片,請參閱 Veo 提示指南。
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
為環境設定驗證方法。
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
Python
如要在本機開發環境中使用本頁的 Python 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
安裝 Google Cloud CLI。
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
詳情請參閱 Google Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI。
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
詳情請參閱 Google Cloud 驗證說明文件中的「Authenticate for using REST」。
從影片中移除物件
控制台
在 Google Cloud 控制台中,前往「Vertex AI Studio」>「Generate Media」頁面。
按一下「Veo」Veo。
選用:在「設定」窗格中,設定下列設定:
模型:選擇「Veo 2 預先發布版」。
顯示比例:選擇「16:9」或「9:16」。
結果數量:調整滑桿或輸入介於 1 和 4 之間的值。
影片長度:從選單中選取所需影片長度。
輸出目錄:按一下「瀏覽」,建立或選取用於儲存輸出檔案的 Cloud Storage bucket。
選用步驟:在「安全性」部分,選取下列其中一個「人物生成」設定:
允許 (僅限成人):預設值。僅生成成人或臉部。請勿生成青少年、兒童或臉部。
不允許:不要生成人物或臉孔。
選用:在「Advanced options」(進階選項) 區段中,輸入「Seed」(種子) 值,隨機生成影片。
按一下「上傳圖片或影片」。
選擇要上傳的本機影片,然後按一下「選取」。
執行下列其中一個步驟:
上傳自己的遮罩:
在電腦上建立遮罩。
按一下「上傳遮罩」。在顯示的對話方塊中,選取要上傳的遮罩。
定義遮罩:在編輯工具列中,使用遮罩工具 (masked_transitions反轉工具),指定要新增內容的區域。
方塊、 筆刷或
按一下「生成」
。
Python
安裝
pip install --upgrade google-genai
詳情請參閱 SDK 參考說明文件。
設定環境變數,透過 Vertex AI 使用 Gen AI SDK:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
REST
設定環境後,即可使用 REST 測試文字提示。下列範例會將要求傳送至發布商模型端點。
如要進一步瞭解 Veo API,請參閱 Vertex AI 上的 Veo API。
- 請使用下列指令傳送影片生成要求。這項要求會啟動長時間執行的作業,並將輸出內容儲存在您指定的 Cloud Storage bucket 中。
使用任何要求資料之前,請先替換以下項目:
-
PROJECT_ID
:您的 Google Cloud 專案 ID。 -
TEXT_PROMPT
:用於引導影片生成的文字提示。 -
MASK_STORAGE_URI
遮罩物件的 Cloud Storage 值區 URI 路徑。 -
MASK_MIME_TYPE
圖片遮罩的 MIME 類型。只能是下列其中一項:image/png
image/jpeg
image/webp
-
VIDEO_INPUT_STORAGE_URI
Cloud Storage 值區 URI 路徑影片輸入物件。 -
VIDEO_MIME_TYPE
影片物件的 MIME 類型。只能是下列其中一項:video/mov
video/mpeg
video/mp4
video/mpg
video/avi
video/wmv
video/mpegps
video/flv
-
OUTPUT_STORAGE_URI
: 選用:用於儲存輸出影片的 Cloud Storage bucket。如果未提供,回應中會傳回 Base64 位元組編碼的影片。例如:gs://video-bucket/output/
。 -
RESPONSE_COUNT
:要生成的影片檔案數量。接受的整數值:1 到 4。 -
其他選用參數
請視用途使用下列選用變數。在
"parameters": {}
物件中新增下列部分或所有參數。"parameters": { "aspectRatio": "ASPECT_RATIO", "negativePrompt": "NEGATIVE_PROMPT", "personGeneration": "PERSON_SAFETY_SETTING", // "resolution": RESOLUTION, // Veo 3 models only "sampleCount": RESPONSE_COUNT, "seed": SEED_NUMBER }
-
ASPECT_RATIO
: 選用:描述生成影片顯示比例的字串值。你可以使用下列值:"16:9"
橫向"9:16"
直向
預設值為
"16:9"
-
NEGATIVE_PROMPT
:選用:字串值,說明您要禁止模型生成哪些內容。 -
PERSON_SAFETY_SETTING
: 選用:控制生成人物或臉部安全設定的字串值。你可以使用下列值:-
"allow_adult"
:只允許生成成人人物和臉孔。 -
"disallow"
:不會生成人物或臉部。
預設值為
"allow_adult"
。 -
-
RESOLUTION
: 選用:控制生成影片解析度的字串值。僅支援 Veo 3 模型。你可以使用下列值:"720p"
"1080p"
預設值為
"720p"
。 -
RESPONSE_COUNT
: 選用。整數值,說明要生成的影片數量。 可接受的值範圍為1
到4
。 -
SEED_NUMBER
: 選用。模型用來生成確定性影片的 uint32 值。在要求中指定種子號碼,但不變更其他參數,即可引導模型生成相同的影片。可接受的值範圍為0
到4294967295
。
-
HTTP 方法和網址:
POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/veo-2.0-generate-preview:predictLongRunning
JSON 要求主體:
{ "instances": [ { "prompt": "TEXT_PROMPT", // The following fields can be repeated for up to three total // images. "mask": { "gcsURI": "MASK_STORAGE_URI", "mimeType": "MASK_MIME_TYPE", "maskMode": "remove" }, "video": { "gcsURI": "VIDEO_INPUT_STORAGE_URI", "mimeType": "VIDEO_MIME_TYPE" } } ], "parameters": { "storageUri": "OUTPUT_STORAGE_URI", "sampleCount": RESPONSE_COUNT, } }
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為
request.json
的檔案中,然後執行下列指令:curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/veo-2.0-generate-preview:predictLongRunning"PowerShell
將要求主體儲存在名為
request.json
的檔案中,然後執行下列指令:$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/veo-2.0-generate-preview:predictLongRunning" | Select-Object -Expand Content{ "name": "projects/PROJECT_ID/locations/us-central1/publishers/google/models/veo-2.0-generate-001/operations/a1b07c8e-7b5a-4aba-bb34-3e1ccb8afcc8" }
選用:檢查影片生成長時間執行作業的狀態。
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:您的 Google Cloud 專案 ID。
- MODEL_ID:要使用的模型 ID。
- OPERATION_ID:原始生成影片要求中傳回的專屬作業 ID。
HTTP 方法和網址:
POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MODEL_ID:fetchPredictOperation
JSON 要求主體:
{ "operationName": "projects/PROJECT_ID/locations/us-central1/publishers/google/models/MODEL_ID/operations/OPERATION_ID" }
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為
request.json
的檔案中,然後執行下列指令:curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MODEL_ID:fetchPredictOperation"PowerShell
將要求主體儲存在名為
request.json
的檔案中,然後執行下列指令:$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MODEL_ID:fetchPredictOperation" | Select-Object -Expand Content
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-10-19 (世界標準時間)。