Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Video Intelligence 透過 REST API 的 HTTP 要求,便能協助擷取影片的中繼資料,藉此轉為可搜尋、檢索的格式。
在開始前,先啟用 Cloud Video Intelligence API,這個 Lab 已經預設開啟了。
首先,先建立 IAM 身份 quickstart,並為其建立存取金鑰。
# 取得 Project ID gcloud config list project gcloud iam service-accounts create quickstart gcloud iam service-accounts keys create key.json \ --iam-account quickstart@<你的 Project ID>.iam.gserviceaccount.com gcloud auth activate-service-account --key-file key.json gcloud auth print-access-token
先建立一個 request.json 檔案,並存入 HTTP 要求內容。
{
"inputUri":"gs://spls/gsp154/video/train.mp4",
"features": [
"LABEL_DETECTION"
]
}利用 curl 傳送要求。
curl -s -H 'Content-Type: application/json' \
-H 'Authorization: Bearer '$(gcloud auth print-access-token)'' \
'https://videointelligence.googleapis.com/v1/videos:annotate' \
-d @request.json此時 Video Intelligence API 會建立作業,回傳格式如下:
{
"name": "projects/474887704060/locations/asia-east1/operations/16366331060670521152"
}接著將上述的作業資訊複製,送出另一個 HTTP 要求。
curl -s -H 'Content-Type: application/json' \
-H 'Authorization: Bearer '$(gcloud auth print-access-token)'' \
'https://videointelligence.googleapis.com/v1/projects/474887704060/locations/asia-east1/operations/16366331060670521152'將會回傳如下的資料:
{
"name": "projects/425437283751/locations/asia-east1/operations/17938636079131796601",
"metadata": {
"@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoProgress",
"annotationProgress": [
{
"inputUri": "/spls/gsp154/video/train.mp4",
"progressPercent": 100,
"startTime": "2017-02-17T22:39:00.333942Z",
"updateTime": "2017-02-17T22:39:11.414399Z"
}
]
},
"done": true,
"response": {
"@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoResponse",
"annotationResults": [
{
"inputUri": "/spls/gsp154/video/train.mp4",
"segmentLabelAnnotations": [
{
"entity": {
"entityId": "/m/01yrx",
"languageCode": "en-US"
},
"segments": [
{
"segment": {
"startTimeOffset": "0s",
"endTimeOffset": "14.833664s"
},
"confidence": 0.98509187
}
]
},
...