使用標籤整理資源

本頁說明如何新增及查看 Transcoder API 資源的標籤。標籤是可用來整理資源的鍵/值組合。您可以為個別資源加上標籤,並根據標籤篩選資源。標籤相關資訊會轉送到帳單系統,方便您依據標籤細分帳單費用。

您可以在建立 Transcoder API 工作和工作範本時新增標籤。如果您根據含有標籤的工作範本建立工作,該工作會含有與工作範本相同的標籤。如要覆寫工作範本中的標籤,可以直接在工作本身指定標籤。

您可以使用 REST 或 RPC API 存取標籤。Google Cloud CLI 或 Google Cloud 控制台不提供標籤。

標籤規定

套用於資源的標籤必須符合下列需求條件:

  • 每項資源可以有多個標籤,上限為 64 個。
  • 每個標籤都必須是鍵/值組合。
  • 鍵的長度至少要有 1 個字元,最多 63 個字元,且不能空白。值可以空白,長度上限為 63 個字元。
  • 鍵和值只能使用小寫字母、數字字元、底線和連字號。所有字元都必須使用 UTF-8 編碼,且可使用國際字元。
  • 標籤的鍵在單一資源中不得重複,但可讓多個資源使用相同的鍵。
  • 鍵的開頭必須是小寫字母或國際字元。

在工作中加入標籤

以下範例說明如何在建立新工作時新增標籤。例如,您可以使用標籤,表示工作將用於測試環境。標籤的鍵為 environment,值為 test。

如要建立工作,請使用 projects.locations.jobs.create 方法。

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:IAM 設定中列出的 Google Cloud 專案 ID。
  • LOCATION:工作執行位置。請使用支援的地區。
    顯示地區
    • us-central1
    • us-west1
    • us-west2
    • us-east1
    • us-east4
    • southamerica-east1
    • northamerica-northeast1
    • asia-east1
    • asia-northeast1
    • asia-northeast3
    • asia-south1
    • asia-southeast1
    • australia-southeast1
    • europe-west1
    • europe-west2
    • europe-west4
    • me-west1
    • me-central1
    • me-central2
  • STORAGE_BUCKET_NAME:您建立的 Cloud Storage bucket 名稱。
  • STORAGE_INPUT_VIDEO:Cloud Storage bucket 中要轉碼的影片名稱,例如 my-vid.mp4。這個欄位應考量您在 bucket 中建立的所有資料夾 (例如 input/my-vid.mp4)。
  • STORAGE_OUTPUT_FOLDER:要儲存編碼影片輸出內容的 Cloud Storage 資料夾名稱。

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/JOB_ID",
  "config": {
    "inputs": [
      {
        "key": "input0",
        "uri": "gs://STORAGE_BUCKET_NAME/STORAGE_INPUT_VIDEO"
      }
    ],
    "editList": [
      {
        "key": "atom0",
        "inputs": [
          "input0"
        ],
        "startTimeOffset": "0s"
      }
    ],
    "elementaryStreams": [
      {
        "videoStream": {
          "h264": {
            "widthPixels": 640,
            "heightPixels": 360,
            "frameRate": 30,
            "bitrateBps": 550000,
            "pixelFormat": "yuv420p",
            "rateControlMode": "vbr",
            "crfLevel": 21,
            "gopDuration": "3s",
            "vbvSizeBits": 550000,
            "vbvFullnessBits": 495000,
            "entropyCoder": "cabac",
            "bFrameCount": 3,
            "aqStrength": 1,
            "profile": "high",
            "preset": "veryfast"
          }
        },
        "key": "video-stream0"
      },
      {
        "videoStream": {
          "h264": {
            "widthPixels": 1280,
            "heightPixels": 720,
            "frameRate": 30,
            "bitrateBps": 2500000,
            "pixelFormat": "yuv420p",
            "rateControlMode": "vbr",
            "crfLevel": 21,
            "gopDuration": "3s",
            "vbvSizeBits": 2500000,
            "vbvFullnessBits": 2250000,
            "entropyCoder": "cabac",
            "bFrameCount": 3,
            "aqStrength": 1,
            "profile": "high",
            "preset": "veryfast"
          }
        },
        "key": "video-stream1"
      },
      {
        "audioStream": {
          "codec": "aac",
          "bitrateBps": 64000,
          "channelCount": 2,
          "channelLayout": [
            "fl",
            "fr"
          ],
          "sampleRateHertz": 48000
        },
        "key": "audio-stream0"
      }
    ],
    "muxStreams": [
      {
        "key": "sd",
        "fileName": "sd.mp4",
        "container": "mp4",
        "elementaryStreams": [
          "video-stream0",
          "audio-stream0"
        ]
      },
      {
        "key": "hd",
        "fileName": "hd.mp4",
        "container": "mp4",
        "elementaryStreams": [
          "video-stream1",
          "audio-stream0"
        ]
      },
      {
        "key": "media-sd",
        "fileName": "media-sd.ts",
        "container": "ts",
        "elementaryStreams": [
          "video-stream0",
          "audio-stream0"
        ]
      },
      {
        "key": "media-hd",
        "fileName": "media-hd.ts",
        "container": "ts",
        "elementaryStreams": [
          "video-stream1",
          "audio-stream0"
        ]
      },
      {
        "key": "video-only-sd",
        "fileName": "video-only-sd.m4s",
        "container": "fmp4",
        "elementaryStreams": [
          "video-stream0"
        ]
      },
      {
        "key": "video-only-hd",
        "fileName": "video-only-hd.m4s",
        "container": "fmp4",
        "elementaryStreams": [
          "video-stream1"
        ]
      },
      {
        "key": "audio-only",
        "fileName": "audio-only.m4s",
        "container": "fmp4",
        "elementaryStreams": [
          "audio-stream0"
        ]
      }
    ],
    "manifests": [
      {
        "fileName": "manifest.m3u8",
        "type": "HLS",
        "muxStreams": [
          "media-sd",
          "media-hd"
        ]
      },
      {
        "fileName": "manifest.mpd",
        "type": "DASH",
        "muxStreams": [
          "video-only-sd",
          "video-only-hd",
          "audio-only"
        ]
      }
    ],
    "output": {
      "uri": "gs://STORAGE_BUCKET_NAME/STORAGE_OUTPUT_FOLDER/"
    }
  },
  "state": "PENDING",
  "createTime": CREATE_TIME,
  "ttlAfterCompletionDays": 30,
  "labels": {
    "environment": "test"
  }
}

如要新增多個標籤,請以半形逗號分隔。

依標籤列出及篩選

您可以列出資源,並依標籤篩選。舉例來說,為工作新增標籤後,您可以列出特定位置的工作,並依新增的標籤篩選。下列範例會列出工作,並篩除不含 "environment": "test" 標籤的工作。

如要列出工作,請使用 projects.locations.jobs.list 方法。下列篩選器會附加至網址:?filter=labels.environment:test。

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID: Google Cloud 專案 ID。
  • LOCATION:工作的位置。請使用其中一個支援的地區。
    顯示地區
    • us-central1
    • us-west1
    • us-west2
    • us-east1
    • us-east4
    • southamerica-east1
    • northamerica-northeast1
    • asia-east1
    • asia-northeast1
    • asia-northeast3
    • asia-south1
    • asia-southeast1
    • australia-southeast1
    • europe-west1
    • europe-west2
    • europe-west4
    • me-west1
    • me-central1
    • me-central2
  • 請展開以下其中一個選項,以傳送要求:

    您應該會收到如下的 JSON 回覆:

    {
      "jobs": [
        {
          "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/MY_JOB",
          "config": {
            ....
           },
          "state": "PENDING",
          "createTime": CREATE_TIME,
          "ttlAfterCompletionDays": 30,
          "labels": {
            "environment": "test"
          }
        },
        {
          "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/MY_OTHER_JOB",
          "config": {
            ....
           },
          "state": "SUCCEEDED",
          "createTime": CREATE_TIME,
          "startTime": START_TIME,
          "endTime": END_TIME,
          "ttlAfterCompletionDays": 30,
          "labels": {
            "environment": "test"
          }
        }
      ]
    }