Creating a Cloud Gateway for RTSP Video Ingestion into Amazon Kinesis Video Streams

According to industry researcher IHS Markit, the estimated number of IP cameras deployed worldwide was approaching 1 billion by the end of 2021, and according to Gartner’s Emerging Tech: Revenue Opportunity Projection of Computer Vision report, enterprise computer vision (CV) software, hardware and services in key markets is expected to generate global revenue of $386 billion by 2031, up from $126 billion in 2022. Many on-premises deployments of IP cameras make use of a network video recorder (NVR) to handle recording, storage, and playback of video and audio from those cameras, and that integration is commonly implemented using the real-time streaming protocol (RTSP), among others. IP cameras are being used for personal home surveillance as well as for surveillance in the commercial and public sector markets. It is not always possible to install an NVR to capture media from these IP cameras, and with an increased amount of cameras it becomes increasingly important to build computer vision analytics solutions to quickly surface events and drive intelligent notifications to either end users or professional surveillance teams.

In this blog post you will learn how to build a cloud gateway to securely ingest IP camera streams over RTSP to Amazon Kinesis Video Streams, a managed service that makes it easy for customers to securely send video data from camera devices to the cloud. Amazon Kinesis Video Streams provides you SDKs to make it easy to securely stream media to AWS, including a GStreamer plugin called kvssink. GStreamer is a popular open-source media framework that allows you to create custom media pipelines to greatly simplify integration with a multitude of cameras and video sources. This blog post focuses on building a cloud based gateway for customers that are unable to deploy new hardware on-premises, such as an NVR. The same type of approach could be used to implement the secure streaming of media from existing on-prem NVRs.

The architecture diagram below depicts the resources that this solution will deploy into your account.

Cloud Gateway Amazon Kinesis Video Streams Architecture

Figure 1: AWS Fargate-based gateway for ingestion of on-premises IP camera video streams from RTSP to Amazon Kinesis Video Streams solution architecture

The cloud gateway is deployed as an AWS Fargate application, although it could run on either Fargate or Amazon Elastic Compute Cloud (Amazon EC2). The application running on Fargate is comprised of a GStreamer media pipeline and utilizes the Kinesis Video Streams Gstreamer plugin which is part of the Kinesis Video Streams C++ Producer SDK. You will compile the Kinesis Video Streams Producer SDK, including the GStreamer plugin, in the AWS Fargate container. Therefore, the GStreamer multimedia framework and Kinesis Video Streams Producer SDK compile time dependencies will need to be installed as part of the Fargate Application.

The Amazon Virtual Private Cloud (Amazon VPC) architecture in figure 1 above includes the use of an Internet gateway or Egress-only internet gateway. Depending on the bitrates of your RTSP streams and the total number of cameras you choose to integrate using the solution in this blog, use an Internet or Egress-only gateway to cost optimize network traffic. NAT gateway could be used, but NAT gateway isn’t the most cost optimized approach when ingesting video data from one or more IP cameras. For more information, see Amazon VPC Pricing.

To create a secure connection between your data center of branch office and your AWS resources, the architecture above makes use of AWS Direct Connect or an AWS Site-to-Site VPN. For more information see the Hybrid Networking Lens of the AWS Well-Architected Framework.

An AWS account with full permissions on Kinesis Video Streams, Amazon EC2 or Fargate, and Amazon VPC

Familiarity with Linux operating systems and using the command-line

Familiarity with compiling C++ applications and using CMake is helpful, but not required

A system with AWS CLI, AWS CDK, and docker tools installed

The Cloud Gateway for Amazon Kinesis Video Stream repository contains an AWS Cloud Development Kit (CDK) for Amazon EC2 and Fargate deployments. Instructions to deploy the sample applications into your AWS account are included in the README of the repository. The following is an overview of the steps needed to deploy the sample repo into your own account:

Step 1: Create a Kinesis Video Stream

To create a Kinesis Video Stream, open the AWS Management Console with the desired region . Choose Create video stream and enter CloudGatewayStream for the stream name. Leave the Default configuration radio button selected.

Step 2: Create an Amazon VPC with an Internet Gateway

To be able to run an Amazon EC2 or Fargate container, we need to create a VPC. Next, create an Internet Gateway to allow the Cloud Gateway connectivity to your remote camera.

Step 3: Create SSH Keypair and IAM user

Create a SSH Keypair to authenticate to your Amazon EC2. Create an IAM user to provide access to Kinesis Video Streams in the GStreamer start-up script.

Step 4: Create the Cloud Gateway to ingest your RTSP Streams

One can choose to build the Cloud Gateway using Amazon EC2 and install GStreamer running as a service or build the Cloud Gateway to run as a container.

To run the Cloud Gateway as a container, you must first build the Docker container, and then deploy it. To build the Docker container, create an Amazon EC2 and install docker tools to build an Ubuntu container with GStreamer and startup script. If you already have docker tools installed on your local machine, you can use those instead. Next create an Elastic Container Repository (ECR) to store the built Docker image. Finally, create a Fargate cluster, task, and service, which will launch the cloud gateway instance using the Docker image you have built.

Step 5: View your video streams
Navigate to the Kinesis Video Stream Console, then select Video Streams, and finally select your video stream. Expand the media playback component to begin viewing your video stream. An example stream can be viewed below:

Cloud Gateway for Amazon Kinesis Video Streams Console Preview of video
Figure 2: Viewing the Kinesis Video Stream from the on-premises IP camera

Instead of relying on the AWS Console to view your video streams, you could look at the Amazon Kinesis Video Streams Media Viewer application to learn how to incorporate the video stream into your web application, or simply use the HLS or DASH Streaming Session URLs from Kinesis Video Streams with a video player of your choice.

If you no longer need them to avoid incurring future costs, delete the resources you created using the steps below. If you used the Cloud Gateway for Amazon Kinesis Video Stream CDK project, execute the cdk destroy command to remove the deployment.

In this post you learned how to build a cloud gateway to ingest media from on-premises IP cameras to Amazon Kinesis Video Streams for live streaming, and storage and playback of video. This approach allows you to integrate with existing IP cameras without the need for additional on-premises hardware. It also applies AWS well-architected principles to optimize costs when ingesting video data from on-premises sources using a cloud gateway on Fargate. The solution can be used with cameras installed in homes or businesses and is focused on ingesting video data from RTSP streams. For use cases that require scaling the Cloud Gateway, use the getting started with Amazon EC2 auto scaling or Fargate auto scaling guides.

Learn more about Kinesis Video Streams in the getting started guide, or for more GStreamer pipeline samples see the examples for the Kinesis Video Streams producer SDK GStreamer plugin. To learn how to use GStreamer more effectively, checkout the GStreamer application development manual. And once you have successfully built your cloud gateway to ingest media into Kinesis Video Streams, see the following video to learn how to build a low-code computer vision application for use with your video streams.

Latest articles

Related articles