Stream CCTV IP camera (RTSP) feed into AWS Kinesis Video Streams

In this tutorial, you will get to know about how to ingest real-time live CCTV IP camera feed into AWS Kinesis Video Streams. Amazon Kinesis video stream allows us to easily ingest live video streams securely from connected devices for video analytics, machine learning (ML), and other processing. With AWS Kinesis, it is possible to securely stream video from multiple connected devices such as USB cameras, RTSP cameras, web cameras and Raspberry Pi camera.

Kinesis Video Streams facilitate us to playback video for live and on-demand viewing. With the help of Amazon Kinesis video stream, we can easily build applications with ultra-low latency live streaming for video analysis such as face recognition and verification, baby monitoring, home surveillance system, traffic monitoring, etc.  

AWS Kinesis Video Stream can be internally connected to other AWS services such as AWS SageMaker and AWS rekognition. So we can easily build video analysis application based on Machine Learning where AWS Kinesis video stream allows us to get live CCTV data and aws SageMaker or aws Rekognition allows us to apply Machine Learning algorithm on video data to analyze it.

Applications

Through AWS services we can develop various applications for video analysis that can be very useful in real-life. Here I have listed a few of them:

1. The employee monitoring system in a retail store:

Track employee in-store or factory by examine the live CCTV camera feed. We can also monitor their activity like how much time a particular employee has spent stocking activity, customer service, cleaning, etc.

2. Customer (Crowd) counting application:

With Machine Learning and computer vision technique, a store owner can get to know about customer traffic information like at what time and day, most customers prefer for shopping.

Which section of the shop gets the most attention by a customers

3. Smart Home Security:

Analyze video feed from your home security camera using face recognition technology and get to know who is at your door?

4. Baby Monitoring application:

Monitor baby’s movement by analyzing video feed and alert their parents if there is any emergency via Alexa notification.

5. Smart city:

Through Machine learning, the traffic problem can be solved by analyzing video 24/7.

 

These are the sample use-cases of video analysis but we can build many more application using the power of AWS services and machine learning.

The basic build block of video analysis application is to get live CCTV camera feed and store it to cloud for analysis or prediction using deep learning techniques.

One of the feasible solution to store live CCTV data is AWS Kinesis Video Stream service. AWS Kinesis Video Stream facilitate us to ingest data from the camera and store videos in its internal storage till defined retention period.

Start the Video Streaming from an RTSP Source

To use any AWS service, it is mandatory to create the account in AWS. We also require Access Key ID and Secret Access Key to access Kinesis Video Stream service. If you have already created before, then you don’t need to create it again. Otherwise, follow the below steps to create the Access Key ID.

Create Access Key ID

Go to AWS IAM service in the AWS console, and select the user from Users tab. You need to grant AmazonKinesisVideoStreamsFullAccess permission to access Kinesis Video Stream service by going to the permission tab and add permissions.

Then Go to the “Security Credentials” tab, to create access key ID and secret access key.

Create AWS Kinesis Video Stream

Go to the Amazon Kinesis video stream console to create the new stream by setting up the details with stream name and data retention period.

Ingest video into Kinesis Video Stream

We can use the popular media framework GStreamer to get started with streaming video from a webcam or RTSP camera to Kinesis Video Stream. The GStreamer plugin automatically manages the transfer of your video stream to Kinesis Video Streams by encapsulating the functionality provided by the Kinesis Video Streams Producer SDK in a GStreamer sink element, kvssink. 

Kinesis Video Stream provide Producer API and Consumer API to read and write media data to and from a stream. Kinesis Video Stream support a set of producer libraries to ingest video data to your Kinesis video stream.

Producer API   – Provide PutMedia API to write media data to the Kinesis video stream. Currently, Kinesis Video Stream only support Java, c++ and Andriod producer library.

Consumer API – allows to consume video data from a Kinesis video stream

In the following section, we will use C++ producer API to send media data from a device to Kinesis Video Stream. The C++ producer library provides a Docker container to connect with RTSP camera and ingest data into Kinesis Video Stream.

Build the Docker Image

To build the docker image, create a folder called “RTSP_streaming” and download the following two files to the newly created folder.

  1. Dockerfile
  2. start_rtsp_in_docker.sh

 

Run the following command to create the Docker image and tags it as rtspdockertest

cd RTSP_streaming

docker build -t rtspdockertest .

Note down the image ID that was returned in the previous command.

Run the Docker container

To start the streaming from RTSP camera into Kinesis Video Stream, we need to run the above Docker container using the following command by providing the Image ID from the previous step, AWS credentials such as access key ID and secret access key, RTSP URL of camera and name of the Kinesis Video Stream to ingest data.

docker run -it <IMAGE_ID> <AWS_ACCESS_KEY_ID> <AWS_SECRET_ACCESS_KEY> <RTSP_URL> <STREAM_NAME>

This will start to send live CCTV camera feed to Kinesis Video Stream. You can visualize streaming by going to the Media Playback section of the Amazon Kinesis Video Stream console.

Leave a Reply

Your email address will not be published. Required fields are marked *

Machine Learning Model Tutorials

Content-Based Recommendation System

Face verification on Live CCTV IP camera feed using Amazon Rekognition Video and Kinesis Video Streams

AWS Rekognition: Face detection & analysis of an image

Model Quantization Methods In TensorFlow Lite

Introduction to TensorFlow Lite

TensorFlow : Prepare Custom Neural Network Model with Custom Layers

Regularization Techniques: To avoid Overfitting in Neural Network

Setting Dynamic Learning Rate While Training the Neural Network

Neural Network: Introduction to Learning Rate

Mathematics behind the Neural Network

Implementation of Neural Network from scratch using NumPy

How Neural Network works?

Gradient Descent with Momentum in Neural Network

Gradient Descent in Neural Network

Activation Functions in Neural Network

Introduction to Neural Network

K-Nearest Neighbors (KNN)

Support Vector Machine (SVM)

Logistic Regression

Linear Regression

Random Forest

Decision Tree

Introduction to Machine Learning Model

Performance Measurement Metrics to Evaluate Machine Learning Model

Essential Mathematics for Machine Learning

Applications of Machine Learning