Google 會運用 AI 技術將內容翻譯成你偏好的語言,但可能會出錯。
分析影片中的標籤
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Video Intelligence API 可使用 LABEL_DETECTION 功能,識別影片片段中顯示的實體。這項功能可辨識物件、地點、活動、動物物種、產品等。
分析可分為以下幾類:
- 影格層級:
系統會識別每個影格中的實體並加上標籤 (每秒取樣一個影格)。
- 鏡頭層級:
系統會自動偵測每個片段 (或影片) 中的鏡頭。接著,系統會識別每個鏡頭中的實體並加上標籤。
- 片段層級:
您可以指定影片中要分析的片段,方法是設定註解的開始和結束時間偏移 (請參閱 VideoSegment)。然後在每個區段中識別並標記實體。如果未指定任何片段,系統會將整部影片視為一個片段。
為本機檔案加註
下列範例示範如何對本機檔案的影片執行標籤分析。
想要更深入瞭解?請參閱詳細的 Python 教學課程。
REST
傳送處理要求
以下說明如何將 POST 要求傳送至 videos:annotate 方法。您可以將
LabelDetectionMode
設定為鏡頭層級和/或影格層級的註解。建議使用 SHOT_AND_FRAME_MODE。其中使用的存取憑證,屬於透過 Google Cloud CLI 建立的專案服務帳戶。如需安裝 Google Cloud CLI、使用服務帳戶建立專案,以及取得存取權杖的操作說明,請參閱 Video Intelligence 快速入門導覽課程。
使用任何要求資料之前,請先替換以下項目:
- BASE64_ENCODED_CONTENT:以 Base64 編碼資料形式提供的影片。請參閱將資料轉換為 base64 的操作說明。
- PROJECT_NUMBER: Google Cloud 專案的數字 ID
HTTP 方法和網址:
POST https://videointelligence.googleapis.com/v1/videos:annotate
JSON 要求主體:
{
"inputContent": "BASE64_ENCODED_CONTENT",
"features": ["LABEL_DETECTION"],
}
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: PROJECT_NUMBER" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://videointelligence.googleapis.com/v1/videos:annotate"
PowerShell (Windows)
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://videointelligence.googleapis.com/v1/videos:annotate" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
{
"name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID"
}
如果要求成功,Video Intelligence 會傳回作業名稱。
取得結果
如要取得要求結果,您必須將 GET 要求傳送至 projects.locations.operations 資源。以下說明如何傳送這類要求。
使用任何要求資料之前,請先替換以下項目:
- OPERATION_NAME:Video Intelligence API 傳回的作業名稱。作業名稱的格式為
projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID
- PROJECT_NUMBER: Google Cloud 專案的數字 ID
HTTP 方法和網址:
GET https://videointelligence.googleapis.com/v1/OPERATION_NAME
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: PROJECT_NUMBER" \
"https://videointelligence.googleapis.com/v1/OPERATION_NAME"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://videointelligence.googleapis.com/v1/OPERATION_NAME" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID",
"metadata": {
"@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoProgress",
"annotationProgress": [
{
"progressPercent": 100,
"startTime": "2019-03-12T19:36:09.110351Z",
"updateTime": "2019-03-12T19:36:17.519069Z"
}
]
},
"done": true,
"response": {
"@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoResponse",
"annotationResults": [
{
"segmentLabelAnnotations": [
{
"entity": {
"entityId": "/m/01prls",
"description": "land vehicle",
"languageCode": "en-US"
},
"categoryEntities": [
{
"entityId": "/m/07yv9",
"description": "vehicle",
"languageCode": "en-US"
}
],
"segments": [
{
"segment": {
"startTimeOffset": "0s",
"endTimeOffset": "38.757872s"
},
"confidence": 0.6614419
}
]
},
{
"entity": {
"entityId": "/m/039jbq",
"description": "urban area",
"languageCode": "en-US"
},
"categoryEntities": [
{
"entityId": "/m/01n32",
"description": "city",
"languageCode": "en-US"
}
],
"segments": [
{
"segment": {
"startTimeOffset": "0s",
"endTimeOffset": "38.757872s"
},
"confidence": 0.92337775
}
]
},
...
為 Cloud Storage 中的檔案加註
以下範例示範如何對位於 Cloud Storage 的檔案中的影片執行標籤分析。
REST
如要進一步瞭解如何安裝及使用 Python 適用的 Video Intelligence API 用戶端程式庫,請參閱 Video Intelligence API 用戶端程式庫。
傳送處理要求
以下說明如何將 POST 要求傳送至 annotate 方法。其中使用的存取憑證,屬於透過 Google Cloud CLI 建立的專案服務帳戶。如需安裝 Google Cloud CLI、使用服務帳戶建立專案,以及取得存取權杖的操作說明,請參閱 Video Intelligence 快速入門導覽課程。
使用任何要求資料之前,請先替換以下項目:
- INPUT_URI:包含要註解檔案的 Cloud Storage bucket,包括檔案名稱。開頭必須為
gs://。
- PROJECT_NUMBER: Google Cloud 專案的數字 ID
HTTP 方法和網址:
POST https://videointelligence.googleapis.com/v1/videos:annotate
JSON 要求主體:
{
"inputUri": "INPUT_URI",
"features": ["LABEL_DETECTION"],
}
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: PROJECT_NUMBER" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://videointelligence.googleapis.com/v1/videos:annotate"
PowerShell (Windows)
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://videointelligence.googleapis.com/v1/videos:annotate" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
{
"name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID"
}
如果要求成功,Video Intelligence 會傳回作業名稱。
取得結果
如要取得要求結果,您必須將 GET 要求傳送至 projects.locations.operations 資源。以下說明如何傳送這類要求。
使用任何要求資料之前,請先替換以下項目:
- OPERATION_NAME:Video Intelligence API 傳回的作業名稱。作業名稱的格式為
projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID
- PROJECT_NUMBER: Google Cloud 專案的數字 ID
HTTP 方法和網址:
GET https://videointelligence.googleapis.com/v1/OPERATION_NAME
請展開以下其中一個選項,以傳送要求:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: PROJECT_NUMBER" \
"https://videointelligence.googleapis.com/v1/OPERATION_NAME"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://videointelligence.googleapis.com/v1/OPERATION_NAME" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
回應
{
"name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID",
"metadata": {
"@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoProgress",
"annotationProgress": [
{
"inputUri": "INPUT_URI",
"progressPercent": 100,
"startTime": "2019-11-13T19:25:56.206335Z",
"updateTime": "2019-11-13T19:26:16.215615Z"
}
]
},
"done": true,
"response": {
"@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoResponse",
"annotationResults": [
{
"inputUri": "INPUT_URI",
"segmentLabelAnnotations": [
{
"entity": {
"entityId": "/m/01vkl",
"description": "circle",
"languageCode": "en-US"
},
"categoryEntities": [
{
"entityId": "/m/016nqd",
"description": "shape",
"languageCode": "en-US"
}
],
"segments": [
{
"segment": {
"startTimeOffset": "0s",
"endTimeOffset": "16.416666s"
},
"confidence": 0.36535457
}
]
},
...
]
}
]
}
}
下載註解結果
將註解從來源複製到目標值區:(請參閱「複製檔案和物件」)
gcloud storage cp gcs_uri gs://my-bucket
注意:如果輸出 GCS URI 是由使用者提供,註解就會儲存在該 GCS URI 中。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2026-07-19 (世界標準時間)。
[null,null,["上次更新時間:2026-07-19 (世界標準時間)。"],[],[]]