機器學習

How Smart Tools Are Shaping the Future of Creative Work

Eric Chuang
2021-06-17

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
              }
            ]
          },
         ...

Sign up for our newsletter

Subscribe to our newsletter to receive the latest updates, expert insights, and practical tips directly in your inbox. Stay informed with content designed to help you grow.

+480.000 happy customers

Gain more with expert solutions

Unlock the full potential of your business with our expert solutions. Our team provides tailored strategies, professional guidance, and actionable insights to help you achieve better results.

  • Eric Chuang
  • •
  • 2025-01-23
如何同時使用 Webinoly 與 Cloudflare 保護網站安全

在社群夥伴勇哥的文章〈Webinoly 最新版快速安裝〉中,提到使用 Webinoly 來建立 WordPre […]

主機