本頁說明如何在 Transcoder API 資源中新增及查看標籤。標籤是鍵/值組合,可用來整理資源。您可以為個別資源加上標籤,然後根據標籤篩選資源。標籤的相關資訊會轉送至帳單系統,因此您可以依據標籤查看帳單費用明細。
您可以在建立轉碼器 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 值區名稱。
- STORAGE_INPUT_VIDEO:Cloud Storage 值區中要轉碼的影片名稱,例如- my-vid.mp4。這個欄位應考量到您在桶中建立的任何資料夾 (例如- 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"
      }
    }
  ]
}