Run the sample application (Cloud9)

In this step, run the Amazon Kinesis Video Streams Producer SDK C++ sample application and upload the video.

Creating a Stream

  • Open Amazon Kinesis Video Streams console
  • Confirm the region is same as the region you selected in 1-1-b
  • Click on the Video streams in the left menu and then click on the Create video stream button
  • Fill in the form with the following information and click the Create video stream button
    • Video Stream Name: kvs-workshop-stream
    • Select default configuration

That’s all, and the stream has been created.

Downloading the video for playback

  • Instead of a USB camera, you will use a pre-downloaded video.
  • Run the following command in a Cloud9 terminal to download a video clip
cd
wget https://awsj-iot-handson.s3-ap-northeast-1.amazonaws.com/kvs-workshop/sample.mp4

Instead of the sample video above, you can also use your own video. Note that if you want to analyze the video using Amazon Rekognition Video in Lab-2, the video must be encoded in H.264.

Getting AWS Credentials

Please select a step by the AWS environment you use.

A) If you are using an account by AWS Event Engine

If you are using an account by the AWS Event Engine in an AWS event, you should follow this step and then skip the “B) If you are using your own AWS account” step.

  • Copy the credentials like below from Team Dashboard > AWS Console of Event Engine and paste them to Cloud9 environment terminal
export AWS_DEFAULT_REGION=...
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
export AWS_SESSION_TOKEN=...

B) If you are using your own AWS account.

Use the AWS CLI to get temporary credentials to upload the video.

Note that if you have not already set up the AWS CLI on the PC for operation, follow the steps: Installing the AWS CLI and Configuring the AWS CLI.

In the terminal on the PC for operation, run the following commands.

aws sts get-session-token

You will get the following results, so we will set this value to the Cloud9’s environment variable.

{
    "Credentials": {
        "AccessKeyId": "...",
        "SecretAccessKey": "...",
        "SessionToken": "...",
        "Expiration": "2020-01-01T00:00:01Z"
    }
}

Next, open Cloud9 terminal and execute the following commands.

export AWS_DEFAULT_REGION="The region you use (e.g. ap-northeast-1, us-west-2)"
export AWS_ACCESS_KEY_ID="The AccessKeyId value of the result above"
export AWS_SECRET_ACCESS_KEY="The SecretAccessKey value of the result above"
export AWS_SESSION_TOKEN="The SessionToken value of the result above"

In this workshop, the AWS CLI is used to get temporary credentials of the IAM user to simplify the procedure, but it is difficult to do this every time on a real camera device. In a real-world use case, you can use a client certificate managed by AWS IoT to get the credentials. How to Eliminate the Need for Hardcoded AWS Credentials in Devices by Using the AWS IoT Credentials Provider

Uploading to a video stream

Run the following command in the Cloud9 terminal to set the environment variables.

export GST_PLUGIN_PATH=$HOME/amazon-kinesis-video-streams-producer-sdk-cpp/build
export LD_LIBRARY_PATH=$HOME/amazon-kinesis-video-streams-producer-sdk-cpp/open-source/local/lib

Then run the following command to upload the video.

cd ~/amazon-kinesis-video-streams-producer-sdk-cpp/build
while true; do ./kvs_gstreamer_file_uploader_sample kvs-workshop-stream ~/sample.mp4 $(date +%s) audio-video && sleep 10s; done

If you get an error, make sure you have set the AWS credentials as the environment variables and the stream name (kvs-workshop-stream) is correct.

This video stream will be used in the following steps, leave the command running, or rerun it when you run the next step.

Checking the video stream

  • Open Amazon Kinesis Video Streams console
  • Click on the Video streams in the left menu > Click on kvs-workshop-stream in the list of streams
  • Click on the Media playback part to expand it, and you’ll see the video you downloaded

Playback video

That’s it. You learned how to upload your videos with Amazon Kinesis Video Streams Producer SDK C++. Next, let’s download the video in MP4 format.