

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

# 對 Kinesis Video Streams 進行故障診斷
<a name="troubleshooting"></a>

使用以下資訊對 Amazon Kinesis Video Streams 遇到的常見問題進行故障診斷。

**Topics**
+ [一般問題](#troubleshooting-general)
+ [API 問題](#troubleshooting-api)
+ [HLS 問題](#troubleshooting-hls)
+ [Java 問題](#troubleshooting-java)
+ [生產者程式庫問題](#troubleshooting-producer)
+ [串流剖析器程式庫問題](#troubleshooting-parser)
+ [網路問題](#troubleshooting-network)

## 一般問題
<a name="troubleshooting-general"></a>

本節說明使用 Kinesis Video Streams 時可能遇到的一般問題。

**Topics**
+ [延遲過高](#troubleshooting-general-latency)

### 延遲過高
<a name="troubleshooting-general-latency"></a>

延遲可能是由於傳送至 Kinesis Video Streams 服務的片段持續時間所致。減少生產者和服務之間延遲的方法之一是，設定媒體管道以產生較短的片段持續期間。

若要減少每個片段中傳送的影格數量，請在 中減少下列值`kinesis_video_gstreamer_sample_app.cpp`：

```
g_object_set(G_OBJECT (data.encoder), "bframes", 0, "key-int-max", 45, "bitrate", 512, NULL);
```

**注意**  
因為影片轉譯的內部實作，在 Mozilla Firefox 瀏覽器的延遲很嚴重。

## API 問題
<a name="troubleshooting-api"></a>

本節說明使用 Kinesis Video Streams 時可能遇到的 API 問題。

**Topics**
+ [錯誤：「未知的選項」](#troubleshooting-api-unknown-options)
+ [錯誤：「無法判斷要授權的服務/操作名稱」](#troubleshooting-api-name-auth)
+ [錯誤：「無法將影格放入串流」](#troubleshooting-api-putframe)
+ [錯誤：「服務在接收到最終 AckEvent 之前已關閉連線」](#troubleshooting-api-closeconnection)
+ [錯誤：「STATUS\$1STORE\$1OUT\$1OF\$1MEMORY」](#troubleshooting-api-storeoutofmemory)
+ [錯誤：「憑證應範圍限定為有效區域。」](#troubleshoot-api-credential)

### 錯誤：「未知的選項」
<a name="troubleshooting-api-unknown-options"></a>

`GetMedia` 和 `GetMediaForFragmentList` 可能會因為下列錯誤而失敗：

```
Unknown options: <filename>.mkv
```

如果您 AWS CLI 使用 `output`類型設定 ，則會發生此錯誤`json`。 AWS CLI 使用預設輸出類型 () 重新設定 `none`。如需設定 的詳細資訊 AWS CLI，請參閱《 *AWS CLI 命令參考*》中的[設定](https://docs.aws.amazon.com/cli/latest/reference/configure) 。

### 錯誤：「無法判斷要授權的服務/操作名稱」
<a name="troubleshooting-api-name-auth"></a>

`GetMedia` 可能會因為下列錯誤而失敗：

```
Unable to determine service/operation name to be authorized
```

若未正確指定端點，可能會發生此錯誤。當您取得端點時，請務必在`GetDataEndpoint`呼叫中包含下列參數，視要呼叫的 API 而定：

```
--api-name GET_MEDIA
--api-name PUT_MEDIA
--api-name GET_MEDIA_FOR_FRAGMENT_LIST
--api-name LIST_FRAGMENTS
```

### 錯誤：「無法將影格放入串流」
<a name="troubleshooting-api-putframe"></a>

`PutMedia` 可能會因為下列錯誤而失敗：

```
Failed to put a frame in the stream
```

若未將連線或權限提供給服務，可能會發生此錯誤。在 中執行下列項目 AWS CLI，並確認可以擷取串流資訊：

```
aws kinesisvideo describe-stream --stream-name StreamName --endpoint https://ServiceEndpoint.kinesisvideo.region.amazonaws.com
```

如果呼叫失敗，請參閱[故障診斷 AWS CLI 錯誤](https://docs.aws.amazon.com/cli/latest/userguide/troubleshooting.html)以取得詳細資訊。

### 錯誤：「服務在接收到最終 AckEvent 之前已關閉連線」
<a name="troubleshooting-api-closeconnection"></a>

`PutMedia` 可能會因為下列錯誤而失敗：

```
com.amazonaws.SdkClientException: Service closed connection before final AckEvent was received
```

如果 `PushbackInputStream` 未正確實作，可能會發生此錯誤。確認`unread()`方法已正確實作。

### 錯誤：「STATUS\$1STORE\$1OUT\$1OF\$1MEMORY」
<a name="troubleshooting-api-storeoutofmemory"></a>

`PutMedia` 可能會因為下列錯誤而失敗：

```
The content store is out of memory.
```

當內容存放區未分配足夠的大小時，將會發生此錯誤。若要提高內容存放區的大小，請提高 `StorageInfo.storageSize` 的值。如需詳細資訊，請參閱[StorageInfo](producer-reference-structures-producer.md#producer-reference-structures-producer-storageinfo)。

### 錯誤：「憑證應範圍限定為有效區域。」
<a name="troubleshoot-api-credential"></a>

如果簽署區域與端點區域不相符，就會發生此錯誤。

例如，如果您指定 `us-west-2`做為簽署區域，但嘗試連線到 `kinesisvideo.us-east-1.amazonaws.com`(`us-east-1`) 端點，則會收到此錯誤。

在某些應用程式中，例如 [kvssink](examples-gstreamer-plugin.md)，區域備用鏈預設為 `us-west-2`。確認您已根據您使用的應用程式正確設定您的區域。

## HLS 問題
<a name="troubleshooting-hls"></a>

如果您的影片串流未正確播放，請參閱 [故障診斷 HLS 問題](hls-playback.md#how-hls-ex1-ts)。

## Java 問題
<a name="troubleshooting-java"></a>

本節說明如何疑難排解使用 Kinesis Video Streams 時遇到的常見 Java 問題。

**Topics**
+ [啟用 Java 日誌](#troubleshooting-java-log)

### 啟用 Java 日誌
<a name="troubleshooting-java-log"></a>

若要疑難排解 Java 範例和程式庫的問題，啟用和檢查偵錯日誌會很有幫助。若要啟用偵錯日誌，請依下列步驟執行：

1. 將 `log4j` 新增至 `pom.xml``` 檔案，在 `dependencies` 節點中：

   ```
   <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
       <version>1.2.17</version>
   </dependency>
   ```

1. 在 `target/classes` 目錄中，建立名為 `log4j.properties` 的檔案，內含下列內容：

   ```
   # Root logger option
   log4j.rootLogger=DEBUG, stdout
   
   # Redirect log messages to console
   log4j.appender.stdout=org.apache.log4j.ConsoleAppender
   log4j.appender.stdout.Target=System.out
   log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
   log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
   
   log4j.logger.org.apache.http.wire=DEBUG
   ```

偵錯日誌將會列印到 IDE 主控台。

## 生產者程式庫問題
<a name="troubleshooting-producer"></a>

本節說明使用 [上傳至 Kinesis Video Streams](producer-sdk.md) 時可能遇到的問題。

**Topics**
+ [無法編譯生產者 SDK](#troubleshooting-producer-compile)
+ [影片串流不會顯示在主控台](#troubleshooting-producer-console)
+ [錯誤：使用 GStreamer 示範應用程式串流資料時「包含在請求中的安全字符無效」](#troubleshooting-producer-general-securitytoken)
+ [錯誤：「無法將影格提交到 Kinesis Video 用戶端」](#troubleshooting-producer-failed-frame-client)
+ [GStreamer 應用程式停止並在 OS X 上出現「串流停止，原因未交涉」訊息](#troubleshooting-producer-failed-stream-osx)
+ [在 Raspberry Pi 上的 GStreamer 示範中建立 Kinesis 影片用戶端時出現錯誤：「無法配置堆積」](#troubleshooting-producer-raspberrypi-heap)
+ [在 Raspberry Pi 上執行 GStreamer 示範時出現錯誤：「非法指示」](#troubleshooting-producer-raspberrypi-illegalinstruction)
+ [攝影機無法載入 Raspberry Pi](#troubleshooting-producer-raspberrypi-camera)
+ [在 macOS High Sierra 上找不到攝影機](#troubleshooting-producer-sierra-camera)
+ [在 macOS High Sierra 上編譯時找不到 jni.h 檔案](#troubleshooting-producer-sierra-compile)
+ [執行 GStreamer 示範應用程式時 Curl 錯誤](#troubleshooting-producer-curl)
+ [在 Raspberry Pi 執行時間的時間戳記/範圍聲明](#troubleshooting-producer-raspberrypi-timestamp-assert)
+ [在 Raspberry Pi 上的 gst\$1value\$1set\$1fraction\$1range\$1full 聲明](#troubleshooting-producer-raspberrypi-gst-assert)
+ [在 Android 上發生 STATUS\$1MKV\$1INVALID\$1ANNEXB\$1NALU\$1IN\$1FRAME\$1DATA (0x3200000d) 錯誤](#troubleshooting-producer-android-invalid-annexb)
+ [已達到片段持續時間上限錯誤](#troubleshooting-producer-maxfragmentduration)
+ [使用 IoT 授權時的「傳遞的物件名稱無效」錯誤](#troubleshooting-producer-thingname)

### 無法編譯生產者 SDK
<a name="troubleshooting-producer-compile"></a>

確認您的路徑中有所需的程式庫。若要確認，請使用下列命令：

```
env | grep LD_LIBRARY_PATH
LD_LIBRARY_PATH=/home/local/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp/kinesis-video-native-build/downloads/local/lib
```

### 影片串流不會顯示在主控台
<a name="troubleshooting-producer-console"></a>

若要在主控台顯示您的視訊串流，必須使用 AvCC 格式中的 H.264 編碼。如果您的串流不會顯示，請確認以下資訊：
+ 如果原始串流為 Annex-B 格式，您的 [NAL 適應旗標](producer-reference-nal.md) 已設定為 `NAL_ADAPTATION_ANNEXB_NALS | NAL_ADAPTATION_ANNEXB_CPD_NALS`。這是 `StreamDefinition` 建構函數中的預設值。
+ 您提供正確的轉碼器私有資料。對於 H.264，這是序列參數集 (SPS) 和圖片參數集 (PPS)。根據您的媒體資料來源，此資料可能會從媒體來源單獨擷取或編碼到框架。

  許多基礎串流為以下格式，其中的 `Ab` 是 Annex-B 起始碼 (001 或 0001)：

  ```
  Ab(Sps)Ab(Pps)Ab(I-frame)Ab(P/B-frame) Ab(P/B-frame)…. Ab(Sps)Ab(Pps)Ab(I-frame)Ab(P/B-frame) Ab(P/B-frame)
  ```

  如果 H.264 作為 SPS 和 PPS 在串流中，CPD （編解碼器私有資料） 可以適應 AvCC 格式。除非媒體管道單獨提供 CPD，否則應用程式可以透過尋找第一個 Idr 影格 （應包含 SPS 和 PPS) 從影格擷取 CPD，擷取兩個 NALUs（將為 Ab(Sps)Ab(Pps))，並在 中的 CPD 中設定它`StreamDefinition`。

### 錯誤：使用 GStreamer 示範應用程式串流資料時「包含在請求中的安全字符無效」
<a name="troubleshooting-producer-general-securitytoken"></a>

如果發生此錯誤，表示您的登入資料有問題。請確認下列內容：
+ 如果您使用臨時的登入資料，必須指定工作階段字符。
+ 確認您的臨時登入資料並未過期。
+ 確認您已設定適當的權利。
+ 在 macOS 上，確認您沒有在鑰匙圈中快取登入資料。

### 錯誤：「無法將影格提交到 Kinesis Video 用戶端」
<a name="troubleshooting-producer-failed-frame-client"></a>

如果發生此錯誤，表示來源串流中的時間戳記未正確設定。請嘗試以下做法：
+ 使用最新的軟體開發套件範例，其中可能有更新可修正您的問題。
+ 將高品質串流設定為較高的位元速率，並在攝影機支援時修正來源串流中的任何抖動。

### GStreamer 應用程式停止並在 OS X 上出現「串流停止，原因未交涉」訊息
<a name="troubleshooting-producer-failed-stream-osx"></a>

串流可能會在 OS X 上停止並出現以下訊息：

```
Debugging information: gstbasesrc.c(2939): void gst_base_src_loop(GstPad *) (): /GstPipeline:test-pipeline/GstAutoVideoSrc:source/GstAVFVideoSrc:source-actual-src-avfvide:
streaming stopped, reason not-negotiated (-4)
```

可能的解決方法是從 中的`gst_caps_new_simple`呼叫中移除影格率參數`kinesis_video_gstreamer_sample_app.cpp`：

```
GstCaps *h264_caps = gst_caps_new_simple("video/x-h264",
                                             "profile", G_TYPE_STRING, "baseline",
                                             "stream-format", G_TYPE_STRING, "avc",
                                             "alignment", G_TYPE_STRING, "au",
                                             "width", GST_TYPE_INT_RANGE, 320, 1920,
                                             "height", GST_TYPE_INT_RANGE, 240, 1080,
                                             "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, 30, 1,
                                             NULL);
```

### 在 Raspberry Pi 上的 GStreamer 示範中建立 Kinesis 影片用戶端時出現錯誤：「無法配置堆積」
<a name="troubleshooting-producer-raspberrypi-heap"></a>

GStreamer 範例應用程式嘗試配置 512 MB 的 RAM，但您的系統可能無法提供。您可以降低以下 `KinesisVideoProducer.cpp` 中的值以降低此配置：

```
device_info.storageInfo.storageSize = 512 * 1024 * 1024;
```

### 在 Raspberry Pi 上執行 GStreamer 示範時出現錯誤：「非法指示」
<a name="troubleshooting-producer-raspberrypi-illegalinstruction"></a>

如果您在執行 GStreamer 示範時遇到下列錯誤，請確認您已編譯應用程式的正確版本的裝置。（例如，當您在 Raspberry Pi 2 上執行 時，請確認您沒有為 Raspberry Pi 3 編譯。)

```
INFO - Initializing curl.
Illegal instruction
```

### 攝影機無法載入 Raspberry Pi
<a name="troubleshooting-producer-raspberrypi-camera"></a>

若要檢查是否已載入攝影機，請執行下列動作：

```
ls /dev/video*
```

若未發現任何結果，請執行下列動作：

```
vcgencmd get_camera
```

輸出格式應類似以下內容：

```
supported=1 detected=1
```

如果驅動程式未偵測到攝影機，請執行下列動作：

1. 檢查實體攝影機設定並確認正確連接。

1. 執行以下動作以升級韌體：

   ```
   sudo rpi-update
   ```

1. 重新啟動裝置。

1. 執行以下動作以載入驅動程式：

   ```
   sudo modprobe bcm2835-v4l2
   ```

1. 確認已偵測到攝影機：

   ```
   ls /dev/video*
   ```

### 在 macOS High Sierra 上找不到攝影機
<a name="troubleshooting-producer-sierra-camera"></a>

在 macOS High Sierra 上，示範應用程式找不到攝影機 (如果有多個攝影機)。

### 在 macOS High Sierra 上編譯時找不到 jni.h 檔案
<a name="troubleshooting-producer-sierra-compile"></a>

若要解決這個錯誤，請將您安裝的 Xcode 更新到最新版本。

### 執行 GStreamer 示範應用程式時 Curl 錯誤
<a name="troubleshooting-producer-curl"></a>

若要解決當您執行 GStreamer 示範應用程式時 curl 錯誤，請將 [此憑證檔案](https://www.amazontrust.com/repository/SFSRootCAG2.pem)複製至 `/etc/ssl/cert.pem`。

### 在 Raspberry Pi 執行時間的時間戳記/範圍聲明
<a name="troubleshooting-producer-raspberrypi-timestamp-assert"></a>

如果在執行時間發生時間戳記聲明，請更新韌體並重新啟動裝置：

```
sudo rpi-update 
$ sudo reboot
```

### 在 Raspberry Pi 上的 gst\$1value\$1set\$1fraction\$1range\$1full 聲明
<a name="troubleshooting-producer-raspberrypi-gst-assert"></a>

如果 `uv4l` 服務正在執行，將會顯示以下聲明：

```
gst_util_fraction_compare (numerator_start, denominator_start, numerator_end, denominator_end) < 0' failed
```

如果發生這種情況，請停止 `uv4l` 服務並重新啟動應用程式。

### 在 Android 上發生 STATUS\$1MKV\$1INVALID\$1ANNEXB\$1NALU\$1IN\$1FRAME\$1DATA (0x3200000d) 錯誤
<a name="troubleshooting-producer-android-invalid-annexb"></a>

如果媒體串流的 [NAL 適應旗標](producer-reference-nal.md)​ 不正確，則會顯示以下錯誤：

```
putKinesisVideoFrame(): Failed to put a frame with status code 0x3200000d
```

如果發生此錯誤，請提供媒體的正確 `.withNalAdaptationFlags`​ 旗標 (例如，`NAL_ADAPTATION_ANNEXB_CPD_NALS`​)。在以下 [Android](producer-sdk-android.md) 一行中提供此旗標：

[ https://github.com/awslabs/aws-sdk-android-samples/blob/master/AmazonKinesisVideoDemoApp/src/main/java/com/amazonaws/kinesisvideo/demoapp/fragment/StreamConfigurationFragment.java\$1L169](https://github.com/awslabs/aws-sdk-android-samples/blob/master/AmazonKinesisVideoDemoApp/src/main/java/com/amazonaws/kinesisvideo/demoapp/fragment/StreamConfigurationFragment.java#L169)

### 已達到片段持續時間上限錯誤
<a name="troubleshooting-producer-maxfragmentduration"></a>

此錯誤會在串流中的媒體片段超過片段持續時間上限時發生。請參閱 [媒體和封存媒體 API 服務配額](limits.md#limits-akv-data)區段中的片段持續時間上限。

請嘗試下列方法解決此問題：
+ 如果您使用的是網路攝影機/USB 攝影機，請執行以下其中一項：
  + 如果您使用金鑰影格型分段，請將編碼器設定為在 10 秒內提供金鑰影格。
  + 如果您不是使用金鑰影格型分段，則在 中定義串流時[撰寫並檢查程式碼](producersdk-cpp-write.md)，請將片段持續時間上限設定為小於 10 秒的值。
  + 如果您在 GStreamer 管道中使用軟體編碼器 （例如 x264)，您可以在 10 秒內將 key-int-max 屬性設定為值。例如，將 key-int-max 設定為 60，fps 設定為 30，以每 2 秒啟用金鑰影格。
+ 如果您使用的是 RPI 攝影機，請將關鍵影格間隔屬性設定為小於 10 秒。
+ 如果您使用的是 IP (RTSP) 攝影機，請將 GOP 大小設定為 60。

### 使用 IoT 授權時的「傳遞的物件名稱無效」錯誤
<a name="troubleshooting-producer-thingname"></a>

若要在使用 IoT 登入資料進行授權時避免此錯誤 (`HTTP Error 403: Response: {"message":"Invalid thing name passed"}`)，請確定 的值 `stream-name`( `kvssink` 元素的必要參數） 與 的值相同`iot-thingname`。如需詳細資訊，請參閱[GStreamer 元素參數參考](examples-gstreamer-plugin-parameters.md)。

## 串流剖析器程式庫問題
<a name="troubleshooting-parser"></a>

本節說明使用 [使用剖析器程式庫進行串流](parser-library.md) 時可能遇到的問題。

**Topics**
+ [無法從串流存取單一影格](#troubleshooting-parser-frame)
+ [片段解碼錯誤](#troubleshooting-parser-fragment)

### 無法從串流存取單一影格
<a name="troubleshooting-parser-frame"></a>

若要從消費者應用程式中的串流來源存取單一影格，請確認您的串流包含正確的轉碼器私有資料。如需有關串流資料格式的詳細資訊，請參閱 [資料模型](how-data.md)。

若要了解如何使用轉碼器私有資料存取影格的詳細資訊，請參閱 GitHub 網站上的以下測試檔案：[KinesisVideoRendererExampleTest.java](https://github.com/aws/amazon-kinesis-video-streams-parser-library/blob/master/src/test/java/com/amazonaws/kinesisvideo/parser/examples/KinesisVideoRendererExampleTest.java)

### 片段解碼錯誤
<a name="troubleshooting-parser-fragment"></a>

如果您的片段未以瀏覽器支援的 H.264 格式和層級正確地編碼，當您在主控台播放串流時，可能會看到以下錯誤：

```
Fragment Decoding Error
There was an error decoding the video data. Verify that the stream contains valid H.264 content
```

如果發生這種情況，請檢查下列各項：
+ 影格的解析度符合轉碼器私有資料中指定的解析度。
+ 編碼影格的 H.264 設定檔和層級符合轉碼器私有資料中指定的設定檔和層級。
+ 瀏覽器支援設定檔/層級組合。大多數目前的瀏覽器皆支援所有設定檔和層級組合。
+ 時間戳記準確並且順序正確，並且未建立重複的時間戳記。
+ 您的應用程式使用 H.264 格式編碼影格資料。

## 網路問題
<a name="troubleshooting-network"></a>

如果您在嘗試連線至 Kinesis Video Streams 時看到連線錯誤，例如「連線逾時」或「連線失敗」，這可能是因為您聯網設定中的 IP 地址範圍限制所致。

如果您的設定具有 Kinesis Video Streams 的 IP 地址範圍限制，請更新您的網路組態以允許列出 Kinesis Video Streams [IP 地址範圍](https://ip-ranges.amazonaws.com/ip-ranges.json)。

**重要**  
IP 範圍清單不是 Kinesis Video Streams IP 地址的完整清單。包含您看到的 IP 地址範圍，並請注意 IP 地址可能會隨著時間而變更。

如需詳細資訊，請參閱 [AWS IP 範圍](https://docs.aws.amazon.com//vpc/latest/userguide/aws-ip-ranges.html)。若要在 IP 範圍變更時收到通知，請遵循[訂閱程序](https://docs.aws.amazon.com//vpc/latest/userguide/aws-ip-ranges.html#subscribe-notifications)。