LoginSignup
2
4

More than 1 year has passed since last update.

MacのインカメラをGStreamerでKinesis Video Streamに配信し、それをGStreamerで受信する方法

Last updated at Posted at 2021-11-17

GStreamer難しいですね...
gst-launchとの長き戦い - Qiita の通りだなと。

メモがてらMacのインカメラをGStreamerでKinesis Video Stream(KVS)に配信し、それをGStreamerで受信するコマンドを書きます。

MacのインカメラをGStreamerでKinesis Video Streamに配信するコマンドは下記です。

kvssink.sh
gst-launch-1.0 -v avfvideosrc \
! clockoverlay font-desc="Sans bold 60px" \
! videorate \
! video/x-raw,framerate=1/1 \
! vtenc_h264_hw allow-frame-reordering=FALSE realtime=TRUE max-keyframe-interval=2 bitrate=512  \
! h264parse \
! video/x-h264,stream-format=avc,alignment=au \
! kvssink stream-name="test-instream" storage-size=512 \
    access-key="${AWS_ACCESS_KEY_ID}" \
    secret-key="${AWS_SECRET_ACCESS_KEY}" \
    aws-region="${AWS_REGION}" \
    frame-timecodes=true \
    framerate=1

KVSをGStreamerで受信する方法は下記です。

hls.sh
STREAM_NAME=test-instream
ENDPOINT_URL=$(aws kinesisvideo get-data-endpoint \
    --stream-name ${STREAM_NAME} \
    --api-name GET_HLS_STREAMING_SESSION_URL \
    | jq -r '.DataEndpoint')
HLS_URL=$(aws kinesis-video-archived-media get-hls-streaming-session-url \
    --endpoint ${ENDPOINT_URL} \
    --stream-name ${STREAM_NAME} | jq -r '.HLSStreamingSessionURL' )

echo ${HLS_URL}

gst-launch-1.0 souphttpsrc location=${HLS_URL} do-timestamp=true is-live=true  \
! hlsdemux \
! decodebin \
! clockoverlay halignment=right valignment=top font-desc="Sans bold 60px" \
! autovideosink sync=false

既に8秒くらい遅延してますね...
mac-kvs-mac.png

ネットワーク環境が悪いのかhlsdemuxなど時間かかっているのか、、難しいですね。。

AWSのblackbeltでも原因調査方法が紹介されてます。
latency.png

しかし難しいので、この遅延を改善する方法をstackoverflowで質問してます。
python - How to reduce the gstreamer pipeline latency in "AWS Kinesis Video Stream(kvs) -> gstreamer+opencv image processing -> kvs " process? - Stack Overflow

回答はおそらくないので、自分で解決するしかなさそうですね ^^;
GStreamerに強くなりたい今日この頃です。

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4