

# IVS 錄製 \$1 即時串流
<a name="rt-recording"></a>

IVS 即時串流有兩種錄製選項：
+ 個別參與者錄製會將每個發布者的媒體錄製在個別檔案中。
+ 但是，複合錄製會將來自所有發布者的媒體合併為單一檢視，錄製在單一檔案中。

個別參與者錄製不會產生額外的 Amazon IVS 費用，但複合錄製會按每小時費率產生影片編碼費用。這兩種錄製選項都會產生標準 S3 儲存和請求費用。如需更多詳細資訊，請參閱 [Amazon IVS 定價](https://aws.amazon.com/ivs/pricing/)。

如需自訂程度更高的解決方案，請考慮使用開放原始碼 [IVSStageSaver](https://github.com/aws-samples/amazon-ivs-stage-recorder) 專案，作為您自己自主託管錄製服務的基礎。

## 個別參與者錄製
<a name="ind-par-rec"></a>

此選項非常適合具有單一發布者的即時串流，或需要對每個發布者進行個別錄製時 (特別是用於審核目的時)。如需更多詳細資訊，請參閱[個別參與者錄製](rt-individual-participant-recording.md)。

![\[使用個別參與者錄製將每個發布者的媒體錄製到個別檔案。\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/images/Individual_Participant_Recording.png)


## 複合錄製
<a name="comp-rec"></a>

此選項會將來自多個發布者的媒體合併為單一檢視並錄製在單一檔案中，非常適合隨選視訊體驗。如需更多詳細資訊，請參閱[複合錄製](rt-composite-recording.md)。

![\[使用伺服器端合成將階段錄製到 S3 儲存貯體。\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/images/Composite_Recording.png)


## 縮圖
<a name="thumbnails"></a>

IVS 即時串流的縮圖錄製可以同時為個別參與者錄製與合成 (多名參與者) 錄製進行設定。若要啟用或停用縮圖錄製，並調整產生縮圖的間隔：
+ 若為個別參與者錄製，請使用 `thumbnailConfiguration` 屬性。
+ 若為合成錄製，請使用 `thumbnailConfigurations` 屬性。

縮圖間隔範圍介於 1 到 86400 秒 (24 小時) 之間；根據預設，系統會停用縮圖錄製。如需詳細資訊，請參閱 [Amazon IVS 即時串流功能 API 參考](https://docs.aws.amazon.com//ivs/latest/RealTimeAPIReference/Welcome.html)。

縮圖組態包含一個 `storage` 欄位，可設定為 `SEQUENTIAL` 和/或 `LATEST`。`storage` 欄位會決定縮圖的 S3 儲存空間行為：
+ `SEQUENTIAL` 會以序列方式儲存所有縮圖。此為預設值。
+ `LATEST` 僅會儲存最近的縮圖，覆寫先前的縮圖。

如果您同時指定 `SEQUENTIAL` 和 `LATEST`，縮圖會寫入兩個不同的 S3 路徑，一個用於循序封存，另一個用於最新的縮圖。

# IVS 個別參與者錄製 \$1 即時串流
<a name="rt-individual-participant-recording"></a>

本文件說明如何搭配 IVS 即時串流使用個別參與者錄製功能。

會收取標準 S3 儲存空間和請求的成本。縮圖不會產生額外的 IVS 費用。如需詳細資訊，請參閱 [Amazon IVS 定價](https://aws.amazon.com/ivs/pricing/)。

## 簡介
<a name="ind-part-rec-introduction"></a>

個別參與者錄製允許 IVS 即時串流客戶，將 IVS 舞台發布者個別錄製到 S3 儲存貯體。啟用舞台的個別參與者錄製後，發布者開始向舞台發布內容後，就會錄製發布者內容。

**注意：**如果您要將所有舞台參與者混入一段影片中，則複合錄製功能會更為合適。如需錄製 IVS 即時串流內容的摘要，請參閱[錄製](rt-recording.md)。

![\[使用個別參與者錄製將每個發布者的媒體錄製到個別檔案。\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/images/Individual_Participant_Recording.png)


## 工作流程
<a name="ind-part-rec-workflow"></a>

![\[使用個別參與者錄製將每個發布者的媒體錄製到個別檔案的工作流程。\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/images/Workflow_Participant_Recording.png)


### 1. 建立 S3 儲存貯體
<a name="ind-part-rec-create-s3-bucket"></a>

您需要 S3 儲存貯體來寫入 VOD。如需詳細資訊，請參閱 S3 文件：[如何建立儲存貯體](https://docs.aws.amazon.com/AmazonS3/latest/userguide/creating-bucket.html)。請注意，對於個別參與者錄製，必須在與 IVS 舞台相同的 AWS 區域中建立 S3 儲存貯體。

**重要**：如果您使用現有的 S3 儲存貯體：
+ **物件擁有權**設定必須是**強制執行的儲存貯體擁有者**，或是**偏好的儲存貯體擁有者**。
+ **預設類型**設定必須是**使用 Amazon S3 受管金鑰進行伺服器端加密 (SSE-S3)**。

如需詳細資訊，請參閱 S3 文件：[controlling ownership of objects](https://docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html) 和 [protecting data with encryption](https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingEncryption.html)。

### 2. 建立 StorageConfiguration 物件
<a name="ind-part-rec-create-storageconfig-object"></a>

建立儲存貯體後呼叫 IVS 即時串流 API，以[建立 StorageConfiguration](https://docs.aws.amazon.com//ivs/latest/RealTimeAPIReference/API_CreateStorageConfiguration.html) 物件。成功建立儲存體組態後，IVS 將獲得許可，可寫入所提供 S3 儲存貯體。您可以將此 StorageConfiguration 物件重複用於多個舞台。

### 3. 建立具有參與者權杖的舞台
<a name="ind-part-rec-create-stage-with-part-tokens"></a>

現在，您需要[建立 IVS 舞台](https://docs.aws.amazon.com//ivs/latest/RealTimeAPIReference/API_CreateStage.html)，並為舞台啟用個別參與者錄製 (方式是設定 AutoParticipantRecordingConfiguration 物件)，同時為每個發布者建立參與者權杖。

以下請求會建立一個具有兩個參與者權杖並啟用個別參與者錄製的舞台。

```
POST /CreateStage HTTP/1.1
Content-type: application/json

{
   "autoParticipantRecordingConfiguration": { 
      "mediaTypes": ["AUDIO_VIDEO"],
      "storageConfigurationArn": "arn:aws:ivs:us-west-2:123456789012:storage-configuration/AbCdef1G2hij",
      "thumbnailConfiguration": {
         "recordingMode": "INTERVAL",
         "storage": ["LATEST", "SEQUENTIAL"],
         "targetIntervalSeconds": 60
      }
   },
   "name": "TestStage",
   "participantTokenConfigurations": [ 
      { 
         "capabilities": ["PUBLISH", "SUBSCRIBE"],
         "duration": 20160,
         "userId": "1"
      },
      { 
         "capabilities": ["PUBLISH", "SUBSCRIBE"],
         "duration": 20160,
         "userId": "2"
      }
   ]
}
```

### 4. 以作用中發布者身分加入此舞台
<a name="ind-part-rec-join-stage-as-active-pub"></a>

將參與者權杖分發給發布者，讓他們加入此舞台並開始[向舞台發布內容](https://docs.aws.amazon.com//ivs/latest/RealTimeUserGuide/getting-started-pub-sub.html)。

發布者加入此舞台並開始使用其中一個 [IVS 即時串流廣播 SDK](https://docs.aws.amazon.com//ivs/latest/RealTimeUserGuide/broadcast.html) 向舞台發布內容時，參與者錄製程序會自動開始，並向您傳送 [EventBridge 事件](eventbridge.md)，指出錄製已開始。(此事件為「IVS 參與者錄製狀態變更 – 錄製開始」。) 同時，參與者錄製程序會開始將 VOD 和中繼資料檔案寫入設定的 S3 儲存貯體。注意：不保證會將連線持續時間極短 (少於 5 秒) 的參與者錄製下來。

有兩種方式可以取得每個錄製的 S3 字首：
+ 接聽 EventBridge 事件：

  ```
  {
     "version": "0",
     "id": "12345678-1a23-4567-a1bc-1a2b34567890",
     "detail-type": "IVS Participant Recording State Change",
     "source": "aws.ivs",
     "account": "123456789012",
     "time": "2024-03-13T22:19:04Z",
     "region": "us-east-1",
     "resources": ["arn:aws:ivs:us-west-2:123456789012:stage/AbCdef1G2hij"],
     "detail": {
        "session_id": "st-ZyXwvu1T2s",
        "event_name": "Recording Start",
        "participant_id": "xYz1c2d3e4f",
        "recording_s3_bucket_name": "ivs-recordings",
        "recording_s3_key_prefix": "<stage_id>/<session_id>/<participant_id>/2024-01-01T12-00-55Z"
     }
  }
  ```
+ 使用 [GetParticipant](https://docs.aws.amazon.com//ivs/latest/RealTimeAPIReference/API_GetParticipant.html) API 操作：此回應包含指向參與者錄製檔案位置的 S3 儲存貯體和字首。以下是請求內容：

  ```
  POST /GetParticipant HTTP/1.1
  Content-type: application/json
  {
     "participantID": "xYz1c2d3e4f",
     "sessionId": "st-ZyXwvu1T2s",
     "stageArn": "arn:aws:ivs:us-west-2:123456789012:stage/AbCdef1G2hij"
  }
  ```

  以下是回應內容：

  ```
  Content-type: application/json
  {
     "participant": {
        ...
        "recordingS3BucketName": "ivs-recordings",
        "recordingS3Prefix": "<stage_id>/<session_id>/<participant_id>",
        "recordingState": "ACTIVE",
        ...
     }
  }
  ```

### 5. 播放 VOD
<a name="ind-part-rec-play-back-vod"></a>

錄製結束後，您可以使用 [IVS 播放器](https://debug.ivsdemos.com/?p=ivs)觀看內容。如需有關如何設定 CloudFront 分佈以進行 VOD 播放的說明，請參閱[從私有儲存貯體播放錄製的內容](https://docs.aws.amazon.com//ivs/latest/RealTimeUserGuide/rt-composite-recording.html#comp-rec-playback)。

## 純音訊錄製
<a name="ind-part-rec-audio-only-recordings"></a>

設定個別參與者錄製時，可以選擇將純音訊 HLS 區段寫入 S3 儲存貯體。若要使用此功能，請在建立舞台時選擇 `AUDIO_ONLY mediaType`：

```
POST /CreateStage HTTP/1.1
Content-type: application/json

{
   "autoParticipantRecordingConfiguration": { 
      "storageConfigurationArn": "arn:aws:ivs:us-west-2:123456789012:storage-configuration/AbCdef1G2hij",
      "mediaTypes": ["AUDIO_ONLY"],
      "thumbnailConfiguration": {
         "recordingMode": "DISABLED"
      }
   },
   "name": "TestStage",
   "participantTokenConfigurations": [ 
      { 
         "capabilities": ["PUBLISH", "SUBSCRIBE"],
         "duration": 20160,
         "userId": "1"
      },
      { 
         "capabilities": ["PUBLISH", "SUBSCRIBE"],
         "duration": 20160,
         "userId": "2"
      }
   ]
}
```

## 僅限縮圖錄製
<a name="ind-part-rec-recording-thumbnail-only"></a>

設定個別參與者錄製時，您可以選擇僅將縮圖寫入 S3 儲存貯體。若要使用此功能，請在建立階段時將 `mediaType` 設為 `NONE`。如此可確保不會有任何 HLS 區段產生；系統仍會建立縮圖並寫入您的 S3 儲存貯體。

```
POST /CreateStage HTTP/1.1
Content-type: application/json
{
   "autoParticipantRecordingConfiguration": { 
      "storageConfigurationArn": "arn:aws:ivs:us-west-2:123456789012:storage-configuration/AbCdef1G2hij",
      "mediaTypes": ["NONE"],
      "thumbnailConfiguration": {
         "recordingMode": "INTERVAL",
         "storage": ["LATEST", "SEQUENTIAL"],
         "targetIntervalSeconds": 60
      }
   },
   "name": "TestStage",
   "participantTokenConfigurations": [ 
      { 
         "capabilities": ["PUBLISH", "SUBSCRIBE"],
         "duration": 20160,
         "userId": "1"
      },
      { 
         "capabilities": ["PUBLISH", "SUBSCRIBE"],
         "duration": 20160,
         "userId": "2"
      }
   ]
}
```

## 錄製內容
<a name="ind-part-rec-recording-contents"></a>

當個別參與者錄製處於作用中狀態時，系統會開始將 HLS 影片區段、中繼資料檔案及縮圖寫入階段建立時所提供的 S3 儲存貯體。此內容可用於後續處理或作為隨需影片播放。

請注意，錄製結束後，「IVS 參與者錄製狀態會變更 – 錄製結束」事件會透過 EventBridge 傳送。建議您只在接收此事件之後播放或處理錄製的串流。如需詳細資訊，請參閱[搭配 IVS 即時串流使用 EventBridge](eventbridge.md)。

以下是即時 IVS 工作階段錄製的範例目錄結構和內容：

```
s3://mybucket/stageId/stageSessionId/participantId/timestamp
   events
      recording-started.json
      recording-ended.json
   media
      hls
	 multivariant.m3u8
         high
            playlist.m3u8
            1.mp4
      thumbnails
         high
            1.jpg
            2.jpg
      latest_thumbnail
         high
            thumb.jpg
```

`events` 資料夾包含對應於錄製事件的中繼資料檔案。JSON 中繼資料檔案會在錄製開始、成功結束或以失敗結束時產生：
+ `events/recording-started.json`
+ `events/recording-ended.json`
+ `events/recording-failed.json`

指定的 `events` 資料夾將包含 `recording-started.json` 以及 `recording-ended.json` 或 `recording-failed.json`。它們包含與錄製的工作階段及其輸出格式相關的中繼資料。JSON 的詳細資訊如下所示。

`media` 資料夾包含支援的媒體內容。`hls` 子資料夾包含錄製工作階段期間產生的所有媒體和資訊清單檔案，而且此子資料夾可以使用 IVS 播放器播放。如果已設定，`thumbnails` 和 `latest_thumbnail` 子資料夾會包含在錄製工作階段期間產生的 JPEG 縮圖媒體檔案。

## 合併分段的個別參與者錄製
<a name="ind-part-rec-merge-frag"></a>

錄製組態的 `recordingReconnectWindowSeconds` 屬性可讓您指定一段時間 (以秒計)，如果階段發布者中斷與階段之間的連線，接著重新連線，IVS 會嘗試錄製到與上一個串流工作階段相同的 S3 字首。換言之，如果發布者中斷連線後在指定的重新連線間隔內重新連線，則會將多個錄製視為單一錄製並合併在一起。

如果在 `SEQUENTIAL` 模式中啟用縮圖錄製，則縮圖也會合併在相同的 `recordingS3Prefix` 之下。合併錄製時，縮圖計數器會從先前的縮圖值 (為先前錄製寫入) 重新啟動。

**Amazon EventBridge 中的 IVS 錄製狀態變更事件：**由於 IVS 會稍待片刻以確保新的串流不啟動，所以錄製結束事件和錄製結束 JSON 中繼資料檔案至少會延遲 `recordingReconnectWindowSeconds`。

如需設定 merge-streams 功能的指示，請參閱《*開始使用 Amazon IVS 即時串流功能*》中的[步驟 2：建立具有選用參與者錄製的階段](getting-started-create-stage.md)。

### 資格
<a name="ind-part-rec-merge-frag-eligibility"></a>

若要使用相同的 S3 字首合併多個錄製，則所有錄製均必須符合特定條件：
+ 階段的 AutoParticipantRecordingConfiguration 之 `recordingReconnectWindowSeconds` 屬性值設定為大於 0。
+ 用於寫入 VOD 成品的 `StorageConfigurationArn`，對每一段錄製而言均相同。
+ 參與者離開和重新加入階段之間的秒數差異小於或等於 `recordingReconnectWindowSeconds`。

請注意，`recordingReconnectWindowSeconds` 的預設值為 0，這會停用合併。

## 同步多個參與者錄製
<a name="ind-part-rec-sync-multiple"></a>

個別參與者錄製在 HLS 播放清單中加入 `EXT-X-PROGRAM-DATE-TIME` 標籤，提供精確至毫秒的 UTC 時間戳記，可在後製處理期間同步多個參與者的錄製。

當您個別錄製多個參與者，並想建立同步合成 (例如並排或子母畫面版面配置) 時，您可以使用這些時間戳記來精準對齊錄製內容，即使參與者在不同時間加入舞台，或因網路中斷而可能畫面不連續。

每個參與者的 HLS 播放清單都包含標記下列項目的 `EXT-X-PROGRAM-DATE-TIME` 標籤：
+ 錄製的開頭 (第一個區段)。
+ 錄製期間的不連續點，例如拼接時。

這些時間戳記精確至毫秒，並使用相同時間參考在所有參與者間同步。

### 範例 HLS 播放清單
<a name="ind-part-rec-sync-multiple-hls-playlist"></a>

```
#EXTM3U
#EXT-X-VERSION:7
#EXT-X-TARGETDURATION:12
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MAP:URI="init-0.mp4"
#EXT-X-PROGRAM-DATE-TIME:2024-01-01T12:00:00.000Z
#EXTINF:3.30091,
0.mp4
#EXTINF:5.63794,
1.mp4
#EXTINF:2.74290,
2.mp4
#EXT-X-DISCONTINUITY
#EXT-X-MAP:URI="init-1.mp4"
#EXT-X-PROGRAM-DATE-TIME:2024-01-01T12:00:52.772Z
#EXTINF:2.54412,
3.mp4
#EXTINF:5.63649,
4.mp4
```

這些 `EXT-X-PROGRAM-DATE-TIME` 標籤提供第一個區段和每個不連續點的確切 UTC 時間，可與其他參與者的錄製精準同步。

### 同步工作流程
<a name="ind-part-rec-sync-multiple-workflow"></a>

若要同步多個參與者錄製，請從每個參與者的 HLS 播放清單中擷取 `EXT-X-PROGRAM-DATE-TIME` 時間戳記，並用來計算時間偏移。接著就可以使用 FFmpeg 等影片處理工具，在後製處理合成期間套用這些偏移。錄製出現不連續點時，那些時間點的時間戳記會提供必要的時間參考，在整個錄製期間持續準確同步。

注意：若為沒有後製處理的即時同步輸出，請考慮使用伺服器端合成，而不是個別參與者錄製。

## JSON 中繼資料檔案
<a name="ind-part-rec-json-metadata-files"></a>

此中繼資料為 JSON 格式。其中包含下列資訊：


| 欄位 | 類型 | 必要 | 描述 | 
| --- | --- | --- | --- | 
| `stage_arn` | string | 是 | 錄製來源舞台 ARN。 | 
| `session_id` | string | 是 | 字串，表示錄製的參與者所在舞台的 `session_id`。 | 
| `participant_id` | string | 是 | 字串，表示錄製的參與者識別碼。 | 
| `recording_started_at` | string | 有條件 | 錄製開始時，RFC 3339 UTC 時間戳記。如果 `recording_status` 為 `RECORDING_START_FAILED`，則無法使用此選項。此外，請參閱下文 `recording_ended_at` 中的備註。 | 
| `recording_ended_at` | string | 有條件 | 錄製結束時，RFC 3339 UTC 時間戳記。當 `recording_status` 為 `"RECORDING_ENDED"` 或 `"RECORDING_ENDED_WITH_FAILURE"` 時才可用。 **注意：**`recording_started_at` 和 `recording_ended_at` 是這些事件產生時的時間戳記，未必與 HLS 影片區段時間戳記完全一致。若要準確判斷錄製的持續時間，請使用 `duration_ms` 欄位。 | 
| `recording_status` | string | 是 | 錄製的狀態。有效值：`"RECORDING_STARTED"`、`"RECORDING_ENDED"`、`"RECORDING_START_FAILED"`、`"RECORDING_ENDED_WITH_FAILURE"`。 | 
| `recording_status_message` | string | 有條件 | 狀態的描述性資訊。當 `recording_status` 為 `"RECORDING_ENDED"` 或 `"RECORDING_ENDED_WITH_FAILURE"` 時才可用。 | 
| `media` | object | 是 | 包含此錄製可用媒體內容之列舉物件的物件。有效值：`"hls"`。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-individual-participant-recording.html)  | object | 是 | 說明 Apple HLS 格式輸出的列舉欄位。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-individual-participant-recording.html)  | integer | 有條件 | 錄製的 HLS 內容的持續時間，以毫秒為單位。當 `recording_status` 為 `"RECORDING_ENDED"` 或 `"RECORDING_ENDED_WITH_FAILURE"` 時才可用。如果在任何錄製完成之前發生失敗，它為 0。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-individual-participant-recording.html)  | string | 是 | 儲存 HLS 內容之 S3 字首的相對路徑。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-individual-participant-recording.html)  | string | 是 | HLS 主播放清單檔案的名稱。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-individual-participant-recording.html)  | object | 是 | 中繼資料物件的轉譯 (HLS 變體) 陣列。總是至少有一個轉譯。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-individual-participant-recording.html)  | string | 是 | 為此轉譯儲存 HLS 內容之 S3 字首的相對路徑。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-individual-participant-recording.html)  | string | 是 | 此轉譯的媒體播放清單檔案名稱。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-individual-participant-recording.html)  | object | 有條件 | 描述縮圖輸出的列舉欄位。僅當縮圖組態的 `storage` 欄位包括 `SEQUENTIAL` 時才可用 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-individual-participant-recording.html)  | string | 是 | 儲存循序縮圖內容之 S3 字首的相對路徑。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-individual-participant-recording.html)  | object | 是 | 中繼資料物件的轉譯 (縮圖變體) 陣列。總是至少有一個轉譯。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-individual-participant-recording.html)  | string | 是 | 為此轉譯儲存縮圖內容之 S3 字首的相對路徑。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-individual-participant-recording.html)  | object | 有條件 | 描述縮圖輸出的列舉欄位。僅當縮圖組態的 `storage` 欄位包括 `LATEST` 時才可用。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-individual-participant-recording.html)  | string | 是 | 儲存 `latest_thumbnail` 之 S3 字首的相對路徑。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-individual-participant-recording.html)  | object | 是 | 中繼資料物件的轉譯 (縮圖變體) 陣列。總是至少有一個轉譯。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-individual-participant-recording.html)  | string | 是 | 針對此轉譯儲存最新縮圖之 S3 字首的相對路徑。 | 
| `version` | string | 是 | 中繼資料結構描述的版本。 | 

### 範例：recording-started.json
<a name="ind-part-rec-json-ex-rec-start"></a>

```
{
   "version": "v1",
   "stage_arn": "arn:aws:ivs:us-west-2:aws_account_id:stage/AbCdef1G2hij",
   "session_id": "st-ZyXwvu1T2s",
   "participant_id": "xYz1c2d3e4f",
   "recording_started_at": "2024-03-13T13:17:17Z",
   "recording_status": "RECORDING_STARTED",
   "media": {
      "hls": {
         "path": "media/hls",
         "playlist": "multivariant.m3u8",
         "renditions": [
            {
               "path": "high",
               "playlist": "playlist.m3u8"
            }
         ]
      },
      "thumbnails": {
         "path": "media/thumbnails",
         "renditions": [
            {
               "path": "high"
            }
         ]
      },
      "latest_thumbnail": {
         "path": "media/latest_thumbnail",
         "renditions": [
            {
               "path": "high"
            }
         ]
      }
   }
}
```

### 範例：recording-ended.json
<a name="ind-part-rec-json-ex-rec-end"></a>

```
{
   "version": "v1",
   "stage_arn": "arn:aws:ivs:us-west-2:aws_account_id:stage/AbCdef1G2hij",
   "session_id": "st-ZyXwvu1T2s",
   "participant_id": "xYz1c2d3e4f",
   "recording_started_at": "2024-03-13T19:44:19Z",
   "recording_ended_at": "2024-03-13T19:55:04Z",
   "recording_status": "RECORDING_ENDED",
   "media": {
      "hls": {
         "duration_ms": 645237,
         "path": "media/hls",
         "playlist": "multivariant.m3u8",
         "renditions": [
            {
               "path": "high",
               "playlist": "playlist.m3u8"
            }
         ]
      },
      "thumbnails": {
         "path": "media/thumbnails",
         "renditions": [
            {
               "path": "high"
            }
         ]
      },
      "latest_thumbnail": {
         "path": "media/latest_thumbnail",
         "renditions": [
            {
               "path": "high"
            }
         ]
      }
   }
}
```

### 範例：recording-failed.json
<a name="ind-part-rec-json-ex-rec-failed"></a>

```
{
   "version": "v1",
   "stage_arn": "arn:aws:ivs:us-west-2:aws_account_id:stage/AbCdef1G2hij",
   "session_id": "st-ZyXwvu1T2s",
   "participant_id": "xYz1c2d3e4f",
   "recording_started_at": "2024-03-13T19:44:19Z",
   "recording_ended_at": "2024-03-13T19:55:04Z",
   "recording_status": "RECORDING_ENDED_WITH_FAILURE",
   "media": {
      "hls": {
         "duration_ms": 645237,
         "path": "media/hls",
         "playlist": "multivariant.m3u8",
         "renditions": [
            {
               "path": "high",
               "playlist": "playlist.m3u8"
            }
         ]
      },
      "thumbnails": {
         "path": "media/thumbnails",
         "renditions": [
            {
               "path": "high"
            }
         ]
      },
      "latest_thumbnail": {
         "path": "media/latest_thumbnail",
         "renditions": [
            {
               "path": "high"
            }
         ]
      }
   }
}
```

## 將錄製轉換為 MP4
<a name="ind-part-rec-convert-rec-mp4"></a>

個別參與者錄製會以 HLS 格式儲存，包含播放清單和分段的 MP4 (fMP4) 區段。若要將 HLS 錄製轉換為單一 MP4 檔案，請安裝 FFmpeg 並執行下列命令：

```
ffmpeg -i /path/to/playlist.m3u8 -i /path/to/playlist.m3u8 -map 0:v -map 1:a -c copy output.mp4
```

# IVS 複合錄製 \$1 即時串流
<a name="rt-composite-recording"></a>

本文件說明如何在[伺服器端合成](server-side-composition.md)中使用複合錄製功能。複合錄製可讓您產生 IVS 階段的 HLS 錄製檔，方法是使用 IVS 伺服器將所有階段發布者有效地合併至一個檢視，然後將產生的影片儲存到 S3 儲存貯體。

會收取標準 S3 儲存空間和請求的成本。縮圖不會產生額外的 IVS 費用。如需詳細資訊，請參閱 [Amazon IVS 定價](https://aws.amazon.com/ivs/pricing/)。

## 必要條件
<a name="comp-rec-prerequisites"></a>

若要使用複合錄製，您必須具有包含作用中發布者的舞台，並使用 S3 儲存貯體作為錄製目的地。下面我們描述了一種使用 EventBridge 事件將合成錄製到 S3 儲存貯體的可能工作流程。您也可以根據自己的應用程式邏輯啟動和停止合成。

1. 為每個發布者建立 [IVS 階段](getting-started-create-stage.md)和參與者權杖。

1. 建立一個 [EncoderConfiguration](https://docs.aws.amazon.com/ivs/latest/RealTimeAPIReference/API_CreateEncoderConfiguration.html) (此物件表示應如何轉譯錄製的影片)。

1. 建立 [S3 儲存貯體](https://docs.aws.amazon.com/AmazonS3/latest/userguide/creating-bucket.html)和 [StorageConfiguration](https://docs.aws.amazon.com//ivs/latest/RealTimeAPIReference/API_CreateStorageConfiguration.html) (錄製內容的儲存位置)。

   **重要事項**：如果您使用現有的 S3 儲存貯體，則**物件擁有權**設定必須是**強制執行的儲存貯體擁有者**，或是**偏好的儲存貯體擁有者**。如需詳細資訊，請參閱 S3 文件：[控制物件擁有權](https://docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html)。

1. [加入並發布到階段](getting-started-pub-sub.md)。

1. 當您收到參與者已發布的 [EventBridge 事件](eventbridge.md)時，請呼叫以 S3 DestinationConfiguration 物件為目的地的 [StartComposition](https://docs.aws.amazon.com//ivs/latest/RealTimeAPIReference/API_StartComposition.html)

1. 幾秒鐘後，您應該能看到 HLS 片段已被保留在 S3 儲存貯體中。

![\[使用伺服器端合成將階段錄製到 S3 儲存貯體。\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/images/Composite_Recording_Workflow.png)


**注意**：在階段上的發布者參與者閒置 60 秒後，合成會執行自動關閉。此時，合成會終止並轉換為 `STOPPED` 狀態。合成會在保持 `STOPPED` 狀態幾分鐘後自動刪除。如需詳細資訊，請參閱「伺服器端合成」中的[合成生命週期](ssc-overview.md#ssc-composition-endpoint)。**

## 複合錄製範例：以 S3 儲存貯體為目的地的 StartComposition
<a name="comp-rec-example"></a>

下列範例顯示對 [StartComposition](https://docs.aws.amazon.com//ivs/latest/RealTimeAPIReference/API_StartComposition.html) 操作的典型呼叫，並將 S3 指定為合成的唯一目的地。只要合成變更為 `ACTIVE` 狀態，影片片段和中繼資料就會開始寫入 `storageConfiguration` 物件指定的 S3 儲存貯體。若要建立具有不同配置的合成，請參閱[伺服器端合成](ssc-overview.md#ssc-api-layouts)中的「版面配置」和 [IVS Real-Time Streaming API Reference](https://docs.aws.amazon.com//ivs/latest/RealTimeAPIReference/API_LayoutConfiguration.html)。

### 請求
<a name="comp-rec-example-request"></a>

```
POST /StartComposition HTTP/1.1
Content-type: application/json

{
   "destinations": [
      {
         "s3": {
            "encoderConfigurationArns": [
              "arn:aws:ivs:ap-northeast-1:927810967299:encoder-configuration/PAAwglkRtjge"
            ],
            "storageConfigurationArn": "arn:aws:ivs:ap-northeast-1:927810967299:storage-configuration/ZBcEbgbE24Cq",
	    "thumbnailConfigurations": [
	       {
		  "storage": ["LATEST", "SEQUENTIAL"],
		  "targetIntervalSeconds": 30
               }
	    ]
	 }
      }
   ],
   "idempotencyToken": "db1i782f1g9",
   "stageArn": "arn:aws:ivs:ap-northeast-1:927810967299:stage/WyGkzNFGwiwr"
}
```

### 回應
<a name="comp-rec-example-response"></a>

```
{
    "composition": {
        "arn": "arn:aws:ivs:ap-northeast-1:927810967299:composition/s2AdaGUbvQgp",
        "destinations": [
            {
                "configuration": {
                    "name": "",
                    "s3": {
                        "encoderConfigurationArns": [
                            "arn:aws:ivs:ap-northeast-1:927810967299:encoder-configuration/PAAwglkRtjge"
                        ],
                        "recordingConfiguration": {
                            "format": "HLS"
                        },
                        "storageConfigurationArn": "arn:aws:ivs:ap-northeast-1:927810967299:storage-configuration/ZBcEbgbE24Cq",
	                "thumbnailConfigurations": [
	                   {
		              "storage": ["LATEST", "SEQUENTIAL"],
		              "targetIntervalSeconds": 30
                           }
	                ]
                    }
                },
                "detail": {
                    "s3": {
                        "recordingPrefix": "MNALAcH9j2EJ/s2AdaGUbvQgp/2pBRKrNgX1ff/composite"
                    }
                },
                "id": "2pBRKrNgX1ff",
                "state": "STARTING"
            }
        ],
        "layout": null,
        "stageArn": "arn:aws:ivs:ap-northeast-1:927810967299:stage/WyGkzNFGwiwr",
        "startTime": "2023-11-01T06:25:37Z",
        "state": "STARTING",
        "tags": {}
    }
}
```

出現在 StartComposition 回應中的 `recordingPrefix` 欄位可用來決定複製內容的儲存位置。

## 錄製內容
<a name="comp-rec-contents"></a>

當合成轉換為 `ACTIVE` 狀態時，系統會開始將 HLS 影片區段、中繼資料檔案和縮圖 (若已設定) 寫入 StartComposition 呼叫期間指定的 S3 儲存貯體。此內容可用於後續處理或作為隨需影片播放。

請注意，合成上線之後，即會發出「IVS 合成狀態變更」事件，並且可能需要一點時間才能寫入資訊清單檔案、影片片段及縮圖。建議您只在收到「IVS 合成狀態變更 (工作階段結束)」事件之後，才播放或處理錄製的串流。如需詳細資訊，請參閱[搭配 IVS 即時串流使用 EventBridge](eventbridge.md)。

以下是即時 IVS 工作階段錄製的範例目錄結構和內容：

```
MNALAcH9j2EJ/s2AdaGUbvQgp/2pBRKrNgX1ff/composite
   events
      recording-started.json
      recording-ended.json
   media
      hls
      thumbnails
      latest_thumbnail
```

`events` 資料夾包含對應於錄製事件的中繼資料檔案。JSON 中繼資料檔案會在錄製開始、成功結束或以失敗結束時產生：
+ `events/recording-started.json`
+ `events/recording-ended.json`
+ `events/recording-failed.json`

指定的 `events` 資料夾將包含 `recording-started.json` 以及 `recording-ended.json` 或 `recording-failed.json`。

它們包含與錄製的工作階段及其輸出格式相關的中繼資料。JSON 的詳細資訊如下所示。

`media` 資料夾包含支援的媒體內容。`hls` 子資料夾包含合成工作階段期間產生的所有媒體和清單檔案，並且可以使用 IVS 播放器播放。HLS 清單檔案位於 `multivariant.m3u8` 資料夾中。如果已設定，`thumbnails` 和 `latest_thumbnail` 子資料夾會包含在合成工作階段期間產生的 JPEG 縮圖媒體檔案。

## StorageConfiguration 的儲存貯體政策
<a name="comp-rec-bucket-policy"></a>

建立 StorageConfiguration 物件時，IVS 會取得將內容寫入指定 S3 儲存貯體的存取權。該存取權透過修改 S3 儲存貯體的政策來授予。*如果以移除 IVS 存取權的方式變更儲存貯體的政策，則進行中和新的錄製將會失敗。*

以下範例顯示允許 IVS 寫入 S3 儲存貯體的 S3 儲存貯體政策：

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "CompositeWrite-y1d212y",
            "Effect": "Allow",
            "Principal": {
                "Service": "ivs-composite.ap-northeast-1.amazonaws.com"
            },
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": "arn:aws:s3:::my-s3-bucket/*",
            "Condition": {
                "StringEquals": {
                    "s3:x-amz-acl": "bucket-owner-full-control"
                },
                "Bool": {
                    "aws:SecureTransport": "true"
                }
            }
        }
    ]
}
```

------

## JSON 中繼資料檔案
<a name="comp-rec-json"></a>

此中繼資料為 JSON 格式。其中包含下列資訊：


| 欄位 | 類型 | 必要 | 描述 | 
| --- | --- | --- | --- | 
| `stage_arn` | string | 是 | 作為合成來源而使用的階段 ARN。 | 
| `media` | object | 是 | 包含此錄製可用媒體內容之列舉物件的物件。有效值：`"hls"`。  | 
| [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html) | object | 是 | 說明 Apple HLS 格式輸出的列舉欄位。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | integer | 有條件 | 錄製的 HLS 內容的持續時間，以毫秒為單位。當 `recording_status` 為 `"RECORDING_ENDED"` 或 `"RECORDING_ENDED_WITH_FAILURE"` 時才可用。如果在任何錄製完成之前發生失敗，它為 0。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | string | 是 | 儲存 HLS 內容之 S3 字首的相對路徑。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | string | 是 |  HLS 主播放清單檔案的名稱。  | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | object | 是 | 中繼資料物件的轉譯 (HLS 變體) 陣列。總是至少有一個轉譯。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | string | 是 | 為此轉譯儲存 HLS 內容之 S3 字首的相對路徑。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | string | 是 | 此轉譯的媒體播放清單檔案名稱。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | int | 有條件 | 編碼影片的像素解析度高度。轉譯包含影片軌道時才可用。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | int | 有條件 | 編碼影片的像素解析度寬度。轉譯包含影片軌道時才可用。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | object | 有條件 | 描述縮圖輸出的列舉欄位。僅當縮圖組態的 `storage` 欄位包括 `SEQUENTIAL` 時才可用 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | string | 是 | 儲存循序縮圖內容之 S3 字首的相對路徑。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | object | 是 | 中繼資料物件的解析度 (縮圖變體) 陣列。一律至少會有一種解析度。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | string | 是 | 針對此解析度儲存縮圖內容之 S3 字首的相對路徑。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | int | 是 | 縮圖的像素解析度高度。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | int | 是 | 縮圖的像素解析度寬度。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | object | 有條件 | 描述縮圖輸出的列舉欄位。僅當縮圖組態的 `storage` 欄位包括 `LATEST` 時才可用。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | string | 是 | 儲存 `latest_thumbnail` 之 S3 字首的相對路徑。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | object | 是 | 中繼資料物件的解析度 (縮圖變體) 陣列。一律至少會有一種解析度。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | string | 是 | 針對此解析度儲存最新縮圖之 S3 字首的相對路徑。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | int | 是 | 最新縮圖的像素解析度高度。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | int | 是 | 最新縮圖的像素解析度寬度。 | 
| `recording_ended_at` | string | 有條件 | 錄製結束時，RFC 3339 UTC 時間戳記。當 `recording_status` 為 `"RECORDING_ENDED"` 或 `"RECORDING_ENDED_WITH_FAILURE"` 時才可用。 `recording_started_at` 和 `recording_ended_at` 是這些事件生成時的時間戳記，未必與 HLS 影片區段時間戳記完全相符。若要準確判斷錄製的持續時間，請使用 `duration_ms` 欄位。  | 
| `recording_started_at` | string | 有條件 | 錄製開始時，RFC 3339 UTC 時間戳記。如果 `recording_status` 為 `RECORDING_START_FAILED`，則無法使用此選項。 請參閱上面的 `recording_ended_at` 備註。  | 
| `recording_status` | string | 是 | 錄製的狀態。有效值：`"RECORDING_STARTED"`、`"RECORDING_ENDED"`、`"RECORDING_START_FAILED"`、`"RECORDING_ENDED_WITH_FAILURE"`。 | 
| `recording_status_message` | string | 有條件 | 狀態的描述性資訊。當 `recording_status` 為 `"RECORDING_ENDED"` 或 `"RECORDING_ENDED_WITH_FAILURE"` 時才可用。 | 
| `version` | string | 是 | 中繼資料結構描述的版本。 | 

### 範例：recording-started.json
<a name="comp-rec-json-ex-rec-start"></a>

```
{
  "version": "v1",
  "stage_arn": "arn:aws:ivs:ap-northeast-1:123456789012:stage/aAbBcCdDeE12",
  "recording_started_at": "2023-11-01T06:01:36Z",
  "recording_status": "RECORDING_STARTED",
  "media": {
    "hls": {
      "path": "media/hls",
      "playlist": "multivariant.m3u8",
      "renditions": [
        {
          "path": "720p30-abcdeABCDE12",
          "playlist": "playlist.m3u8",
          "resolution_width": 1280,
          "resolution_height": 720
        }
      ]
    },
    "thumbnails": {
      "path": "media/thumbnails",
      "resolutions": [
        {
          "path": "1280x720",
          "resolution_width": 1280,
          "resolution_height": 720
        }
      ]
    },
    "latest_thumbnail": {
      "path": "media/latest_thumbnail",
      "resolutions": [
        {
          "path": "1280x720",
          "resolution_width": 1280,
          "resolution_height": 720
        }
      ]
    }
  }
}
```

### 範例：recording-ended.json
<a name="comp-rec-json-ex-rec-end"></a>

```
{
  "version": "v1",
  "stage_arn": "arn:aws:ivs:ap-northeast-1:123456789012:stage/aAbBcCdDeE12",
  "recording_started_at": "2023-10-27T17:00:44Z",
  "recording_ended_at": "2023-10-27T17:08:24Z",
  "recording_status": "RECORDING_ENDED",
  "media": {
    "hls": {
      "duration_ms": 460315,
      "path": "media/hls",
      "playlist": "multivariant.m3u8",
      "renditions": [
        {
          "path": "720p30-abcdeABCDE12",
          "playlist": "playlist.m3u8",
          "resolution_width": 1280,
          "resolution_height": 720
        }
      ]
    },
    "thumbnails": {
      "path": "media/thumbnails",
      "resolutions": [
        {
          "path": "1280x720",
          "resolution_width": 1280,
          "resolution_height": 720
        }
      ]
    },
    "latest_thumbnail": {
      "path": "media/latest_thumbnail",
      "resolutions": [
        {
          "path": "1280x720",
          "resolution_width": 1280,
          "resolution_height": 720
        }
      ]
    }
  }
}
```

### 範例：recording-failed.json
<a name="comp-rec-json-ex-rec-fail"></a>

```
{
  "version": "v1",
  "stage_arn": "arn:aws:ivs:ap-northeast-1:123456789012:stage/aAbBcCdDeE12",
  "recording_started_at": "2023-10-27T17:00:44Z",
  "recording_ended_at": "2023-10-27T17:08:24Z",
  "recording_status": "RECORDING_ENDED_WITH_FAILURE",
  "media": {
    "hls": {
      "duration_ms": 460315,
      "path": "media/hls",
      "playlist": "multivariant.m3u8",
      "renditions": [
        {
          "path": "720p30-abcdeABCDE12",
          "playlist": "playlist.m3u8",
          "resolution_width": 1280,
          "resolution_height": 720
        }
      ]
    },
    "thumbnails": {
      "path": "media/thumbnails",
      "resolutions": [
        {
          "path": "1280x720",
          "resolution_width": 1280,
          "resolution_height": 720
        }
      ]
    },
    "latest_thumbnail": {
      "path": "media/latest_thumbnail",
      "resolutions": [
        {
          "path": "1280x720",
          "resolution_width": 1280,
          "resolution_height": 720
        }
      ]
    }
  }
}
```

## 從私人儲存貯體播放錄製的內容
<a name="comp-rec-playback"></a>

預設情況下，錄製內容為私有；因此，直接使用 S3 URL 無法存取這些物件。如果您嘗試使用 IVS 播放器或其他播放器開啟 HLS 多重變數播放清單 (m3u8 檔案) 進行播放，就會收到錯誤訊息 (例如「您沒有存取所請求資源的許可」)。不過，您可以使用 Amazon CloudFront CDN (內容交付網路) 播放這些檔案。

CloudFront 分佈可設定為從私有儲存貯體提供內容。普遍情況下，這比擁有可開放存取的儲存貯體來繞過 CloudFront 提供的控制項更好。您可以設定分佈，透過建立原始存取控制 (OAC) 從私有儲存貯體提供服務；該身分是對私有來源儲存貯體具有讀取許可的特殊 CloudFront 使用者。您可以在建立分發之後，透過 CloudFront 主控台或 API 建立 OAC。請參閱《Amazon CloudFront 開發人員指南》中的[建立新的原始存取控制](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html#create-oac-overview-s3)。**

### 在啟用 CORS 的情況下使用 CloudFront 設定播放
<a name="comp-rec-playback-setup"></a>

此範例說明開發人員如何在啟用 CORS 的情況下設定 CloudFront 分佈，以便從任何網域播放錄製檔。這在開發階段特別有用，但您可以修改以下範例以符合生產需求。

#### 步驟 1：建立 S3 儲存貯體
<a name="comp-rec-playback-setup-step1"></a>

建立將用來存放錄製檔的 S3 儲存貯體。請注意，儲存貯體必須位在您用於 IVS 工作流程的相同區域中。

將 CORS 許可政策新增至儲存貯體：

1. 在 AWS Console 中，前往 **S3 儲存貯體許可**索引標籤。

1. 複製下面的 CORS 政策，並將其粘貼到**跨來源資源共用 (CORS)**下。這將啟用 S3 儲存貯體上的 CORS 存取。

   ```
   [
       {
           "AllowedHeaders": [
               "*"
           ],
           "AllowedMethods": [
               "PUT",
               "POST",
               "DELETE",
               "GET"
           ],
           "AllowedOrigins": [
               "*"
           ],
           "ExposeHeaders": [
               "x-amz-server-side-encryption",
               "x-amz-request-id",
               "x-amz-id-2"
           ]
       }
   ]
   ```

#### 步驟 2：建立 CloudFront 分佈
<a name="comp-rec-playback-setup-step2"></a>

請參閱《CloudFront 開發人員指南》中的[建立 CloudFront 分佈](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-creating-console.html)。**

使用 AWS Console 輸入以下資訊：


| 對於此欄位 | 選擇此項目 | 
| --- | --- | 
| 原始網域 | 在上一步建立的 S3 儲存貯體 | 
| 原始存取 | 原始存取控制設定 (建議使用)，使用預設參數 | 
| 預設的快取行為：檢視器通訊協定 | 重新引導 HTTP 到 HTTPS | 
| 預設快取行為：允許的 HTTP 方法 | GET、HEAD 和 OPTIONS | 
| 預設快取行為：快取索引鍵和原始請求 | CachingDisabled 政策 | 
| 預設快取行為：原始要求政策 | CORS-S3Origin | 
| 預設快取行為：回應標頭政策 | SimpleCORS | 
| Web 應用程式防火牆 | 啟用安全保護 | 

然後儲存 CloudFront 分佈。

#### 步驟 3：設定 S3 儲存貯體政策
<a name="comp-rec-playback-setup-step3"></a>

1. 刪除您為 S3 儲存貯體設定的任何 StorageConfiguration。這將移除為該儲存貯體建立政策時自動新增的任何儲存貯體政策。

1. 前往 CloudFront 分佈，確保所有分佈欄位都處於上一步中定義的狀態，然後**複製儲存貯體政策** (使用**複製政策**按鈕)。

1. 前往您的 S3 儲存貯體。在**許可**索引標籤上選取**編輯儲存貯體政策**，然後貼上您在上一步複製的儲存貯體政策。完成此步驟之後，儲存貯體政策中應該只有 CloudFront 政策。

1. 建立 StorageConfiguration，指定 S3 儲存貯體。

建立 StorageConfiguration 之後，您會在 S3 儲存貯體政策中看到兩個項目，一個允許 CloudFront 讀取內容，另一個允許 IVS 寫入內容。在[範例：具備 CloudFront 和 IVS 存取權的 S3 儲存貯體政策](#comp-rec-playback-example)部分中，顯示了具有 CloudFront 和 IVS 存取權的最終儲存貯體政策範例。

#### 步驟 4：播放錄製檔
<a name="comp-rec-playback-setup-step4"></a>

成功設定 CloudFront 分佈並更新儲存貯體政策之後，您應該可以使用 IVS 播放器播放錄製檔：

1. 成功啟動合成，並確定您已將錄製檔存放在 S3 儲存貯體中。

1. 按照此範例中的步驟 1 到步驟 3 操作之後，您應該可以透過 CloudFront URL 使用影片檔案。您的 CloudFront URL 是 Amazon CloudFront 主控台中**詳細資訊**索引標籤上的**分佈網域名稱**。外觀大致如下：

   `a1b23cdef4ghij.cloudfront.net`

1. 若要透過 CloudFront 分佈播放錄製的影片，請在 S3 儲存貯體下尋找 `multivariant.m3u8` 檔案的物件金鑰。外觀大致如下：

   `FDew6Szq5iTt/9NIpWJHj0wPT/fjFKbylPb3k4/composite/media/hls/multivariant.m3u8`

1. 將物件金鑰附加到 CloudFront URL 結尾。您的最終 URL 大致如下：

   `https://a1b23cdef4ghij.cloudfront.net/FDew6Szq5iTt/9NIpWJHj0wPT/fjFKbylPb3k4/composite/media/hls/multivariant.m3u8`

1. 現在，您可以將最終 URL 新增到 IVS 播放器的來源屬性中，以觀看完整的錄製檔。若要觀看錄製的影片，您可以使用《IVS 播放器 SDK：Web 指南》當中[入門](https://docs.aws.amazon.com//ivs/latest/LowLatencyUserGuide/web-getting-started.html)裡的示範。**

### 範例：具備 CloudFront 和 IVS 存取權的 S3 儲存貯體政策
<a name="comp-rec-playback-example"></a>

下面的程式碼片段描繪了一段 S3 儲存貯體政策，該政策允許 CloudFront 將內容讀取到私有儲存貯體，允許 IVS 將內容寫入儲存貯體。**注意：請勿將下面的程式碼片段複製並貼上到自己的儲存貯體中。您的政策應包含與自己 CloudFront 分佈和 StorageConfiguration 相關的 ID。**

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "CompositeWrite-7eiKaIGkC9DO",
      "Effect": "Allow",
      "Principal": {
        "Service": "ivs-composite.ap-northeast-1.amazonaws.com"
      },
      "Action": [
        "s3:PutObject",
        "s3:PutObjectAcl"
      ],
      "Resource": "arn:aws:s3:::eicheane-test-1026-2-ivs-recordings/*",
      "Condition": {
        "StringEquals": {
          "s3:x-amz-acl": "bucket-owner-full-control"
        },
        "Bool": {
          "aws:SecureTransport": "true"
        }
      }
    },
    {
      "Sid": "AllowCloudFrontServicePrincipal",
      "Effect": "Allow",
      "Principal": {
        "Service": "cloudfront.amazonaws.com"
      },
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::eicheane-test-1026-2-ivs-recordings/*",
      "Condition": {
        "StringEquals": {
          "AWS:SourceArn": "arn:aws:cloudfront::844311324168:distribution/E1NG4YMW5MN25A"
        }
      }
    }
  ]
}
```

------

## 疑難排解
<a name="comp-rec-troubleshooting"></a>
+ **合成沒被寫入 S3 儲存貯體：**請確保已在相同區域中建立 S3 儲存貯體和 StorageConfiguration 物件。另外，請檢查儲存貯體政策，確保 IVS 能夠存取儲存貯體；請參閱 [StorageConfiguration 的儲存貯體政策](#comp-rec-bucket-policy)。
+ **我在執行 *ListCompositions* 時找不到合成：**合成是短暫的資源。一旦變更為最終狀態，就會在幾分鐘後自動刪除。
+ **我的合成會自動停止：**如果階段上超過 60 秒都沒有發布者，合成將自動停止。

## 已知問題
<a name="comp-rec-issues"></a>

在合成進行時，透過複合錄製寫入的媒體播放清單擁有 `#EXT-X-PLAYLIST-TYPE:EVENT` 標籤。合成完成後，標籤會更新為 `#EXT-X-PLAYLIST-TYPE:VOD`。為了獲得流暢的播放體驗，我們建議您只在成功完成合成後使用此播放清單。