

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 Amazon Rekognition 分段 API
<a name="segment-api"></a>

存储视频中 Amazon Rekognition Video 分段检测是一项 Amazon Rekognition Video 异步操作。Amazon Rekognition 分段 API 是一种复合 API，您可以从单个 API 调用中选择分析类型（技术提示或镜头检测）。有关调用异步操作的信息，请参阅[调用 Amazon Rekognition Video 操作](api-video.md)。

**Topics**
+ [起始段分析](#segment-api-start)
+ [获取分段分析结果](#segment-api-get)

## 起始段分析
<a name="segment-api-start"></a>

要开始检测存储视频中的分段，请调用 [StartSegmentDetection](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_StartSegmentDetection.html)。输入参数与其他 Amazon Rekognition Video 操作相同，但添加了分段类型选择和结果筛选。有关更多信息，请参阅 [启动视频分析](api-video.md#api-video-start)。

以下是 `StartSegmentDetection` 传递的 JSON 示例。请求同时指定检测技术提示和镜头检测分段。为技术提示分段 (90%) 和镜头检测分段 (80%) 请求了不同的筛选器，以实现最低检测置信度。

```
{
  "Video": {
    "S3Object": {
      "Bucket": "test_files",
      "Name": "test_file.mp4"
    }
    "SegmentTypes":["TECHNICAL_CUES", "SHOT"]
    "Filters": {
      "TechnicalCueFilter": {
         "MinSegmentConfidence": 90,
         "BlackFrame" : {
            "MaxPixelThreshold": 0.1,
            "MinCoveragePercentage": 95     
         }
      },
      "ShotFilter" : {
          "MinSegmentConfidence": 60
      }
  }
}
```

### 选择分段类型
<a name="segment-feature-type"></a>

使用数`SegmentTypes`组输入参数检测输入视频中的技术提示 and/or 镜头检测片段。
+ 技术提示 — 识别在视频中检测到的技术提示（黑帧、彩条、片头字幕、片尾字幕、工作室徽标和主要节目内容）的开始、结束和持续时间的精确到帧的时间戳。例如，您可以使用技术提示来查找片尾字幕的开始。有关更多信息，请参阅 [技术提示](segments.md#segment-technical-cue)。
+ 镜头 — 识别镜头的开始、结束和持续时间。例如，您可以使用镜头检测来确定一个视频的最终编辑候选镜头。有关更多信息，请参阅 [镜头检测](segments.md#segment-shot-detection)。

### 筛选分析结果
<a name="w2aac43c29b7c11"></a>

您可以使用 `Filters` ([StartSegmentDetectionFilters](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_StartSegmentDetectionFilters.html)) 输入参数指定响应中返回的最低检测可信度。在 `Filters` 中，使用 `ShotFilter` ([StartShotDetectionFilter](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_StartShotDetectionFilter.html)) 筛选检测到的镜头。使用 `TechnicalCueFilter` ([StartTechnicalCueDetectionFilter](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_StartTechnicalCueDetectionFilter.html)) 筛选技术线索。

有关示例代码，请参阅[示例：检测存储视频中的分段](segment-example.md)。

## 获取分段分析结果
<a name="segment-api-get"></a>

Amazon Rekognition Video 会将视频分析的完成状态发布到 Amazon Simple Notification Service 主题。如果视频分析成功，请致电[GetSegmentDetection](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_GetSegmentDetection.html)以获取视频分析的结果。

以下是一个示例 `GetSegmentDetection` 请求。`JobId` 是从对 `StartSegmentDetection` 的调用中返回的作业标识符。有关其他输入参数的信息，请参阅[获取 Amazon Rekognition Video 分析结果](api-video.md#api-video-get)。

```
{
    "JobId": "270c1cc5e1d0ea2fbc59d97cb69a72a5495da75851976b14a1784ca90fc180e3",
    "MaxResults": 10,
    "NextToken": "XfXnZKiyMOGDhzBzYUhS5puM+g1IgezqFeYpv/H/+5noP/LmM57FitUAwSQ5D6G4AB/PNwolrw=="
}
```

`GetSegmentDetection` 返回所请求分析的结果以及有关存储的视频的常规信息。

### 一般信息
<a name="segment-api-general"></a>

`GetSegmentDection` 返回以下常规信息。
+ **音频信息**-响应包括[AudioMetadata](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_AudioMetadata.html)对象数组中的音频元数据。`AudioMetadata`可以有多个音频流。每个 `AudioMetadata` 对象都包含一个音频流的元数据。`AudioMetadata` 对象中的音频信息包括音频编解码器、音频通道数量、音频流的持续时间和采样率。音频元数据在 `GetSegmentDetection` 返回的每个信息页面中返回。
+ **视频信息** — 目前，Amazon Rekognition Video 返回数组中的单个对象。[VideoMetadata](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_VideoMetadata.html)`VideoMetadata`该对象包含有关 Amazon Rekognition Video 选择分析的输入文件中视频流的信息。`VideoMetadata` 对象包括视频编解码器、视频格式和其他信息。视频元数据在 `GetSegmentDetection` 返回的每个信息页面中返回。
+ **分页信息** – 示例显示了分段信息的一页。您可以在 `GetSegmentDetection` 的 `MaxResults` 输入参数中指定要返回的元素数量。如果存在的结果的数量超过了 `MaxResults`，则 `GetSegmentDetection` 会返回一个令牌 (`NextToken`)，用于获取下一页的结果。有关更多信息，请参阅 [获取 Amazon Rekognition Video 分析结果](api-video.md#api-video-get)。
+ **请求信息** – 在对 `StartSegmentDetection` 的调用中请求的分析类型在 `SelectedSegmentTypes` 字段中返回。

### Segments
<a name="segment-api-technical-segments"></a>

在视频中检测到的技术提示和镜头信息在 [SegmentDetection](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_SegmentDetection.html) 对象的数组 `Segments` 中返回。输入按照在 `StartSegmentDetection` 的 `SegmentTypes` 输入参数中指定的分段类型（TECHNICAL\_CUE 或 SHOT）排序。在每个分段类型中，数组按时间戳值排序。每个 `SegmentDetection` 对象都包括有关所检测到分段类型的信息（技术提示或镜头检测）以及常规信息，例如分段的开始时间、结束时间和持续时间。

时间信息以三种格式返回。
+ 

**毫秒**  
自视频开始以来的毫秒数。字段 `DurationMillis`、`StartTimestampMillis` 和 `EndTimestampMillis` 采用毫秒格式。
+ 

**时间码**  
Amazon Rekognition Video 时间码采用 [SMPTE](https://en.wikipedia.org/wiki/SMPTE_timecode) 格式，视频的每个帧都有一个唯一的时间码值。格式为 *hh:mm:ss:frame*。例如，时间码值 01:05:40:07 将被读取为 1 小时 5 分 47 秒第 7 帧。Amazon Rekognition Video 支持[丢帧](https://en.wikipedia.org/wiki/SMPTE_timecode#Drop-frame_timecode)率用例。丢帧率时间码格式为 *hh:mm:ss;frame*。字段 `DurationSMPTE`、`StartTimecodeSMPTE` 和 `EndTimecodeSMPTE` 采用时间码格式。
+ 

**帧计数器**  
每个视频分段的持续时间也用帧数表示。该字段 `StartFrameNumber` 给出视频分段开头的帧数，`EndFrameNumber` 给出视频分段末尾的帧数。`DurationFrames` 给出视频分段的总帧数。这些值是使用以 0 开头的帧索引计算的。

您可以使用 `SegmentType` 字段确定 Amazon Rekognition Video 返回的分段的类型。
+ **技术线索** — 该`TechnicalCueSegment`字段是一个包含探测置信度和技术线索类型的[TechnicalCueSegment](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_TechnicalCueSegment.html)对象。技术提示的类型有 `ColorBars`、`EndCredits`、`BlackFrames`、`OpeningCredits`、`StudioLogo`、`Slate`和`Content`。
+ **镜头** — 该`ShotSegment`字段是一个包含检测置信度和视频中镜头片段标识符的[ShotSegment](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_ShotSegment.html)对象。

 以下示例是 `GetSegmentDetection` 的 JSON 响应。

```
{
    "SelectedSegmentTypes": [
        {
            "ModelVersion": "2.0",
            "Type": "SHOT"
        },
        {
            "ModelVersion": "2.0",
            "Type": "TECHNICAL_CUE"
        }
    ],
    "Segments": [
        {
            "DurationFrames": 299,
            "DurationSMPTE": "00:00:09;29",
            "StartFrameNumber": 0,
            "EndFrameNumber": 299,
            "EndTimecodeSMPTE": "00:00:09;29",
            "EndTimestampMillis": 9976,
            "StartTimestampMillis": 0,
            "DurationMillis": 9976,
            "StartTimecodeSMPTE": "00:00:00;00",
            "Type": "TECHNICAL_CUE",
            "TechnicalCueSegment": {
                "Confidence": 90.45006561279297,
                "Type": "BlackFrames"
            }
        },
        {
            "DurationFrames": 150,
            "DurationSMPTE": "00:00:05;00",
            "StartFrameNumber": 299,
            "EndFrameNumber": 449,
            "EndTimecodeSMPTE": "00:00:14;29",
            "EndTimestampMillis": 14981,
            "StartTimestampMillis": 9976,
            "DurationMillis": 5005,
            "StartTimecodeSMPTE": "00:00:09;29",
            "Type": "TECHNICAL_CUE",
            "TechnicalCueSegment": {
                "Confidence": 100.0,
                "Type": "Content"
            }
        },
        {
            "DurationFrames": 299,
            "ShotSegment": {
                "Index": 0,
                "Confidence": 99.9982681274414
            },
            "DurationSMPTE": "00:00:09;29",
            "StartFrameNumber": 0,
            "EndFrameNumber": 299,
            "EndTimecodeSMPTE": "00:00:09;29",
            "EndTimestampMillis": 9976,
            "StartTimestampMillis": 0,
            "DurationMillis": 9976,
            "StartTimecodeSMPTE": "00:00:00;00",
            "Type": "SHOT"
        },
        {
            "DurationFrames": 149,
            "ShotSegment": {
                "Index": 1,
                "Confidence": 99.9982681274414
            },
            "DurationSMPTE": "00:00:04;29",
            "StartFrameNumber": 300,
            "EndFrameNumber": 449,
            "EndTimecodeSMPTE": "00:00:14;29",
            "EndTimestampMillis": 14981,
            "StartTimestampMillis": 10010,
            "DurationMillis": 4971,
            "StartTimecodeSMPTE": "00:00:10;00",
            "Type": "SHOT"
        }
    ],
    "JobStatus": "SUCCEEDED",
    "VideoMetadata": [
        {
            "Format": "QuickTime / MOV",
            "FrameRate": 29.970029830932617,
            "Codec": "h264",
            "DurationMillis": 15015,
            "FrameHeight": 1080,
            "FrameWidth": 1920,
            "ColorRange": "LIMITED"

        }
    ],
    "AudioMetadata": [
        {
            "NumberOfChannels": 1,
            "SampleRate": 48000,
            "Codec": "aac",
            "DurationMillis": 15007
        }
    ]
}
```

有关示例代码，请参阅[示例：检测存储视频中的分段](segment-example.md)。