

# IVS 自動錄製至 Amazon S3 \| 低延遲串流
<a name="record-to-s3"></a>

本節提供 Amazon IVS 低延遲串流功能自動錄製到 S3 功能的相關資訊。我們會討論錄製的 Amazon IVS 串流的資料儲存。我們會解釋儲存內容和中繼資料檔案結構描述。我們也會討論播放錄製的內容。


| 如需詳細資訊， | 請參閱 | 
| --- | --- | 
| 設定和停止影片錄製 |  *Amazon IVS 入門*中的[建立帶有選用錄製的頻道](https://docs.aws.amazon.com//ivs/latest/LowLatencyUserGuide/getting-started-create-channel.html) | 
| API | [IVS API 參考](https://docs.aws.amazon.com//ivs/latest/LowLatencyAPIReference/Welcome.html) | 
| 成本 |  [Amazon IVS 費用](https://docs.aws.amazon.com//ivs/latest/LowLatencyUserGuide/costs.html) | 

## S3 字首
<a name="r2s3-prefix"></a>

S3 字首是錄製的每個即時串流的唯一目錄結構。即時串流的所有媒體和中繼資料檔案都會寫入此目錄中。對於啟用錄製的頻道，S3 字首會在實時工作階段開始時產生，並會在錄製開始和結束時在 CloudWatch 事件中提供。

S3 字首的格式如下：

```
/ivs/v1/<aws_account_id>/<channel_id>/<year>/<month>/<day>/<hours>/<minutes>/<recording_id>
```

其中：
+ `aws_account_id` 是 AWS 帳戶的 ID (建立 AWS 帳戶時產生)，從中建立頻道。
+ `channel_id` 是頻道 ARN 的資源 ID 部分 (Amazon 資源名稱的最後部分)。請參閱 [詞彙表](ivs-glossary.md) 中的 ARN。
+ `<year>/<month>/<day>/<hours>/<minutes>` 是錄製開始時的 UTC 時間戳記。
+ `recording_id` 是為每個錄製工作階段產生的唯一 ID。

例如：

```
ivs/v1/123456789012/AsXego4U6tnj/2020/6/23/20/12/j8Z9O91ndcVs
```

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

錄製開始時，影片片段和中繼資料檔案會寫入至為頻道設定的 S3 儲存貯體。這些內容可用於後續處理或作為隨需影片播放。

請注意，即時串流啟動並發出「錄製開始 EventBridge」事件之後，需要一點時間才能寫入資訊清單檔案和影片片段。建議您只在傳送「錄製結束」事件之後播放或處理錄製的串流。(請參閱 [搭配 IVS 使用 Amazon EventBridge](eventbridge.md))。

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

```
ivs/v1/123456789012/AsXego4U6tnj/2020/6/23/20/12/j8Z9O91ndcVs/
   events
      recording-started.json
      recording-ended.json
   media
      hls
      thumbnails
```

`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` 包含即時工作階段期間產生的所有媒體和資訊清單檔案，並且可以使用 Amazon IVS 播放器播放。此資料夾中有兩種類型的 HLS 清單檔案，即標準主清單檔案 `master.m3u8` 和啟用位元組範圍的清單檔案 `byte-range-multivariant.m3u8`。因此，每個轉譯資料夾都有 `playlist.m3u8` 和 `byte-range-variant.m3u8` 檔案。(請參閱下方的[位元組範圍播放清單](#r2s3-byte-range-playlists)。)
+ `thumbnails` 包含即時工作階段期間產生的縮圖影像。每分鐘會產生縮圖並寫入儲存貯體。(若要變更此行為，請覆蓋錄製組態中的 `thumbnailConfiguration` 屬性。)

**重要：**`media` 資料夾中的內容動態產生並由第一個接收的影片片段的特性決定；資料夾內容可能無法代表最終特性 (例如轉譯品質)。*不要對靜態路徑做任何假設。*若要探索可用的 HLS 轉譯及其路徑，請使用如下所述的 JSON 中繼資料檔案。

## 位元組範圍播放清單
<a name="r2s3-byte-range-playlists"></a>

除了標準 HLS 播放清單外，auto-record-to-S3 功能還支援產生[位元組範圍播放清單](https://datatracker.ietf.org/doc/html/draft-pantos-http-live-streaming-23#section-4.3.2.2)。位元組範圍播放清單符合 HLS 規範的第 4 版。這允許進行更精細的內容剪輯：在位元組範圍播放清單中，轉譯索引檔案中的每個區段都會參考影片區塊的位元組子範圍，從而提供高於標準 10 秒媒體檔案大小的精細程度。使用位元組範圍播放清單，區段持續時間會與為串流設定的關鍵影格間隔相同。

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

錄製組態中的 `thumbnailConfiguration` 屬性允許您啟用或停用實時工作階段的縮圖錄製，並修改為實時工作階段產生縮圖的間隔。縮圖間隔時間可能介於 1 秒至 60 秒之間；依預設，會以 60 秒的間隔時間啟用縮圖錄製。如需詳細資訊，請參閱 [Amazon IVS 低延遲串流功能 API 參考](https://docs.aws.amazon.com//ivs/latest/LowLatencyAPIReference/Welcome.html)。

縮圖組態也可能包括 `storage` 欄位 (`SEQUENTIAL` 及/或 `LATEST`) 和解析度 (`LOWEST_RESOLUTION`、`SD`、`HD` 或 `FULL_HD`)。以下是每個選項的解析度：

160 <= `LOWEST_RESOLUTION` <= 360

360 < `SD` <= 480

480 < `HD` <= 720

720 < `FULL_HD` <= 1080

如果針對使用多軌視訊輸入的串流取消設定 `resolution`，則會錄製所有轉譯的縮圖。如需多軌的相關資訊，請參閱[多軌視訊](multitrack-video.md)。

## 合併分段的串流
<a name="r2s3-merge-fragmented-streams"></a>

錄製組態的 `recordingReconnectWindowSeconds` 屬性可讓您指定一段時間 (以秒為單位)，如果在這段時間內串流中斷並啟動新串流，Amazon IVS 會試圖將其錄製到與上一個串流相同的 S3 字首。換言之，如果廣播中斷連線後在指定的重新連線間隔內重新連線，則會將多個串流視為單一廣播並合併在一起。

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

如需設定合併串流功能的說明，請參閱 *Amazon IVS 入門*中的[步驟 4：建立帶有選用錄製的頻道](getting-started-create-channel.md)。

### 資格
<a name="r2s3-merge-fragmented-streams-eligibility"></a>

若要將多個串流錄製到相同的 S3 字首，則所有串流都必須符合某些特定條件：
+ 影片寬度和高度必須相同。
+ 影格播放速率必須相同。
+ 後續串流的位元速率差異必須小於或等於原始串流位元速率的 50%。
+ 影片和音訊轉碼器必須相同。

**備註：**
+ 最多可合併 20 個串流，合併後會建立新的 S3 字首。
+ 48 小時後會建立新的 S3 字首。例如，如果第一個廣播持續 48 小時，而另一個廣播在 `recordingReconnectWindowSeconds` 間隔內開始，那麼下一個廣播*不會*合併到第一個 S3 字首。
+ 快速重新連線可能會導致新的廣播在前一個廣播完成寫入 S3 之前開始，在這種情況下，新的廣播*不會*合併到前一個 S3 字首。(通常，寫入 S3 會在廣播結束後的 10 秒內完成。) 快速重新連線可能會在多種情況下發生，包括：1) 快速切換行動應用程式的背景/前景，2) 使用 IVS 行動廣播 SDK 的自動重新連線功能時無法進行串流接管，以及 3) 呼叫 [StopStream](https://docs.aws.amazon.com//ivs/latest/LowLatencyAPIReference/API_StopStream.html) 時觸發串流用戶端軟體的自動重新連線。

### 已知問題
<a name="r2s3-merge-fragmented-streams-known-issue"></a>

如果 `recordingReconnectWindowSeconds` 已啟用且使用 Web 廣播開發套件，則錄製到相同 S3 字首的功能可能無法運作，因為 Web 廣播開發套件會動態變更位元速率和品質。

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

發生錄製狀態變更事件時，系統會產生對應的 Amazon CloudWatch 指標，並在 S3 字首中寫入中繼資料檔案。(請參閱[監控 Amazon IVS 低延遲串流功能](stream-health.md)。)

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


| 欄位 | 類型 | 必要 | 描述 | 
| --- | --- | --- | --- | 
| `channel_arn` | string | 是 | 廣播即時串流的頻道的 ARN。 | 
| `media` | object | 是 | 包含此錄製可用媒體內容之列舉物件的物件。有效值：`"hls"`、`"thumbnails"`。 | 
| [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html) | object | 是 | 說明 Apple HLS 格式輸出的列舉欄位。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.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/LowLatencyUserGuide/record-to-s3.html)  | string | 是 | 儲存 HLS 內容之 S3 字首的相對路徑。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html)  | string | 是 | HLS 主播放清單檔案的名稱。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html)  | string | 是 | HLS 位元組範圍多變體播放清單的名稱。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html)  | object | 是 | 中繼資料物件的轉譯 (HLS 變體) 陣列。總是至少有一個轉譯。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html)  | string | 是 | 為此轉譯儲存 HLS 內容之 S3 字首的相對路徑。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html)  | string | 是 | 此轉譯的媒體播放清單檔案名稱。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html)  | string | 是 | 此轉譯的位元組範圍播放清單的名稱。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html)  | int | 有條件 | 編碼影片的像素解析度高度。轉譯包含影片軌道時才可用。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html)  | int | 有條件 | 編碼影片的像素解析度寬度。轉譯包含影片軌道時才可用。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html)  | object | 有條件 | 描述縮圖輸出的列舉欄位。僅當縮圖組態的 `recordingMode` 為 `INTERVAL` 時才可用。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html)  | string | 有條件 | 儲存縮圖內容之 S3 字首的相對路徑。僅當縮圖組態的 `recordingMode` 為 `INTERVAL` 時才可用。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html)  | int | 是 | 縮圖的高度。預設值：來源轉譯的解析度。此值受相關錄製組態中的使用者輸入的影響；特別是 `thumbnailConfiguration.resolution ` 值。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html)  | int | 是 | 縮圖的寬度。預設值：來源轉譯的解析度。此值受相關錄製組態中的使用者輸入的影響；特別是 `thumbnailConfiguration.resolution` 值。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html)  | object | 是 | 描述最新縮圖輸出的列舉欄位。僅當縮圖組態的 `storage` 包括 `LATEST` 時才可用。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html)  | int | 是 | 縮圖的高度。預設值將為來源轉譯的解析度。此值受相關錄製組態中的使用者輸入的影響；特別是 `thumbnailConfiguration.resolution` 值。 | 
|  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/record-to-s3.html)  | int | 是 | 縮圖的寬度。預設值將為來源轉譯的解析度。此值受相關錄製組態中的使用者輸入的影響；特別是 `thumbnailConfiguration.resolution` 值。 | 
| `recording_ended_at` | string | 有條件 | 錄製結束時，RFC 3339 UTC 時間戳記。當 `recording_status` 為 `"RECORDING_ENDED"` 或 `"RECORDING_ENDED_WITH_FAILURE"` 時才可用。<br />`recording_started_at` 和 `recording_ended_at` 是這些事件生成時的時間戳記，未必與 HLS 影片區段時間戳記完全相符。若要準確判斷錄製的持續時間，請使用 `duration_ms` 欄位。 | 
| `recording_started_at` | string | 是 | 錄製開始時，RFC 3339 UTC 時間戳記。<br />請參閱上面的 `recording_ended_at` 備註。 | 
| `recording_status` | string | 是 | 錄製的狀態。有效值：`"RECORDING_STARTED"`、`"RECORDING_ENDED"`、`"RECORDING_ENDED_WITH_FAILURE"`。 | 
| `recording_status_message` | string | 有條件 | 狀態的描述性資訊。當 `recording_status` 為 `"RECORDING_ENDED"` 或 `"RECORDING_ENDED_WITH_FAILURE"` 時才可用。 | 
| `version` | string | 是 | 中繼資料結構描述的版本。 | 

### 範例：recording\_started.json
<a name="r2s3-json-metadata-recording-started"></a>

```
{
   "version": "v1",
   "channel_arn": "arn:aws:ivs:us-west-2:123456789012:channel/AsXego4U6tnj",
   "recording_started_at": "2020-06-12T12:53:26Z",
   "recording_status : "RECORDING_STARTED",
   "media": {
      "hls": {
         "path": "media/hls",
         "playlist": "master.m3u8",
         "byte_range_playlist": "byte-range-multivariant.m3u8",
         "renditions": [
            {
               "path": "480p30",
               "playlist": "playlist.m3u8",
               "byte_range_playlist": "byte-range-variant.m3u8",
               "resolution_height": 480,
               "resolution_width": 852
            },
            {
               "path": "360p30",
               "playlist": "playlist.m3u8",
               "byte_range_playlist": "byte-range-variant.m3u8",
               "resolution_height": 360,
               "resolution_width": 640
            },
            {
               "path": "160p30",
               "playlist": "playlist.m3u8",
               "byte_range_playlist": "byte-range-variant.m3u8",
               "resolution_height": 160,
               "resolution_width": 284
            },
            {
               "path": "720p60",
               "playlist": "playlist.m3u8",
               "byte_range_playlist": "byte-range-variant.m3u8",
               "resolution_height": 720,
               "resolution_width": 1280
            }
         ]
      },
      "thumbnails": {
         "path": "media/thumbnails",
         "resolution_height": 480,
         "resolution_width": 852
      },
      "latest_thumbnail": {
         "path": "media/latest_thumbnail/thumb.jpg",
         "resolution_height": 480,
         "resolution_width": 852
      }
   }
}
```

### 範例：recording\_ended.json
<a name="r2s3-json-metadata-recording-ended"></a>

```
{
   "version": "v1",
   "channel_arn": "arn:aws:ivs:us-west-2:123456789012:channel/AsXego4U6tnj",
   "recording_ended_at": "2020-06-14T12:53:20Z",
   "recording_started_at": "2020-06-12T12:53:26Z",
   "recording_status": "RECORDING_ENDED",
   "media": {
      "hls": {
         "duration_ms": 172794489,
         "path": "media/hls",
         "playlist": "master.m3u8",
         "byte_range_playlist": "byte-range-multivariant.m3u8",
         "renditions": [
            {
               "path": "480p30",
               "playlist": "playlist.m3u8",
               "byte_range_playlist": "byte-range-variant.m3u8",
               "resolution_height": 480,
               "resolution_width": 852
            },
            {
               "path": "360p30",
               "playlist": "playlist.m3u8",
               "byte_range_playlist": "byte-range-variant.m3u8",
               "resolution_height": 360,
               "resolution_width": 640
            },
            {
               "path": "160p30",
               "playlist": "playlist.m3u8",
               "byte_range_playlist": "byte-range-variant.m3u8",
               "resolution_height": 160,
               "resolution_width": 284
            },
            {
               "path": "720p60",
               "playlist": "playlist.m3u8",
               "byte_range_playlist": "byte-range-variant.m3u8",
               "resolution_height": 720,
               "resolution_width": 1280
            }
         ]
      },
      "thumbnails": {
         "path": "media/thumbnails",
         "resolution_height": 480,
         "resolution_width": 852
      },
      "latest_thumbnail": {
         "path": "media/latest_thumbnail/thumb.jpg",
         "resolution_height": 480,
         "resolution_width": 852
      }
   }
}
```

### 範例：recording\_failed.json
<a name="r2s3-json-metadata-recording-failed"></a>

```
{
   "version": "v1",
   "channel_arn": "arn:aws:ivs:us-west-2:123456789012:channel/AsXego4U6tnj",
   "recording_ended_at": "2020-06-14T12:53:20Z",
   "recording_started_at": "2020-06-12T12:53:26Z",
   "recording_status": "RECORDING_ENDED_WITH_FAILURE",
   "recording_status_message": "InternalServerException",
   "media": {
      "hls": {
         "duration_ms": 172794489,
         "path": "media/hls",
         "playlist": "master.m3u8",
         "renditions": [
            {
               "path": "480p30",
               "playlist": "playlist.m3u8",
               "resolution_height": 480,
               "resolution_width": 852
            },
            {
               "path": "720p60",
               "playlist": "playlist.m3u8",
               "resolution_height": 720,
               "resolution_width": 1280
            }
         ]
      },
      "thumbnails": {
         "path": "media/thumbnails",
         "resolution_height": 480,
         "resolution_width": 852
      },
      "latest_thumbnail": {
         "path": "media/latest_thumbnail/thumb.jpg",
         "resolution_height": 480,
         "resolution_width": 852
      }
   }
}
```

## 發現錄製的轉譯
<a name="r2s3-recording-renditions"></a>

將內容串流到 Amazon IVS 頻道時，自動錄製到 s3 會使用來源影片產生多個轉譯。使用[自適應位元速率串流](player.md) (ABR)，Amazon IVS 播放器會根據需要自動切換轉譯 (位元速率)，以針對不同的網路條件使播放最佳化。

即時串流期間產生的每個轉譯都會錄製在 S3 錄製字首中的唯一路徑中。在錄製開始和停止期間，解析度詳細資訊、路徑和播放清單檔案名稱會儲存在 [JSON 中繼資料檔案](#r2s3-json-metadata)中。如果錄製組態的 `renditionSelection` 值為 `ALL`，則會選取所有轉譯以進行錄製。如果 `renditionSelection` 為 `CUSTOM`，則使用者必須選取下列一個或多個選項：`LOWEST_RESOLUTION`、`SD`、`HD` 和FULL\_HD。以下是每個選項的解析度：

160 <= `LOWEST_RESOLUTION` <= 360

360 < `SD` <= 480

480 < `HD` <= 720

720 < `FULL_HD` <= 1080

**重要：***請勿*對靜態轉譯路徑或產生的轉譯清單做出任何假設，因為這些假設可能會發生變化。*請勿*假設某個特定轉譯始終可用於 Amazon IVS 錄製 若要確定可用的轉譯、解析度和路徑，請參閱中繼資料檔案。

錄製字首中的 `event/recording_started.json` 或 `event/recording_ended.json` 檔案包含錄製字首中的媒體檔案路徑和名稱。所有 `path` 元素相對於階層中的先前路徑。`media > hls` 下的元素利用在此層級定義的主播清單名稱和路徑來描述 HLS 資產。

下面是一個 Python 程式碼片段，展示如何使用 S3 錄製字首和中繼資料檔案產生主播放清單路徑：

```
def get_master_playlist(metadata_json, s3_recording_prefix):
   return s3_recording_prefix + '/' + metadata_json['media']['hls']['path'] + '/' + metadata_json['media']['hls']['playlist']
```

`media > hls > renditions` 下的元素描述錄製的轉譯清單。`resolution_height` 和 `resolution_width` 屬性可用來識別影片解析度。`path` 和 `playlist` 元素可以用來衍生轉譯播放清單路徑。使用這些欄位可決定哪些轉譯用於後續處理。

您可以訂閱「IVS 錄製狀態變更」EventBridge 事件，以探索某個錄製的最高可用播放清單。(請參閱 [搭配 IVS 使用 Amazon EventBridge](eventbridge.md))。下面是一個 Python 指令碼範例，它說明了如何使用訂閱這些事件的 lambda 函數。

```
import json
import boto3
s3 = boto3.resource('s3')

def get_highest_rendition_playlist(bucket_name, prefix_name):
   object_path = "{}/events/recording-started.json".format(prefix_name)
   object = s3.Object(bucket_name, object_path)
   body = str(object.get()['Body'].read().decode('utf-8'))
   metadata = json.loads(body)
   media_path = metadata["media"]["hls"]["path"]
   renditions = metadata["media"]["hls"]["renditions"]

   highest_rendition = None
   highest_rendition_size = 0

   for rendition in renditions:
       current_rendition_size = rendition["resolution_height"]
       if (current_rendition_size > highest_rendition_size):
           highest_rendition_size = current_rendition_size
           highest_rendition = rendition

   highest_rendition_playlist = media_path + '/' + highest_rendition['path'] + '/' + highest_rendition['playlist']
   return highest_rendition_playlist


def lambda_handler(event, context):
   prefix_name = event["detail"]["recording_s3_key_prefix"]
   bucket_name = event["detail"]["recording_s3_bucket_name"]
   rendition_playlist = get_highest_rendition_playlist(bucket_name, prefix_name)
   print("Highest rendition playlist: {}/{}".format(prefix_name, rendition_playlist))

   return {
       'statusCode': 200,
       'body': rendition_playlist
   }
```

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

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

### Amazon CloudFront 分佈
<a name="r2s3-cdn-oai"></a>

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

### 從 Amazon CloudFront 播放
<a name="r2s3-cdn-playback"></a>

一旦您使用 OAC 設定分佈以存取私有儲存貯體，您的影片檔案應該可以透過 CloudFront URL 取用。您的 CloudFront URL 是 AWS CloudFront 主控台中**詳細資訊**索引標籤上的**分發網域名稱**。外觀大致如下：

a1b23cdef4ghij.cloudfront.net。

若要透過分佈串流錄製的影片，請尋找 `master.m3u8` 檔案的物件金鑰。外觀大致如下：

```
ivs/v1/012345678912/a0bCDeFGH1IjK/2021/4/20/12/03/aBcdEFghIjkL/media/hls/master.m3u8
```

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

```
https://a1b23cdef4ghij.cloudfront.net/ivs/v1/012345678912/a0bCDeFGH1IjK/2021/4/20/12/03/aBcdEFghIjkL/media/hls/master.m3u8
```

若要從 Web 瀏覽器播放，請務必同時在 CloudFront 和 S3 儲存貯體中設定 CORS。若是 CloudFront 組態，請遵循 [Creating origin request policies](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-origin-requests.html#origin-request-create-origin-request-policy) 中的說明，將 **CORS-S3 原始**請求政策和 **SimpleCORS** 回應標頭政策連接至 CloudFront 分發。請參閱下面的範例組態主控台頁面：

![範例組態主控台頁面。建議您使用快取政策和原始請求政策，來控制快取索引鍵和原始請求。](http://docs.aws.amazon.com/zh_tw/ivs/latest/LowLatencyUserGuide/images/CORS_Configuration.png)


如需 S3 CORS 組態相關資訊，請參閱 [CORS 組態](https://docs.aws.amazon.com/AmazonS3/latest/userguide/ManageCorsUsing.html)，為您的 S3 儲存貯體建立適當的規則。

現在，您可以像直接從儲存貯體播放一樣播放錄製的影片。

如需詳細資訊，請參閱[限制對 Amazon S3 原始伺服器的存取](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html)。