本頁面說明如何建立及管理 Transcoder API 工作範本。
根據預設,Transcoder API 會套用名為 preset/web-hd
的預設範本,填入工作設定。建立轉碼工作時,您可以指定自己的自訂工作範本。工作設定代表您在建立工作時可自訂的許多設定。
設定 Google Cloud 專案和驗證
如果您尚未建立Google Cloud 專案和憑證,請參閱「事前準備」一節。建立工作範本
您可以在工作範本中指定各種設定。如要瞭解工作設定的一些術語和概念,請參閱 Transcoder API 總覽。
如要建立工作範本,請使用 projects.locations.jobTemplates.create
方法。以下範例使用簡單設定,建立標準定義和高畫質 .mp4
輸出檔案。如要進一步瞭解作業設定,請參閱 JobConfig
參考資料。
REST
使用任何要求資料之前,請先替換以下項目:
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
TEMPLATE_ID
:新工作範本的使用者定義 ID,用於建立範本。這個值的長度應為 4 至 63 個字元,有效字元位於規則運算式[a-zA-Z][a-zA-Z0-9_-]*
。
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobTemplates/TEMPLATE_ID", "config": { "inputs": [ { "key": "input0" } ], "editList": [ { "key": "atom0", "inputs": [ "input0" ], "startTimeOffset": "0s" } ], "elementaryStreams": [ { "videoStream": { "h264": { "widthPixels": 640, "heightPixels": 360, "frameRate": 60, "bitrateBps": 550000, "pixelFormat": "yuv420p", "rateControlMode": "vbr", "crfLevel": 21, "gopDuration": "3s", "vbvSizeBits": 550000, "vbvFullnessBits": 495000, "entropyCoder": "cabac", "profile": "high", "preset": "veryfast" } }, "key": "video-stream0" }, { "videoStream": { "h264": { "widthPixels": 1280, "heightPixels": 720, "frameRate": 60, "bitrateBps": 2500000, "pixelFormat": "yuv420p", "rateControlMode": "vbr", "crfLevel": 21, "gopDuration": "3s", "vbvSizeBits": 2500000, "vbvFullnessBits": 2250000, "entropyCoder": "cabac", "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" ] } ], "output": {} } }
gcloud
- 建立
request.json
檔案,定義工作範本欄位。以下是工作範本範例:{ "config": { "elementaryStreams": [ { "key": "video-stream0", "videoStream": { "h264": { "heightPixels": 360, "widthPixels": 640, "bitrateBps": 550000, "frameRate": 60 } } }, { "key": "video-stream1", "videoStream": { "h264": { "heightPixels": 720, "widthPixels": 1280, "bitrateBps": 2500000, "frameRate": 60 } } }, { "key": "audio-stream0", "audioStream": { "codec": "aac", "bitrateBps": 64000 } } ], "muxStreams": [ { "key": "sd", "container": "mp4", "elementaryStreams": [ "video-stream0", "audio-stream0" ] }, { "key": "hd", "container": "mp4", "elementaryStreams": [ "video-stream1", "audio-stream0" ] } ] } }
- 對
gcloud
指令進行下列替換: - TEMPLATE_ID:使用者定義的新工作範本 ID。這個值的長度應為 4 至 63 個字元,有效字元位於規則運算式
[a-zA-Z][a-zA-Z0-9_-]*
中。 - 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
- 執行下列指令:
畫面會顯示類似以下的回應:gcloud transcoder templates create TEMPLATE_ID --file="request.json" --location=LOCATION
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobTemplates/TEMPLATE_ID", "config": { "inputs": [ { "key": "input0" } ], "editList": [ { "key": "atom0", "inputs": [ "input0" ], "startTimeOffset": "0s" } ], "elementaryStreams": [ { "videoStream": { "h264": { "widthPixels": 640, "heightPixels": 360, "frameRate": 60, "bitrateBps": 550000, "pixelFormat": "yuv420p", "rateControlMode": "vbr", "crfLevel": 21, "gopDuration": "3s", "vbvSizeBits": 550000, "vbvFullnessBits": 495000, "entropyCoder": "cabac", "profile": "high", "preset": "veryfast" } }, "key": "video-stream0" }, { "videoStream": { "h264": { "widthPixels": 1280, "heightPixels": 720, "frameRate": 60, "bitrateBps": 2500000, "pixelFormat": "yuv420p", "rateControlMode": "vbr", "crfLevel": 21, "gopDuration": "3s", "vbvSizeBits": 2500000, "vbvFullnessBits": 2250000, "entropyCoder": "cabac", "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" ] } ], "output": {} } }
C#
在試用這個範例之前,請先按照C#使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API C# API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
在試用這個範例之前,請先按照Go使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Go API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
在試用這個範例之前,請先按照Java使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Java API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
在試用這個範例之前,請先按照Node.js使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Node.js API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
在試用這個範例之前,請先按照PHP使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API PHP API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
在試用這個範例之前,請先按照Python使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Python API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
在試用這個範例之前,請先按照Ruby使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Ruby API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
取得工作範本詳細資料
如要取得工作範本的詳細資料,請使用 projects.locations.jobTemplates.get
方法。
REST
使用任何要求資料之前,請先替換以下項目:
TEMPLATE_ID
:您建立的工作範本 ID。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 回應:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobTemplates/TEMPLATE_ID", "config": { "inputs": [ { "key": "input0" } ], "editList": [ { "key": "atom0", "inputs": [ "input0" ], "startTimeOffset": "0s" } ], "elementaryStreams": [ { "videoStream": { "h264": { "widthPixels": 640, "heightPixels": 360, "frameRate": 60, "bitrateBps": 550000, "pixelFormat": "yuv420p", "rateControlMode": "vbr", "crfLevel": 21, "gopDuration": "3s", "vbvSizeBits": 550000, "vbvFullnessBits": 495000, "entropyCoder": "cabac", "profile": "high", "preset": "veryfast" } }, "key": "video-stream0" }, { "videoStream": { "h264": { "widthPixels": 1280, "heightPixels": 720, "frameRate": 60, "bitrateBps": 2500000, "pixelFormat": "yuv420p", "rateControlMode": "vbr", "crfLevel": 21, "gopDuration": "3s", "vbvSizeBits": 2500000, "vbvFullnessBits": 2250000, "entropyCoder": "cabac", "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" ] } ], "output": {} } }
gcloud
- 對
gcloud
指令進行下列替換: - TEMPLATE_ID:您建立的工作範本 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
- 執行下列指令:
畫面會顯示類似以下的回應:gcloud transcoder templates describe TEMPLATE_ID --location=LOCATION
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobTemplates/TEMPLATE_ID", "config": { "inputs": [ { "key": "input0" } ], "editList": [ { "key": "atom0", "inputs": [ "input0" ], "startTimeOffset": "0s" } ], "elementaryStreams": [ { "videoStream": { "h264": { "widthPixels": 640, "heightPixels": 360, "frameRate": 60, "bitrateBps": 550000, "pixelFormat": "yuv420p", "rateControlMode": "vbr", "crfLevel": 21, "gopDuration": "3s", "vbvSizeBits": 550000, "vbvFullnessBits": 495000, "entropyCoder": "cabac", "profile": "high", "preset": "veryfast" } }, "key": "video-stream0" }, { "videoStream": { "h264": { "widthPixels": 1280, "heightPixels": 720, "frameRate": 60, "bitrateBps": 2500000, "pixelFormat": "yuv420p", "rateControlMode": "vbr", "crfLevel": 21, "gopDuration": "3s", "vbvSizeBits": 2500000, "vbvFullnessBits": 2250000, "entropyCoder": "cabac", "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" ] } ], "output": {} } }
C#
在試用這個範例之前,請先按照C#使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API C# API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
在試用這個範例之前,請先按照Go使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Go API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
在試用這個範例之前,請先按照Java使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Java API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
在試用這個範例之前,請先按照Node.js使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Node.js API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
在試用這個範例之前,請先按照PHP使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API PHP API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
在試用這個範例之前,請先按照Python使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Python API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
在試用這個範例之前,請先按照Ruby使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Ruby API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
列出工作範本
如要查看您在某個地點建立的所有工作範本,請使用 projects.locations.jobTemplates.list
方法。
REST
使用任何要求資料之前,請先替換以下項目:
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 回應:
{ "jobTemplates": [ { "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobTemplates/TEMPLATE_ID", "config": { ... } }, { "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobTemplates/my-other-template", "config": { ... } } ] }
gcloud
- 對
gcloud
指令進行下列替換: - 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
- 執行下列指令:
畫面會顯示類似以下的回應:gcloud transcoder templates list --location=LOCATION
NAME projects/PROJECT_NUMBER/locations/LOCATION/jobTemplates/TEMPLATE_ID projects/PROJECT_NUMBER/locations/LOCATION/jobTemplates/my-other-template
C#
在試用這個範例之前,請先按照C#使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API C# API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
在試用這個範例之前,請先按照Go使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Go API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
在試用這個範例之前,請先按照Java使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Java API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
在試用這個範例之前,請先按照Node.js使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Node.js API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
在試用這個範例之前,請先按照PHP使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API PHP API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
在試用這個範例之前,請先按照Python使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Python API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
在試用這個範例之前,請先按照Ruby使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Ruby API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
這項回應可能包含 nextPageToken
,可用於擷取其他結果:
{ "jobTemplates": [ ... ], "nextPageToken": "NEXT_PAGE_TOKEN" }
在下列 curl
範例中,您可以傳送另一項要求,並納入 NEXT_PAGE_TOKEN 的值,列出其他工作範本,類似於下列範例:
curl -X GET \ -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \ https://transcoder.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/jobTemplates?pageToken=NEXT_PAGE_TOKEN
如要進一步瞭解如何使用這個權杖,請參閱相關的用戶端程式庫。
刪除工作範本
如要刪除工作範本,請使用 projects.locations.jobTemplates.delete
方法。
REST
使用任何要求資料之前,請先替換以下項目:
TEMPLATE_ID
:您建立的工作範本 ID。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 回應:
{}
gcloud
- 對
gcloud
指令進行下列替換: - TEMPLATE_ID:您建立的工作範本 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
- 執行下列指令:
畫面會顯示類似以下的回應:gcloud transcoder templates delete TEMPLATE_ID --location=LOCATION
Deleted template [projects/PROJECT_ID/locations/LOCATION/jobTemplates/TEMPLATE_ID].
C#
在試用這個範例之前,請先按照C#使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API C# API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Go
在試用這個範例之前,請先按照Go使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Go API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
在試用這個範例之前,請先按照Java使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Java API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
在試用這個範例之前,請先按照Node.js使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Node.js API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
PHP
在試用這個範例之前,請先按照PHP使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API PHP API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
在試用這個範例之前,請先按照Python使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Python API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Ruby
在試用這個範例之前,請先按照Ruby使用用戶端程式庫的 Transcoder API 快速入門中的設定說明操作。詳情請參閱 Transcoder API Ruby API 參考說明文件。
如要向 Transcoder API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
後續步驟
瞭解如何建立及管理工作。