

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 範例：Kinesis Video Streams 生產者 SDK GStreamer 外掛程式 - kvssink
<a name="examples-gstreamer-plugin"></a>

本主題說明如何建置 Amazon Kinesis Video Streams 生產者 SDK 以用作 GStreamer 外掛程式。

**Topics**
+ [下載、建置和設定 GStreamer 元素](#examples-gstreamer-plugin-download)
+ [執行 GStreamer 元素](#examples-gstreamer-plugin-run)
+ [GStreamer 啟動命令範例](#examples-gstreamer-plugin-launch)
+ [在 Docker 容器中執行 GStreamer 元素](#examples-gstreamer-plugin-docker)
+ [GStreamer 元素參數參考](examples-gstreamer-plugin-parameters.md)

[GStreamer](https://gstreamer.freedesktop.org/) 是多個攝影機和視訊來源使用的熱門媒體架構，可透過結合模組化外掛程式來建立自訂媒體管道。Kinesis Video Streams GStreamer 外掛程式可簡化現有 GStreamer 媒體管道與 Kinesis Video Streams 的整合。整合 GStreamer 之後，您可以將視訊從網路攝影機或即時串流通訊協定 (RTSP) 攝影機串流到 Kinesis Video Streams，以進行即時或更新版本的播放、儲存和進一步分析。

GStreamer 外掛程式會在 GStreamer 接收器元素 中封裝 Kinesis Video Streams 生產者 SDK 所提供的功能，以自動管理影片串流到 Kinesis Video Streams 的傳輸`kvssink`。GStreamer 架構提供標準受管的環境以建構媒體流量裝置，例如相機或其他影片來源以進行進一步的處理、轉譯或儲存。

GStreamer 管道通常包含來源 (攝影機) 和目的元素 (其中為呈現影片的播放器，或離線擷取的儲存) 之間的連結。在這個範例中，您使用製作者開發套件元素做為*目的*或媒體目的地，對於視訊來源 (網路攝影機或 IP 相機)。封裝 SDK 的外掛程式元素接著會將影片串流傳送至 Kinesis Video Streams。

本主題說明如何建構能夠從視訊來源串流視訊的 GStreamer 媒體管道，例如 Web 攝影機或 RTSP 串流，通常透過中繼編碼階段 （使用 H.264 編碼） 連接到 Kinesis Video Streams。當您的影片串流可作為 Kinesis 影片串流使用時，您可以使用 [使用剖析器程式庫監看攝影機的輸出](parser-library.md)進一步處理、播放、儲存或分析影片串流。

![\[以 GStreamer 媒體管道為串流視訊的功能檢視，從攝影機到 服務。\]](http://docs.aws.amazon.com/zh_tw/kinesisvideostreams/latest/dg/images/gstreamer-pipeline.png)


## 下載、建置和設定 GStreamer 元素
<a name="examples-gstreamer-plugin-download"></a>

GStreamer 外掛程式範例包含在 Kinesis Video Streams C\$1\$1 生產者 SDK 中。如需開發套件先決條件和下載的相關資訊，請參閱 [下載並設定 C\$1\$1 生產者程式庫程式碼](producersdk-cpp-download.md)。

您可以在 macOS、Ubuntu、Raspberry Pi 或 Windows 上將生產者 SDK GStreamer 接收器建置為動態程式庫。GStreamer 外掛程式位於您的 `build` 目錄中。若要載入此外掛程式，它必須位於您的 中`GST_PLUGIN_PATH`。執行以下命令：

```
export GST_PLUGIN_PATH=`pwd`/build
```

**注意**  
在 macOS 環境中，您只能在 Docker 容器內從網路攝影機執行 GStreamer 串流視訊。在 macOS 環境中不支援 Docker 容器內 USB 相機的串流視訊。

## 執行 GStreamer 元素
<a name="examples-gstreamer-plugin-run"></a>

若要使用 Kinesis Video Streams 生產者 SDK 元素作為接收器執行 GStreamer，請使用 `gst-launch-1.0`命令。使用適合 GStreamer 外掛程式使用的上游元素。例如，[v4l2src](https://gstreamer.freedesktop.org/documentation/video4linux2/v4l2src.html?gi-language=c#v4l2src-page) 適用於在 Linux 系統上的 v4l2 裝置，或 [rtspsrc](https://gstreamer.freedesktop.org/documentation/rtsp/rtspsrc.html#rtspsrc-page) 適用於 RTSP 裝置。指定 `kvssink` 做為目的 (最終目的地管道) 以傳送影片到製作者開發套件。

除了[提供登入](https://docs.aws.amazon.com//kinesisvideostreams/latest/dg/examples-gstreamer-plugin-parameters.html#credentials-to-kvssink)資料和[提供區域](https://docs.aws.amazon.com//kinesisvideostreams/latest/dg/examples-gstreamer-plugin-parameters.html#kvssink-region)之外， `kvssink`元素還具有下列必要參數：
+ `stream-name` – 目的地 Kinesis Video Streams 的名稱。

如需選用參數 `kvssink` 的詳細資訊，請參閱[GStreamer 元素參數參考](examples-gstreamer-plugin-parameters.md)。

如需 GStreamer 外掛程式和參數的最新資訊，請參閱 [GStreamer 外掛程式](https://gstreamer.freedesktop.org/documentation/plugins_doc.html?gi-language=c)。您也可以使用 `gst-inspect-1.0` 後面加上 GStreamer 元素或外掛程式的名稱來列印其資訊，並驗證裝置是否可用：

```
gst-inspect-1.0 kvssink
```

如果建置`kvssink`失敗或 GST\$1PLUGIN\$1PATH 未正確設定，您的輸出會如下所示：

```
No such element or plugin 'kvssink'
```

## GStreamer 啟動命令範例
<a name="examples-gstreamer-plugin-launch"></a>

下列範例示範如何使用 `kvssink` GStreamer 外掛程式從不同類型的裝置串流影片。

### 範例 1：從 Ubuntu 上的 RTSP 攝影機串流影片
<a name="examples-gstreamer-plugin-launch-ex1"></a>

下列命令是以 Ubuntu 環境從網路 RTSP 相機串流建立的 GStreamer 管道，使用 [rtspsrc](https://gstreamer.freedesktop.org/documentation/rtsp/rtspsrc.html?gi-language=c) GStreamer 外掛程式：

```
gst-launch-1.0 -v rtspsrc location="rtsp://YourCameraRtspUrl" short-header=TRUE ! rtph264depay ! h264parse ! kvssink stream-name="YourStreamName" storage-size=128
```

### 範例 2：從 Ubuntu 上的 USB 攝影機編碼和串流視訊
<a name="examples-gstreamer-plugin-launch-ex2"></a>

下列命令會在 Ubuntu 上建立 GStreamer 管道，以 H.264 格式從 USB 攝影機編碼串流，並將其串流至 Kinesis Video Streams。此範例使用 [v4l2src](https://gstreamer.freedesktop.org/documentation/video4linux2/v4l2src.html?gi-language=c#v4l2src-page) GStreamer 外掛程式。

```
gst-launch-1.0 v4l2src do-timestamp=TRUE device=/dev/video0 ! videoconvert ! video/x-raw,format=I420,width=640,height=480,framerate=30/1 ! x264enc  bframes=0 key-int-max=45 bitrate=500 ! video/x-h264,stream-format=avc,alignment=au,profile=baseline ! kvssink stream-name="YourStreamName" storage-size=512 access-key="YourAccessKey" secret-key="YourSecretKey" aws-region="YourAWSRegion"
```

### 範例 3：從 Ubuntu 上的 USB 攝影機串流預先編碼的影片
<a name="examples-gstreamer-plugin-launch-ex3"></a>

下列命令會在 Ubuntu 上建立 GStreamer 管道，將相機已編碼為 H.264 格式的影片串流至 Kinesis Video Streams。此範例使用 [v4l2src](https://gstreamer.freedesktop.org/documentation/video4linux2/v4l2src.html?gi-language=c#v4l2src-page) GStreamer 外掛程式。

```
gst-launch-1.0 v4l2src do-timestamp=TRUE device=/dev/video0 ! h264parse ! video/x-h264,stream-format=avc,alignment=au ! kvssink stream-name="plugin" storage-size=512 access-key="YourAccessKey" secret-key="YourSecretKey" aws-region="YourAWSRegion"
```

### 範例 4：從 macOS 上的網路攝影機串流視訊
<a name="examples-gstreamer-plugin-launch-ex4"></a>

下列命令會在 macOS 上建立 GStreamer 管道，將影片從網路攝影機串流至 Kinesis Video Streams。此範例使用 [rtspsrc](https://gstreamer.freedesktop.org/documentation/rtsp/rtspsrc.html#rtspsrc-page) GStreamer 外掛程式。

```
gst-launch-1.0 rtspsrc location="rtsp://YourCameraRtspUrl" short-header=TRUE ! rtph264depay ! h264parse ! video/x-h264, format=avc,alignment=au ! kvssink stream-name="YourStreamName" storage-size=512  access-key="YourAccessKey" secret-key="YourSecretKey" aws-region="YourAWSRegion"
```

### 範例 5：從 Windows 上的網路攝影機串流視訊
<a name="examples-gstreamer-plugin-launch-ex5"></a>

下列命令會在 Windows 上建立 GStreamer 管道，將影片從網路攝影機串流至 Kinesis Video Streams。此範例使用 [rtspsrc](https://gstreamer.freedesktop.org/documentation/rtsp/rtspsrc.html#rtspsrc-page) GStreamer 外掛程式。

```
gst-launch-1.0 rtspsrc location="rtsp://YourCameraRtspUrl" short-header=TRUE ! rtph264depay ! video/x-h264, format=avc,alignment=au ! kvssink stream-name="YourStreamName" storage-size=512  access-key="YourAccessKey" secret-key="YourSecretKey" aws-region="YourAWSRegion"
```

### 範例 6：從 Raspberry Pi 上的攝影機串流影片
<a name="examples-gstreamer-plugin-launch-ex6"></a>

下列命令會在 Raspberry Pi 上建立 GStreamer 管道，將影片串流至 Kinesis Video Streams。此範例使用 [v4l2src](https://gstreamer.freedesktop.org/documentation/video4linux2/v4l2src.html?gi-language=c#v4l2src-page) GStreamer 外掛程式。

```
gst-launch-1.0 v4l2src do-timestamp=TRUE device=/dev/video0 ! videoconvert ! video/x-raw,format=I420,width=640,height=480,framerate=30/1 ! omxh264enc control-rate=1 target-bitrate=5120000 periodicity-idr=45 inline-header=FALSE ! h264parse ! video/x-h264,stream-format=avc,alignment=au,width=640,height=480,framerate=30/1,profile=baseline ! kvssink stream-name="YourStreamName" access-key="YourAccessKey" secret-key="YourSecretKey" aws-region="YourAWSRegion"
```

### 範例 7：在 Raspberry Pi 和 Ubuntu 中串流音訊和視訊
<a name="examples-gstreamer-plugin-launch-ex7"></a>

請參閱如何[執行 gst-launch-1.0 命令，開始在 Raspberry-PI 和 Ubuntu 中串流音訊和視訊](https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp/blob/master/docs/linux.md#running-the-gst-launch-10-command-to-start-streaming-both-audio-and-video-in-raspberry-pi-and-ubuntu)。

### 範例 8：從 macOS 中的裝置來源串流音訊和視訊
<a name="examples-gstreamer-plugin-launch-ex8"></a>

請參閱如何[執行 gst-launch-1.0 命令，開始在 MacOS 中串流音訊和視訊](https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp/blob/master/docs/macos.md#running-the-gst-launch-10-command-to-start-streaming-both-audio-and-raw-video-in-mac-os)。

### 範例 9：上傳包含音訊和視訊的 MKV 檔案
<a name="examples-gstreamer-plugin-launch-ex9"></a>

了解如何[執行 gst-launch-1.0 命令以上傳包含音訊和視訊的 MKV 檔案](https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp/blob/master/docs/windows.md#running-the-gst-launch-10-command-to-upload-mkv-file-that-contains-both-audio-and-video)。您需要具有 h.264 和 AAC 編碼媒體的 MKV 測試檔案。

## 在 Docker 容器中執行 GStreamer 元素
<a name="examples-gstreamer-plugin-docker"></a>

Docker 是一種開發、部署和執行應用程式的使用容器平台。使用 Docker 建立 GStreamer 管道會將 Kinesis Video Streams 的操作環境標準化，以簡化應用程式的建置和使用。

要安裝與設定 Docker，請參閱以下內容：
+ [Docker 下載說明](https://docs.docker.com/engine/install/)
+ [Docker 入門](https://docs.docker.com/guides/getting-started/)

安裝 Docker 之後，您可以使用下列其中一個提供的`docker pull`命令，從 Amazon Elastic Container Registry 下載 Kinesis Video Streams C\$1\$1 Producer SDK （和 GStreamer 外掛程式）。

若要使用 Kinesis Video Streams 生產者 SDK 元素作為 Docker 容器中的接收器來執行 GStreamer，請執行下列動作：

**Topics**
+ [驗證您的 Docker 用戶端](#examples-gstreamer-plugin-docker-authenticate)
+ [下載 Ubuntu、macOS、Windows 或 Raspberry Pi 的 Docker 影像](#examples-gstreamer-plugin-docker-download)
+ [執行 Docker 映像](#examples-gstreamer-plugin-docker-run)

### 驗證您的 Docker 用戶端
<a name="examples-gstreamer-plugin-docker-authenticate"></a>

向打算提取映像的 Amazon ECR 登錄檔驗證您的 Docker 用戶端。您必須取得每個使用的登錄檔的身分驗證字符。字符的有效期為 12 小時。如需詳細資訊，請參閱《Amazon Elastic Container Registry 使用者指南》**中的[登錄檔身分驗證](https://docs.aws.amazon.com/AmazonECR/latest/userguide/Registries.html#registry_auth)。

**Example ：使用 Amazon ECR 進行身分驗證**  
若要使用 Amazon ECR 進行身分驗證，請複製並貼上下列命令，如下所示。  

```
sudo aws ecr get-login-password --region us-west-2 | docker login -u AWS --password-stdin https://546150905175.dkr.ecr.us-west-2.amazonaws.com
```
如果成功，輸出會顯示 `Login Succeeded`。

### 下載 Ubuntu、macOS、Windows 或 Raspberry Pi 的 Docker 影像
<a name="examples-gstreamer-plugin-docker-download"></a>

視您的作業系統而定，使用下列命令下載 Docker 影像到您的 Docker 環境：

#### 下載 Docker 影像到 Ubuntu 環境
<a name="examples-gstreamer-plugin-docker-download-ubuntu"></a>

```
sudo docker pull 546150905175.dkr.ecr.us-west-2.amazonaws.com/kinesis-video-producer-sdk-cpp-amazon-linux:latest
```

#### 下載 Docker 影像到 macOS
<a name="examples-gstreamer-plugin-docker-download-macos"></a>

```
docker pull 546150905175.dkr.ecr.us-west-2.amazonaws.com/kinesis-video-producer-sdk-cpp-amazon-linux:latest
```

#### 下載 Docker 影像到 Windows 環境
<a name="examples-gstreamer-plugin-docker-download-windows"></a>

```
docker pull 546150905175.dkr.ecr.us-west-2.amazonaws.com/kinesis-video-producer-sdk-cpp-amazon-windows:latest
```

#### 下載 Docker 影像到 Raspberry Pi
<a name="examples-gstreamer-plugin-docker-download-rpi"></a>

```
sudo docker pull 546150905175.dkr.ecr.us-west-2.amazonaws.com/kinesis-video-producer-sdk-cpp-raspberry-pi:latest
```

若要驗證已成功新增的影像，請執行下列命令：

```
docker images
```

### 執行 Docker 映像
<a name="examples-gstreamer-plugin-docker-run"></a>

視您的作業系統而定，使用下列其中一個命令執行 Docker 影像：

#### 在 Ubuntu 上執行 Docker 映像
<a name="examples-gstreamer-plugin-docker-run-ubuntu"></a>

```
sudo docker run -it --network="host" --device=/dev/video0 546150905175.dkr.ecr.us-west-2.amazonaws.com/kinesis-video-producer-sdk-cpp-amazon-linux /bin/bash
```

#### 在 macOS 上執行 Docker 映像
<a name="examples-gstreamer-plugin-docker-run-macos"></a>

```
sudo docker run -it --network="host" 546150905175.dkr.ecr.us-west-2.amazonaws.com/kinesis-video-producer-sdk-cpp-amazon-linux /bin/bash
```

#### 在 Windows 上執行 Docker 映像
<a name="examples-gstreamer-plugin-docker-run-windows"></a>

```
docker run -it 546150905175.dkr.ecr.us-west-2.amazonaws.com/kinesis-video-producer-sdk-cpp-windows AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY RTSP_URL STREAM_NAME
```

#### 在 Raspberry Pi 上執行 Docker 映像
<a name="examples-gstreamer-plugin-docker-run-rpi"></a>

```
sudo docker run -it --device=/dev/video0 --device=/dev/vchiq -v /opt/vc:/opt/vc 546150905175.dkr.ecr.us-west-2.amazonaws.com/kinesis-video-producer-sdk-cpp-raspberry-pi /bin/bash
```

Docker 會啟動容器，並顯示命令提示，讓您使用容器內的命令。

在容器中請使用下列命令來設定環境變數：

```
export LD_LIBRARY_PATH=/opt/awssdk/amazon-kinesis-video-streams-producer-sdk-cpp/kinesis-video-native-build/downloads/local/lib:$LD_LIBRARY_PATH
export PATH=/opt/awssdk/amazon-kinesis-video-streams-producer-sdk-cpp/kinesis-video-native-build/downloads/local/bin:$PATH
export GST_PLUGIN_PATH=/opt/awssdk/amazon-kinesis-video-streams-producer-sdk-cpp/kinesis-video-native-build/downloads/local/lib:$GST_PLUGIN_PATH
```

`kvssink` 使用 開始串流至 `gst-launch-1.0`，以執行適合您裝置和視訊來源的管道。如需管道範例，請參閱 [GStreamer 啟動命令範例](#examples-gstreamer-plugin-launch)。

# GStreamer 元素參數參考
<a name="examples-gstreamer-plugin-parameters"></a>

若要將影片傳送至 Amazon Kinesis Video Streams 生產者 C\$1\$1 SDK，您可以將 指定`kvssink`為管道的*目的地*或最終目的地。此參考提供有關必要的 `kvssink` 和選用參數的資訊。如需詳細資訊，請參閱[範例：Kinesis Video Streams 生產者 SDK GStreamer 外掛程式 - kvssink](examples-gstreamer-plugin.md)。

**主題**
+ [提供登入資料給 `kvssink`](#credentials-to-kvssink)
+ [提供區域給 `kvssink`](#kvssink-region)
+ [`kvssink` 選用參數](#kvssink-optional-parameters)

## 提供登入資料給 `kvssink`
<a name="credentials-to-kvssink"></a>

若要允許 `kvssink` GStreamer 元素向 發出請求 AWS，請在呼叫 Amazon Kinesis Video Streams 服務時提供 AWS 登入資料以供其使用。登入資料提供者鏈結會依下列順序尋找登入資料：

### 1. AWS IoT 憑證
<a name="collapsible-section-1"></a>

若要設定 AWS IoT 登入資料，請參閱 [使用 控制對 Kinesis Video Streams 資源的存取 AWS IoT](how-iot.md)。

`iot-credentials` 參數值必須以 開頭`iot-certificate,`，後面接著下列 *key*=*value* 對的逗號分隔清單。


****  

| 金錀 | 必要 | 描述 | 
| --- | --- | --- | 
| ca-path | 是 | 用於透過 TLS 與後端服務建立信任的 CA 憑證檔案路徑。 

**Example**  
**範例**：` /file/path/to/certificate.pem` | 
| cert-path | 是 | X.509 憑證的檔案路徑。 

**Example**  
**範例**：`/file/path/to/certificateID-certificate.pem.crt` | 
| endpoint | 是 | 您 AWS 帳戶的 AWS IoT Core 登入資料端點提供者端點。請參閱 [AWS IoT 開發人員指南](https://docs.aws.amazon.com//iot/latest/developerguide/authorizing-direct-aws.html)。 

**Example**  
**範例**：`credential-account-specific-prefix.credentials.iot.aws-region.amazonaws.com` | 
| key-path | 是 | 公有/私有金鑰對中使用的私有金鑰的檔案路徑。 

**Example**  
**範例**：`/file/path/to/certificateID-private.pem.key` | 
| role-aliases | 是 | 連線到 時，指向要使用之 AWS IAM 角色的角色別名名稱 AWS IoT Core。 

**Example**  
**範例**：`KvsCameraIoTRoleAlias` | 
| iot-thing-name | 否 | `iot-thing-name` 為選用。如果`iot-thing-name`未提供 ，則會使用 `stream-name` 參數值。 

**Example**  
**範例**：`kvs_example_camera` | 

**Example**  
**範例**：  

```
gst-launch-1.0 -v ... ! kvssink stream-name="YourStream" aws-region="YourRegion" iot-certificate="iot-certificate,endpoint=credential-account-specific-prefix.credentials.iot.aws-region.amazonaws.com,cert-path=certificateID-certificate.pem.crt,key-path=certificateID-private.pem.key,ca-path=certificate.pem,role-aliases=YourRoleAlias,iot-thing-name=YourThingName"
```

### 2. 環境變數
<a name="collapsible-section-2"></a>

若要讓 `kvssink`使用環境中的登入資料，請設定下列環境變數：


****  

| 環境變數名稱 | 必要 | 描述 | 
| --- | --- | --- | 
| AWS\$1ACCESS\$1KEY\$1ID | 是 | 用來存取 Amazon Kinesis Video Streams 的 AWS 存取金鑰。 | 
| AWS\$1SECRET\$1ACCESS\$1KEY | 是 | 與存取金鑰相關聯的 AWS 私密金鑰。 | 
| AWS\$1SESSION\$1TOKEN | 否 | 如果您直接從 AWS STS 操作使用臨時安全登入資料，請指定所需的工作階段字符值。 | 

設定環境變數會變更使用的數值，直到 Shell 工作階段結束或直到您將該變數設為其他數值。若要讓變數在未來的工作階段中持續存在，請在 shell 的啟動指令碼中設定它們。

### 3. `access-key`、 `secret-key` 參數
<a name="collapsible-section-3"></a>

若要直接指定登入資料做為`kvssink`參數，請設定下列參數：


****  

| `kvssink` 參數名稱 | 必要 | 描述 | 
| --- | --- | --- | 
| access-key | 是 | 用來存取 Amazon Kinesis Video Streams 的 AWS 存取金鑰。 | 
| secret-key | 是 | 與存取金鑰相關聯的 AWS 私密金鑰。 | 
| session-token | 否 | 如果您直接從 AWS STS 操作使用臨時安全登入資料，請指定所需的工作階段字符值。 | 

**Example**  
**使用靜態登入資料：**  

```
gst-launch-1.0 -v ... ! kvssink stream-name="YourStream" aws-region="YourRegion" access-key="AKIDEXAMPLE" secret-key="SKEXAMPLE"
```

**Example**  
**使用臨時登入資料：**  

```
gst-launch-1.0 -v ... ! kvssink stream-name="YourStream" aws-region="YourRegion" access-key="AKIDEXAMPLE" secret-key="SKEXAMPLE" session-token="STEXAMPLE"
```

### 4. 登入資料檔案
<a name="collapsible-section-4"></a>

**重要**  
如果您已選取上述其中一種方法，則無法使用 `credential-path` `kvssink` 參數。


****  

| `kvssink` 參數名稱 | 必要 | 描述 | 
| --- | --- | --- | 
| credential-path | 是 | 文字檔案的路徑，其中包含特定格式的登入資料。 | 

文字檔案必須包含下列其中一種格式的登入資料：
+ CREDENTIALS *YourAccessKey* *YourSecretKey*
+ CREDENTIALS *YourAccessKey* *過期* *YourSecretKey* *SessionToken*

**Example**  
**範例：**您的`credentials.txt`檔案位於 `/home/ubuntu`並包含下列項目：  
`CREDENTIALS AKIDEXAMPLE 2023-08-10T22:43:00Z SKEXAMPLE STEXAMPLE`  
若要在 中使用它`kvssink`，請輸入：  

```
gst-launch-1.0 -v ... ! kvssink stream-name="YourStream" aws-region="YourRegion" credential-path="/home/ubuntu/credentials.txt" 
```
過期時間應該至少為 5 \$1 30 \$1 3 = 未來 **38** 秒。寬限期在 中定義為 `IOT_CREDENTIAL_FETCH_GRACE_PERIOD`變數[https://github.com/awslabs/amazon-kinesis-video-streams-producer-c/blob/master/src/source/Common/IotCredentialProvider.h](https://github.com/awslabs/amazon-kinesis-video-streams-producer-c/blob/master/src/source/Common/IotCredentialProvider.h)。如果登入資料在您啟動 時太接近過期`kvssink`，您會收到錯誤碼 `0x52000049 - STATUS_INVALID_TOKEN_EXPIRATION`。
`kvssink` 不會修改登入資料檔案。如果您使用的是暫時登入資料，則必須在過期時間減去寬限期之前，由外部來源更新登入資料檔案。

## 提供區域給 `kvssink`
<a name="kvssink-region"></a>

以下是區域查詢順序：

1. `AWS_DEFAULT_REGION` 環境變數會先檢閱。如果已設定，則會使用該區域來設定用戶端。

1. `aws-region` 接下來會檢閱 參數。如果已設定，則會使用該區域來設定用戶端。

1. 如果之前的方法都未使用，則 `kvssink`預設為 `us-west-2`。

## `kvssink` 選用參數
<a name="kvssink-optional-parameters"></a>

`kvssink` 元素具有下列選用參數：如需這些參數的相關資訊，請參閱 [Kinesis 影片串流結構](producer-reference-structures-stream.md)。


****  

| 參數 | Description | 單位/類型 | 預設 | 
| --- | --- | --- | --- | 
| stream-name  | 目的地 Amazon Kinesis 視訊串流的名稱。 如果未指定串流名稱，將使用預設串流名稱：「DEFAULT\$1STREAM」。如果具有該預設名稱的串流尚不存在，則會建立該串流。  |  |  | 
| absolute-fragment-times | 是否使用絕對片段時間。 | Boolean | true | 
| access-key | 用來存取 Kinesis Video Streams 的 AWS 存取金鑰。 您必須設定 AWS 登入資料或提供此參數。若要提供此資訊，請輸入下列內容： <pre>export AWS_ACCESS_KEY_ID=</pre> |  |  | 
| avg-bandwidth-bps | 串流的預期平均頻寬。 | 每秒位元數 | 4194304 | 
| aws-region |  AWS 區域 要使用的 。  您也可以為區域提供 `AWS_DEFAULT_REGION`環境變數。如果同時設定環境變數和 kvssink 參數，則環境變數優先。   `us-west-2` 如果未另外指定，則區域預設為 。   | String | "us-west-2" | 
| buffer-duration | 串流緩衝持續時間。 | 秒鐘 | 120 | 
| codec-id | 串流的編解碼器 ID。 | String | "V\$1MPEG4/ISO/AVC" | 
| connection-staleness | 之後呼叫串流過時回呼的時間。 | 秒鐘 | 60 | 
| content-type | 串流的內容類型。 | String | "video/h264" | 
| fragment-acks | 發生錯誤時欲採取的動作。 | Boolean | true | 
| fragment-duration | 您需要的片段持續時間。 | 毫秒 | 2000 | 
| framerate | 預期的影格率。 | 每秒影格 | 25 | 
| frame-timecodes | 是否使用影格時間碼或者使用目前時間回呼產生時間戳記。 | Boolean | true | 
| key-frame-fragmentation | 是否在關鍵影格上產生片段。 | Boolean | true | 
| log-config | 日誌設定路徑。 | String | "../kvs\$1log\$1configuration" | 
| max-latency | 串流的最大延遲。 | 秒鐘 | 60 | 
| recalculate-metrics | 是否重新計算指標。 | Boolean | true | 
| replay-duration | 若發生錯誤啟用重新啟動時，則向後捲動目前閱讀器以重放的持續時間。 | 秒鐘 | 40 | 
| restart-on-error | 是否發生錯誤時重新啟動。 | Boolean | true | 
| retention-period | 串流是保留所需的時間。 | 小時 | 2 | 
| rotation-period | 金鑰輪換期間。如需詳細資訊，請參閱[輪換 AWS KMS 金鑰](https://docs.aws.amazon.com/kms/latest/developerguide/rotate-keys.html)。 | 秒鐘 | 3600 | 
| secret-key |  用來存取 Kinesis Video Streams 的 AWS 私密金鑰。 您必須設定 AWS 登入資料或提供此參數。 <pre>export AWS_SECRET_ACCESS_KEY=</pre>  |  |  | 
| session-token | 如果您直接從 AWS STS 操作使用臨時安全登入資料，請指定所需的工作階段字符值。 |  |  | 
| storage-size | 以 MB (MiB) 為單位的裝置儲存體大小。如需設定裝置儲存的詳細資訊，請參閱[StorageInfo](producer-reference-structures-producer.md#producer-reference-structures-producer-storageinfo)。 | Mebibyte (MiB) | 128 | 
| streaming-type | 串流類型。有效值包含：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/kinesisvideostreams/latest/dg/examples-gstreamer-plugin-parameters.html) | 列舉 GstKvsSinkStreamingType | 0：即時 | 
| timecode-scale | MKV 時間碼比例。 | 毫秒 | 1 | 
| track-name | MKV 音軌名稱。 | String | "kinesis\$1video" | 
| iot-certificate | AWS IoT 要在 `kvssink`元素中使用的登入資料。 `iot-certificate` 接受下列金鑰和值：  `iot-thing-name` 是**選用**的。如果`iot-thing-name`未提供 ，則會使用 `stream-name` 參數值。  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/kinesisvideostreams/latest/dg/examples-gstreamer-plugin-parameters.html) | String | 無 | 