

# IVS 合成录制 \$1 实时直播功能
<a name="rt-composite-recording"></a>

本文档介绍如何在[服务器端合成](server-side-composition.md)中使用合成录制功能。合成录制允许您使用 IVS 服务器将所有舞台发布者有效地组合到一个视图中，然后将生成的视频保存到 S3 存储桶中，从而生成 IVS 舞台的 HLS 录制。

需要支付标准 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 存储桶，则**对象所有权**设置必须为**强制存储桶拥有者**或**首选存储桶拥有者**。有关详细信息，请参阅有关[控制对象所有权](https://docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html)的 S3 文档。

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_cn/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 合成状态更改（会话结束）”事件后回放或处理录制的流。有关详细信息，请参阅[将 EventBridge 与 IVS 实时直播功能结合使用](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` | 字符串 | 是 | 用作合成来源的舞台的 ARN。 | 
| `media` | 对象 | 是 | 包含可用于此录制的媒体内容的枚举对象的对象。有效值：`"hls"`。  | 
| [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html) | 对象 | 是 | 描述 Apple HLS 格式输出的枚举字段。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | 字符串 | 是 | 存储 HLS 内容的 S3 前缀的相对路径。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | 字符串 | 是 |  HLS 主播放列表文件的名称。  | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | 对象 | 是 | 元数据对象的呈现数组（HLS 变体）。始终至少有一个呈现。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | 字符串 | 是 | 为此呈现存储 HLS 内容的 S3 前缀的相对路径。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | 字符串 | 是 | 此呈现的媒体播放列表文件的名称。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | int | 条件 | 编码视频的像素分辨率高度。仅当呈现包含视频轨道时，此选项才可用。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | int | 条件 | 编码视频的像素分辨率宽度。仅当呈现包含视频轨道时，此选项才可用。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | object | 有条件 | 描述缩略图输出的枚举字段。只有当缩略图配置的 `storage` 字段包含 `SEQUENTIAL` 时，这才可用 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | 字符串 | 是 | 存储连续缩略图内容的 S3 前缀的相对路径。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | 对象 | 是 | 元数据对象的分辨率数组（缩略图变体）。始终至少有一个分辨率。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | 字符串 | 是 | 为此分辨率存储缩略图内容的 S3 前缀的相对路径。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | int | 是 | 缩略图的像素分辨率高度。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | int | 是 | 缩略图的像素分辨率宽度。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | object | 有条件 | 描述缩略图输出的枚举字段。只有当缩略图配置的 `storage` 字段包含 `LATEST` 时，这才可用 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | 字符串 | 是 | 存储 `latest_thumbnail` 的 S3 前缀的相对路径。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | 对象 | 是 | 元数据对象的分辨率数组（缩略图变体）。始终至少有一个分辨率。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | 字符串 | 是 | 为此分辨率存储最新缩略图的 S3 前缀的相对路径。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | int | 是 | 最新缩略图的像素分辨率高度。 | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/ivs/latest/RealTimeUserGuide/rt-composite-recording.html)  | int | 是 | 最新缩略图的像素分辨率宽度。 | 
| `recording_ended_at` | 字符串 | 条件 | 录制结束时的 RFC 3339 UTC 时间戳。此选项仅在 `recording_status` 为 `"RECORDING_ENDED"` 或 `"RECORDING_ENDED_WITH_FAILURE"` 时可用。 `recording_started_at` 和 `recording_ended_at` 是这些事件生成时的时间戳，可能与 HLS 视频片段的时间戳不完全一致。要准确确定录制的持续时间，请使用 `duration_ms` 字段。  | 
| `recording_started_at` | 字符串 | 有条件 | 录制开始时的 RFC 3339 UTC 时间戳。这在 `recording_status` 为 `RECORDING_START_FAILED` 时不可用。 请参阅上面有关 `recording_ended_at` 的注释。  | 
| `recording_status` | 字符串 | 是 | 录制的状态。有效值：`"RECORDING_STARTED"`、`"RECORDING_ENDED"`、`"RECORDING_START_FAILED"`、`"RECORDING_ENDED_WITH_FAILURE"`。 | 
| `recording_status_message` | 字符串 | 条件 | 状态的描述性信息。此选项仅在 `recording_status` 为 `"RECORDING_ENDED"` 或 `"RECORDING_ENDED_WITH_FAILURE"` 时可用。 | 
| `version` | 字符串 | 是 | 元数据架构的版本。 | 

### 示例：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）将分配设置为从私有存储桶提供服务，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 控制台中，转到 **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 控制台，输入以下内容：


| 对于此字段…… | 选择此…… | 
| --- | --- | 
| 源域 | 在上一步中创建的 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 播放器开发工具包：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`。为了获得流畅的播放体验，我们建议您仅在成功完成合成后使用此播放列表。