awslabs / amazon-kinesis-video-streams-producer-sdk-cpp

Amazon Kinesis Video Streams Producer SDK for C++ is for developers to install and customize for their connected camera and other devices to securely stream video, audio, and time-encoded data to Kinesis Video Streams.
Apache License 2.0
379 stars 334 forks source link

[QUESTION] Raspberry Pi からの映像送信でエラーが発生 #1155

Closed tama7777-hub closed 8 months ago

tama7777-hub commented 8 months ago

私は現在、Raspberry Pi4からawskvsに映像の送信を行おうとしています。dockerを使用せずRaspberry Pi4に直接必要なものをインストールしています。 Raspberry Pi4でRTSPサーバーを起動しています。 エラーが発生してしまいうまく送信できません。 この解決策を求めています

送信は以下のコードで行っています。

設定したパス

ras-pi@raspberrypi2:~/kinesis_video/amazon-kinesis-video-streams-producer-sdk-cpp/samples $ export LD_LIBRARY_PATH=/home/ras-pi/kinesis_video/amazon-kinesis-video-streams-producer-sdk-cpp/open-source/local/lib ras-pi@raspberrypi2:~/kinesis_video/amazon-kinesis-video-streams-producer-sdk-cpp/samples $ export GST_PLUGIN_PATH=/home/ras-pi/kinesis_video/amazon-kinesis-video-streams-producer-sdk-cpp/build

送信コード

import cv2 import os import time

環境変数から設定を取得

STREAM_NAME = os.getenv('STREAM_NAME', '') RTSP_URL = os.getenv('RTSP_URL', '')

AWS_DEFAULT_REGION = os.getenv('AWS_DEFAULT_REGION', 'ap-northeast-1') AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID', '') AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY', '')

STREAM_FPS = os.getenv('STREAM_FPS', 10) WIDTH = os.getenv('WIDTH', 640) HEIGHT = os.getenv('HEIGHT', 480) STREAM_SIZE = (WIDTH, HEIGHT)

print("Start camera")

入力ストリーム

gst_cap_str : str = ' ! '.join([ f'rtspsrc location={RTSP_URL} latency=300', 'decodebin', 'videoconvert', 'video/x-raw,format=BGR', 'appsink drop=1' ]) cap = cv2.VideoCapture(gst_cap_str, cv2.CAP_GSTREAMER)

出力ストリーム

gst_out_str : str = ' ! '.join([ 'appsrc', 'videoconvert', f'x264enc bframes=1 key-int-max={STREAM_FPS} bitrate=1024', 'video/x-h264,stream-format=avc,alignment=au', f'kvssink stream-name={STREAM_NAME} storage-size=128 access-key={AWS_ACCESS_KEY_ID} secret-key={AWS_SECRET_ACCESS_KEY} aws-region={AWS_DEFAULT_REGION}' ])

out = cv2.VideoWriter( gst_out_str, cv2.CAP_GSTREAMER, # 出力形式 STREAM_FPS, # フレームレート STREAM_SIZE, # フレームサイズ True # isColor )

while True: start = time.perf_counter() ret, frame = cap.read() # 画像を取得 if ret:
resized_frame = cv2.resize(frame, STREAM_SIZE) out.write(resized_frame) # 画像を出力 else: print("Can't receive frame (stream end?).") frame_time = time.perf_counter() - start

fpsにあわせて時間調整

time.sleep(max(1.0/STREAM_FPS-frame_time, 0))

エラー内容

ras-pi@raspberrypi2:~/kinesis_video/amazon-kinesis-video-streams-producer-sdk-cpp/samples $ python kvs2.py Start camera [ WARN:0@1.201] global cap_gstreamer.cpp:1697 open OpenCV | GStreamer warning: unable to query duration of stream [ WARN:0@1.201] global cap_gstreamer.cpp:1728 open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1 [INFO ] [20-03-2024 10:49:34:121.558 GMT] Logger config being used: ../kvs_log_configuration [INFO ] [20-03-2024 10:49:34:121.889 GMT] User agent string: AWS-SDK-KVS-CPP-CLIENT/3.4.1 [INFO ] [20-03-2024 10:49:34:124.441 GMT] createKinesisVideoClient(): Creating Kinesis Video Client [INFO ] [20-03-2024 10:49:34:124.695 GMT] heapInitialize(): Initializing native heap with limit size 134217728, spill ratio 0% and flags 0x00000001 [INFO ] [20-03-2024 10:49:34:124.745 GMT] heapInitialize(): Creating AIV heap. [INFO ] [20-03-2024 10:49:34:124.906 GMT] heapInitialize(): Heap is initialized OK [DEBUG] [20-03-2024 10:49:34:125.312 GMT] getSecurityTokenHandler invoked [DEBUG] [20-03-2024 10:49:34:125.431 GMT] Refreshing credentials. Force refreshing: 0 Now time is: 1710931774125412767 Expiration: 0 [INFO ] [20-03-2024 10:49:34:125.505 GMT] createDeviceResultEvent(): Create device result event. [DEBUG] [20-03-2024 10:49:34:125.556 GMT] clientReadyHandler invoked [INFO ] [20-03-2024 10:49:34:125.768 GMT] Try creating stream for Fukuyama [INFO ] [20-03-2024 10:49:34:125.902 GMT] Creating Kinesis Video Stream Fukuyama [INFO ] [20-03-2024 10:49:34:125.963 GMT] createKinesisVideoStream(): Creating Kinesis Video Stream. [INFO ] [20-03-2024 10:49:34:126.011 GMT] logStreamInfo(): SDK version: de4299f942bb89c867d0dc73aeb4bc875d560a8f [DEBUG] [20-03-2024 10:49:34:126.045 GMT] logStreamInfo(): Kinesis Video Stream Info [DEBUG] [20-03-2024 10:49:34:126.078 GMT] logStreamInfo(): Stream name: Fukuyama [DEBUG] [20-03-2024 10:49:34:126.114 GMT] logStreamInfo(): Streaming type: STREAMING_TYPE_REALTIME [DEBUG] [20-03-2024 10:49:34:126.150 GMT] logStreamInfo(): Content type: video/h264 [DEBUG] [20-03-2024 10:49:34:126.188 GMT] logStreamInfo(): Max latency (100ns): 600000000 [DEBUG] [20-03-2024 10:49:34:126.224 GMT] logStreamInfo(): Fragment duration (100ns): 20000000 [DEBUG] [20-03-2024 10:49:34:126.261 GMT] logStreamInfo(): Key frame fragmentation: Yes [DEBUG] [20-03-2024 10:49:34:126.296 GMT] logStreamInfo(): Use frame timecodes: Yes [DEBUG] [20-03-2024 10:49:34:126.332 GMT] logStreamInfo(): Absolute frame timecodes: Yes [DEBUG] [20-03-2024 10:49:34:126.368 GMT] logStreamInfo(): Nal adaptation flags: 0 [DEBUG] [20-03-2024 10:49:34:126.405 GMT] logStreamInfo(): Average bandwidth (bps): 4194304 [DEBUG] [20-03-2024 10:49:34:126.441 GMT] logStreamInfo(): Framerate: 25 [DEBUG] [20-03-2024 10:49:34:126.477 GMT] logStreamInfo(): Buffer duration (100ns): 1200000000 [DEBUG] [20-03-2024 10:49:34:126.513 GMT] logStreamInfo(): Replay duration (100ns): 400000000 [DEBUG] [20-03-2024 10:49:34:126.551 GMT] logStreamInfo(): Connection Staleness duration (100ns): 600000000 [DEBUG] [20-03-2024 10:49:34:126.587 GMT] logStreamInfo(): Store Pressure Policy: 1 [DEBUG] [20-03-2024 10:49:34:126.622 GMT] logStreamInfo(): View Overflow Policy: 1 [DEBUG] [20-03-2024 10:49:34:126.658 GMT] logStreamInfo(): Allow stream creation: Yes [DEBUG] [20-03-2024 10:49:34:126.694 GMT] logStreamInfo(): Segment UUID: NULL [DEBUG] [20-03-2024 10:49:34:126.730 GMT] logStreamInfo(): Frame ordering mode: 0 [DEBUG] [20-03-2024 10:49:34:126.766 GMT] logStreamInfo(): Track list [DEBUG] [20-03-2024 10:49:34:126.799 GMT] logStreamInfo(): Track id: 1 [DEBUG] [20-03-2024 10:49:34:126.835 GMT] logStreamInfo(): Track name: kinesis_video [DEBUG] [20-03-2024 10:49:34:126.871 GMT] logStreamInfo(): Codec id: V_MPEG4/ISO/AVC [DEBUG] [20-03-2024 10:49:34:126.906 GMT] logStreamInfo(): Track type: TRACK_INFO_TYPE_VIDEO [DEBUG] [20-03-2024 10:49:34:127.042 GMT] logStreamInfo(): Track cpd: NULL [INFO ] [20-03-2024 10:49:34:311.832 GMT] writeHeaderCallback(): RequestId: 543dfb74-697a-4826-9186-9ac5d5292825 [DEBUG] [20-03-2024 10:49:34:312.226 GMT] describeStreamCurlHandler(): [] DescribeStream API response: {"StreamInfo":{"CreationTime":1.702380527076E9,"DataRetentionInHours":2,"DeviceName":"Kinesis_Video_Device","IngestionConfiguration":null,"KmsKeyId":"arn:aws:kms:ap-northeast-1:924500117297:alias/aws/kinesisvideo","MediaType":"video/h264","Status":"ACTIVE","StreamARN":"arn:aws:kinesisvideo:ap-northeast-1:924500117297:stream/Fukuyama/1702380527076","StreamName":"Fukuyama","Version":"HmJs5nYvINIvxXlFQ1Ae"}} [INFO ] [20-03-2024 10:49:34:314.243 GMT] describeStreamResultEvent(): Describe stream result event. [INFO ] [20-03-2024 10:49:34:510.144 GMT] writeHeaderCallback(): RequestId: 3bb44995-0b5f-4eab-93d5-7ee7e6f9441b [DEBUG] [20-03-2024 10:49:34:510.369 GMT] getStreamingEndpointCurlHandler(): [Fukuyama] GetStreamingEndpoint API response: {"DataEndpoint":"https://s-96e4f3e9.kinesisvideo.ap-northeast-1.amazonaws.com"} [INFO ] [20-03-2024 10:49:34:512.510 GMT] getStreamingEndpointResultEvent(): Get streaming endpoint result event. [DEBUG] [20-03-2024 10:49:34:512.703 GMT] getStreamingTokenHandler invoked [DEBUG] [20-03-2024 10:49:34:512.760 GMT] Refreshing credentials. Force refreshing: 1 Now time is: 1710931774512750006 Expiration: 18446744073709551615 [INFO ] [20-03-2024 10:49:34:512.848 GMT] getStreamingTokenResultEvent(): Get streaming token result event. [DEBUG] [20-03-2024 10:49:34:512.912 GMT] streamReadyHandler invoked Stream is ready

(python:2498): GStreamer-CRITICAL **: 19:50:07.965: gst_sample_get_caps: assertion 'GST_IS_SAMPLE (sample)' failed [ERROR:0@35.077] global cap_gstreamer.cpp:925 retrieveVideoFrame GStreamer: gst_sample_get_caps() returns NULL Can't receive frame (stream end?).

(python:2498): GStreamer-CRITICAL **: 19:50:37.966: gst_sample_get_caps: assertion 'GST_IS_SAMPLE (sample)' failed [ERROR:0@65.078] global cap_gstreamer.cpp:925 retrieveVideoFrame GStreamer: gst_sample_get_caps() returns NULL Can't receive frame (stream end?).

(python:2498): GStreamer-CRITICAL **: 19:51:07.967: gst_sample_get_caps: assertion 'GST_IS_SAMPLE (sample)' failed [ERROR:0@95.079] global cap_gstreamer.cpp:925 retrieveVideoFrame GStreamer: gst_sample_get_caps() returns NULL Can't receive frame (stream end?).

(python:2498): GStreamer-CRITICAL **: 19:51:37.967: gst_sample_get_caps: assertion 'GST_IS_SAMPLE (sample)' failed [ERROR:0@125.079] global cap_gstreamer.cpp:925 retrieveVideoFrame GStreamer: gst_sample_get_caps() returns NULL Can't receive frame (stream end?).