AWS Kinesis video stream for live video. Part 1 — Producer

Diana Lisovenko
beewise-engineering
4 min readApr 27, 2021

If you have AWS stack on your project and necessity to show live video from camera in you application — AWS kinesis video stream will ideally fit your needs. AWS offers services to capture, parse and store video streams for million of devices with low-latency in real time. Here AWS provides a bit more information how it works.

In order to start working with the stream we will have to set up:

  1. Producer — our input device which will capture video (linux machine, raspberry pi with camera).
  2. Consumer — Our service which will process and displays video stream to the user.

Producer set up and stream creation

Let’s start with creating stream in AWS account. Select AWS Kinesis Video and hit Create button

Give unique name to the stream, note that 1 producer(device) has one dedicated video stream. Default configurations will automatically set Data retention — 24 h. (how much time video is saved in account). Custom configurations allow you reduce time. Note that you have to set at least 1 h. to make video available.

Creating video stream

Now let’s get back to producer set up. In testing purposes I used my Macbook webcam to stream video. Here is detailed guide how to installAmazon Kinesis Video Streams Producer SDK for C/C++ on your machine

For Mac simply clone git repository locally navigate to the repository and create build directory inside.

git clone https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp.git

Note that for further steps you have to have brew preinstalled https://brew.sh/. With brew package manager we install cmake, openssl, gstreamer and other plugins

brew install pkg-config openssl cmake gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly log4cplus gst-libav

Once installed include JNI and Building GStreamer Sample Programs running next commands in the /build directory of SDK.
cmake -DBUILD_GSTREAMER_PLUGIN=TRUE ..

Compile the app

make

Load the application

export GST_PLUGIN_PATH=`pwd`/build
export LD_LIBRARY_PATH=`pwd`/open-source/local/lib

Now if you execute gst-inspect-1.0 kvssink you should get information on the plugin like

if you get error like No such element or plugin 'kvssink' means plugin was installed incorrect. Try to repeat all steps.

In order to start video stream with audio from your webcam use next command:

gst-launch-1.0 -v avfvideosrc ! videoconvert ! vtenc_h264_hw allow-frame-reordering=FALSE realtime=TRUE max-keyframe-interval=45 ! kvssink name=sink stream-name="my_stream_name" access-key="YourAccessKeyId" secret-key="YourSecretAccessKey" osxaudiosrc ! audioconvert ! avenc_aac ! queue ! sink.

You have to indicate stream name, access key and secret key of AWS account.

If device is registered in IoT, you can also use certificates issues, public and private key.

gst-launch-1.0 -v avfvideosrc ! videoconvert ! vtenc_h264_hw allow-frame-reordering=FALSE realtime=TRUE max-keyframe-interval=45 ! kvssink name=sink stream-name="iot-stream" iot-certificate="iot-certificate,endpoint=endpoint,cert-path=/path/to/certificate,key-path=/path/to/private/key,ca-path=/path/to/ca-cert,role-aliases=role-aliases" osxaudiosrc ! audioconvert ! avenc_aac ! queue ! sink.

More detailed info for Mac, Windows, Linux, Raspberry Pi.

Congratulations, now you can see video stream in your AWS account under Media Playback section

If the latency is high and you want to optimize playback — try to adjust settings:

  1. Set lower bitrate, the default one is 500. Quality of picture is decreased however a few seconds is saved. For me bitrate=250 was perfect fit.
  2. Decrease max-keyframe-interval how often keyframes are sent to stream, default value is 45. For me ideal was max-keyframe-interval=25
gst-launch-1.0 -v avfvideosrc ! videoconvert ! vtenc_h264_hw allow-frame-reordering=FALSE realtime=TRUE max-keyframe-interval=25 bitrate=250 ! kvssink name=sink stream-name="my_stream_name" access-key="YourAccessKeyId" secret-key="YourSecretAccessKey" osxaudiosrc ! audioconvert ! avenc_aac ! queue ! sink.

Your producer is set up.

Now lets start with Consumer: https://infinity1high-dl.medium.com/aws-kinesis-video-stream-for-live-video-part-2-consumer-4c4b4e1cdfa7

--

--