awslabs/amazon-kinesis-video-streams-producer-sdk-cpp
Acerca de
Amazon Kinesis Video Streams Producer SDK for C++ is for developers to install and customize for their connected camera and other devices to securely stream video, audio, and time-encoded data to Kinesis Video Streams.
Diseño y multimediaWhat you can do
- C++ SDK with sample programs
- GStreamer plugin (kvssink) and samples
Crecimiento de estrellas medido
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- -1
- in 1 month
- Recopilando historial
Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.
README.md
Original
Amazon Kinesis Video Streams C++ Producer, kvssink GStreamer Plugin, and Java Native Interface
Amazon Kinesis Video Streams | Secure Video Ingestion for Analysis & Storage
Table of Contents
Key Features
- C++ SDK with sample programs
- GStreamer plugin (
kvssink) and samples
[!NOTE] If the GStreamer plugin and samples are not needed for your use case, you may consider instead using the KVS Producer C SDK.
Amazon Kinesis Video Streams Producer SDK for C++ makes it easy to build an on-device application that securely connects to a video stream, and reliably publishes video and other media data to Kinesis Video Streams (KVS). It takes care of all the underlying tasks required to package the frames and fragments generated by the device's media pipeline. The SDK also handles stream creation, token rotation for secure and uninterrupted streaming, processing acknowledgements returned by Kinesis Video Streams, and other tasks. The SDK includes a GStreamer plugin to stream directly to a custom GStreamer element kvssink.
For more info on KVS please see AWS KVS Documentation and Amazon Kinesis Video Streams FAQs.
Quick Start
The following instructions describe the SDK and samples setup for Mac, Linux, and Windows platforms. For dedicated Raspberry Pi instructions, see Use the C++ producer SDK on Raspberry Pi and Raspberry Pi setup guide.
Required Tools
The following packages are required to build the SDK libraries. Using a package manager such as Homebrew (Mac), APT (Linux), and Chocolatey (Windows) is the prefered method of installation.
- C++ Compiler (GNU or Clang recommended)
gitCMake(requires 3.x,CMake4.x is not yet supported)pkg-configfor Mac/Linux,pkgconfiglitefor Windowsm4- Windows only:
nasmandstrawberryperl
Mac
brew install git cmake pkg-config m4
Linux
sudo apt update
sudo apt install git cmake build-essential pkg-config m4
Windows
choco install git cmake pkgconfiglite nasm strawberryperl
Install GStreamer
If building the samples or the kvssink GStreamer plugin, GStreamer libraries are required.
Mac
brew install gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-libav
Linux
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-plugins-base-apps gstreamer1.0-plugins-bad gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-tools
Windows
choco install gstreamer --version=1.22.12 gstreamer-devel --version=1.22.12
[!IMPORTANT] Windows users: After installing GStreamer, add the GStreamer DLL path to your PATH environment variable:
set PATH=%PATH%;C:\gstreamer\1.0\msvc_x86_64\binReplace the path with your actual GStreamer installation directory if different.
Verify GStreamer Installation
Run the following command to display the GStreamer version to confirm the installation was successful:
gst-launch-1.0 --gst-version
GStreamer Core Library version 1.24.9
Download
git clone https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp.git --single-branch -b master kvs-producer-cpp-sdk
Build
Prepare a build directory in the newly checked out repository:
mkdir -p kvs-producer-cpp-sdk/build
cd kvs-producer-cpp-sdk/build
Configure the build:
Mac and Linux
cmake -DBUILD_GSTREAMER_PLUGIN=ON ..
Windows (may need to run twice)
cmake -G "NMake Makefiles" -DBUILD_GSTREAMER_PLUGIN=ON ..
[!NOTE] For more build configuration options, see CMake Arguments.
Compile:
Mac and Linux
make
Windows
nmake
Run the Samples
Included are sample applications for streaming and ingesting to a KVS stream. To stream to KVS, the GStreamer samples use an implemented appsink sink element, and the "kvssink" samples use the custom kvssink sink element.
[!TIP] More on GStreamer elements.
AWS Authentication
In your terminal, export AWS credentials for your IAM user or role and the region your stream is located in. The samples will default to us-west-2 if the region is not specified. The sample applications do not support IMDS credentials.
export AWS_ACCESS_KEY_ID=YourAccessKey
export AWS_SECRET_ACCESS_KEY=YourSecretKey
export AWS_DEFAULT_REGION=YourAWSRegion
If you're using temporary AWS credentials, also export your session token:
export AWS_SESSION_TOKEN=YourSessionToken
GStreamer appsink Samples
To stream media from the device's camera and microphone sources, create a stream in the AWS KVS console and run the following sample:
./kvs_gstreamer_audio_video_sample <your-stream-name>
kvssink Samples
The SDK comes with two programmatic GStreamer samples: kvssink_gstreamer_sample and kvssink_intermittent_sample. For more use cases, see the CLI pipeline examples at Example: Kinesis Video Streams Producer SDK GStreamer Plugin.
The programmatic samples require the AWS region to be set with the AWS_DEFAULT_REGION environment variable. For example:
export AWS_DEFAULT_REGION=us-west-2
To load the kvssink plugin into GStreamer, set the following environment variable from the build directory.
Mac and Linux
export GST_PLUGIN_PATH=`pwd`/.
Windows
set GST_PLUGIN_PATH=%CD%\.
Running the following command should now display information on the kvssink plugin:
gst-inspect-1.0 kvssink
If the build failed or GST_PLUGIN_PATH is not properly set, you may instead see the following output:
No such element or plugin kvssink
After building the SDK, loading kvssink into the GStreamer plugin path, and setting a region, the sample executables, which are located in the build directory, can be run. For example:
./kvssink_gstreamer_sample MyStreamName
To stream from file with this sample, you can download a test video file and append the file name after the stream name in the sample run command:
wget https://awsj-iot-handson.s3-ap-northeast-1.amazonaws.com/kvs-workshop/sample.mp4
./kvssink_gstreamer_sample MyStreamName ./sample.mp4
Running the kvssink Intermittent Sample
The intermittent kvssink sample will stream video for 20 seconds, then pause for 40 seconds, and repeat until an interrupt signal is received. To manually adjust the streaming and paused intervals, you can change the KVS_INTERMITTENT_PLAYING_INTERVAL_SECONDS and KVS_INTERMITTENT_PAUSED_INTERVAL_SECONDS values in the kvssink_intermittent_sample.cpp file.
./kvssink_intermittent_sample <stream-name> <testsrc or devicesrc (optional)>
Setting the source to testsrc will use videotestsrc and to devicesrc will use autovideosrc. By default, kvssink uses "DEFAULT_STREAM" as the stream name, and the sample uses videotestsrc as the source. If a KVS stream with the provided or default name does not exist, the stream will automatically be created.
Viewing the Sample Footage
Check the ingested video stream to confirm successful streaming using either the AWS KVS Console or the KVS Media Viewer.
If playback issues are encountered, pleaser refer to the playback requirements under GetHLSStreamingSessionURL or GetDASHStreamingSessionURL and to the Troubleshooting HLS Issues guide.
Using putEventMetadata for Events and S3 Image Generation
The image generation feature is available in the kvs_gstreamer_audio_video_sample.cpp sample. To enable it, include the argument -e <event_option> where <event option> is a string that can be:
notification- for a notification eventimage- for an image eventboth- for both
The addition of event metadata will begin on the 2nd key frame and recur every 200 key frames. To modify this frequency, you can adjust the sample accordingly.
Using a File Source
In the kvs_gstreamer_audio_video_sample.cpp sample, if you would like to upload from a file, include the -f <file_path> argument.
Running in Offline Mode
By default, the samples run in near-realtime mode. To use offline mode, set streamInfo.streamCaps.streamingType to STREAMING_TYPE_OFFLINE, where, streamInfo is of type StreamInfo, streamCaps is of type StreamCaps and streamingType is of type STREAMING_TYPE.
Build Options
Considerations
- The
kvssinkGStreamer plugin and samples are not built by default. To build them, use the cmake command option-DBUILD_GSTREAMER_PLUGIN=ON. - By default, the dependency libraries (Curl, OpenSSL, and Log4Cplus) are installed from GitHub and built locally. To instead link to pre-installed libraries on the device, include the following cmake command argument:
cmake .. -DBUILD_DEPENDENCIES=OFF
CMake Arguments
You can pass the following additional CMake options:
| Option | Default | Description |
|---|---|---|
| BUILD_GSTREAMER_PLUGIN | OFF | Build the kvssink GStreamer plugin and samples |
| PARALLEL_BUILD | ON | When building dependencies, use multiple CPU cores in parallel (speeds up the build). Not available in Windows. |
| BUILD_DEPENDENCIES | ON | Build depending libraries from source |
| BUILD_TEST | OFF | Build unit/integration tests, may be useful to confirm support for your device, to run tests: ./tst/producerTest |
| CODE_COVERAGE | OFF | Enable coverage reporting |
| COMPILER_WARNINGS | OFF | Enable all compiler warnings |
| ADDRESS_SANITIZER | OFF | Build with AddressSanitizer |
| MEMORY_SANITIZER | OFF | Build with MemorySanitizer |
| THREAD_SANITIZER | OFF | Build with ThreadSanitizer |
| UNDEFINED_BEHAVIOR_SANITIZER | OFF | Build with UndefinedBehaviorSanitizer |
| ALIGNED_MEMORY_MODEL | OFF | Build for aligned memory model only devices |
| BUILD_LOG4CPLUS_HOST | OFF | Specify host-name for log4cplus for cross-compilation |
| CONSTRAINED_DEVICE | OFF | Set the thread stack size to 0.5MB, needed for Alpine builds |
| KVS_LINK_PIC_ALSO | OFF | Explicitly link kvspic to targets, needed for some external dependency builds |
These options can be set as arguments to the cmake command, for example:
cmake .. -DBUILD_GSTREAMER_PLUGIN=ON -DBUILD_DEPENDENCIES=OFF
Setting the Log Level
To set a log level, update the log level value here.
The log levels currently available with log4cplus are:
TRACEDEBUGINFOWARNERRORFATAL
Note: The default log level is DEBUG.
The SDK also tracks entry and exit of functions which increases the verbosity of the logs. This will be useful when you want to track the transitions within the codebase. To do so, you need to set log level to TRACE and add the following to the cmake file:
add_definitions(-DLOG_STREAMING)
Note: This log level is extremely VERBOSE and could flood the files if using file based logging strategy.
Installing the Library
If the SDK library needs to be installed on your system rather than the local build directory, run make install. This will install in the default directory such as usr/local/lib/, based on the system. To install in another directory, run cmake with the -DCMAKE_INSTALL_PREFIX option with the desired directory before running make install
Cross-Compilation
If you wish to cross-compile CC and CXX are respected when building the library and all its dependencies. See the ci.yml for an example. Every commit is tested for cross compilation.
Please note that GStreamer is not cross-compiled as a part of the cross-compilation of the KVS-SDK, you will have to cross-compile it separately.
Docker Scripts
The sample docker scripts for RTSP plugin, Raspberry Pi and Linux can be found in the Kinesis demos repository.
Configuring kvssink
The kvssink GStreamer element includes the following parameters:
| Parameter | Default | Description |
|---|---|---|
| stream‑name | 'DEFAULT_STREAM' | The name of the destination Kinesis video stream. If a KVS stream with the provided or default name does not exist, the stream will automatically be created. |
| aws‑region | 'us-west-2' | The region specified by this parameter will be used if the AWS_DEFAULT_REGION environment variable is not set. |
| storage‑size | 128 | The storage size of the device in mebibytes (MiB). For information about configuring device storage, see StorageInfo. |
| access‑key | N/A | The AWS access key that is used to access Kinesis Video Streams. You must provide either this parameter or credential-path, or set the AWS_ACCESS_KEY_ID environment variable. |
| secret‑key | N/A | The AWS secret key that is used to access Kinesis Video Streams. You must provide either this parameter or credential-path, or set the AWS_SECRET_ACCESS_KEY environment variable. |
| credential‑path | '.kvs/credential' | A path to a file containing your credentials for accessing Kinesis Video Streams. For example credential files and more information, see Provide credentials to kvssink. You must provide either this parameter or access-key and secret-key, or set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables. |
| ignore‑region‑env | false | When true, the AWS_DEFAULT_REGION environment variable is ignored and the aws-region parameter is always used. See the precedence note below. |
| ignore‑credentials‑env | false | When true, the AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN environment variables are ignored and the access-key, secret-key, and session-token parameters are always used. See the precedence note below. |
Environment variable precedence. By default, when both an environment variable and its corresponding kvssink parameter are set, the environment variable takes precedence. The region lookup order is:
AWS_DEFAULT_REGIONenvironment variable is reviewed first. If it is set, that region is used to configure the client.aws-regionparameter is reviewed next. If it is set, that region is used to configure the client.- If neither of the previous methods were used,
kvssinkdefaults tous-west-2.
Set kvssink's ignore-region-env=true property to skip step 1 so the aws-region parameter is always used. Credentials follow the same env-first precedence; set ignore-credentials-env=true to skip the AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY / AWS_SESSION_TOKEN environment variables so the access-key / secret-key / session-token parameters are always used. Both ignore environment properties default to false.
To see all kvssink parameters, see AWS Docs - kvssink Paramters.
For examples of common use cases, see Example: Kinesis Video Streams Producer SDK GStreamer Plugin.
Certificate configuration (KVSSINK_CA_CERT_PATH)
kvssink uses libcurl to make HTTP requests to AWS. By default, libcurl relies on the system’s standard locations for SSL/TLS certificate verification. In some environments, you may need to override where libcurl looks for CA certificates. You can do this by setting the environment variable:
export KVSSINK_CA_CERT_PATH=/path/to/certs
The value can be either:
- A directory containing certificate files, or
- A single certificate file (with
.pemextension).
This is particularly useful in restricted or read-only environments—such as certain camera systems that lack CA certificates.
In such cases, you can provide certificate bundle from this repo (certs/cert.pem).
Java Native Interface (JNI)
JNI enables seamless integration between Java and Android applications and the underlying native Producer libraries.
The JNI implementation is maintained in the KVS Java Producer SDK.
Check the README in that repository for more information on building and how to use it.
Troubleshooting
Additional Platform-Specific Instructions
We have FAQs and platform specific instructions for Windows, MacOS and Linux.
Debugging
Build Issues
- Clean Build: When modifying the build configuration between builds, ensure the appropriate files from the previous build are removed before running
cmakefor the next build. A simple way to ensure all the previous build's files are removed is to delete all the directories created during the build. To do so, run the following in the project's root folder:
rm -rf build dependency open-source
- If you are running into issues building libcurl on M1 Mac, you can try
brew unlink openssl.
Playback Issues
- If you are successfully streaming but run into issue with playback. You can do
export KVS_DEBUG_DUMP_DATA_FILE_DIR=/path/to/directorybefore streaming. Producer will then dump MKV files into that path. The file is exactly what KVS will receive. You can use MKVToolNIX to check that everything looks correct. You can also try to play the MKV file in compatible players. - See AWS Docs - Playback issues for more troubleshooting guidance.
GStreamer Issues
- If you would like to visualize the GStreamer pipeline being constructed in a GStreamer application, include the following after the elements have been linked:
GST_DEBUG_BIN_TO_DOT_FILE(<gst-bin-object>, GST_DEBUG_GRAPH_SHOW_ALL, <file-name>);For example, if the application created a pipeline objectGstPipeline* pipeline = gst_pipeline_new("test-pipeline"), and you would like to see the visualized pipeline with filename pipeline, add:GST_DEBUG_BIN_TO_DOT_FILE((GstBin*) pipeline, GST_DEBUG_GRAPH_SHOW_ALL, "pipeline");. Also, ensure to set the path to where you would like the file to be stored.export GST_DEBUG_DUMP_DOT_DIR=.. The file generated would be a.dotformat. Convert to PDF to check the visualized pipeline. This requiresgraphvizto be installed.
CI Testing
GitHub actions will run tests and builds for every pull request.
To setup the CI in your environment, follow https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services to setup the IAM permissions and role for your GitHub repository.
Afterwards, go to your repository settings and add the following repository secrets:
- Key:
AWS_ROLE_TO_ASSUME-- Assume role ARN - Key:
AWS_REGION-- Region to use (e.g.us-west-2) - Key:
AWS_ROLE_SESSION_NAME-- Optional. This name appears in AWS CloudTrail logs for entries associated with this session.
Local Development with Dependency Overrides
When developing changes across the SDK stack (C++ SDK → C Producer → PIC), you can point the build to local checkouts instead of fetching from GitHub. This avoids the git-fetch cycle and lets you test changes across repos immediately.
CMake Variables
| Variable | Used By | Description |
|---|---|---|
LOCAL_KVSC_PATH |
C++ SDK | Path to a local KVS Producer C SDK checkout |
LOCAL_KVSPIC_PATH |
C++ SDK, C Producer | Path to a local KVS PIC checkout |
Usage
# Build C++ SDK using local C Producer and local PIC
mkdir -p build && cd build
cmake .. \
-DBUILD_GSTREAMER_PLUGIN=ON \
-DLOCAL_KVSC_PATH=/path/to/amazon-kinesis-video-streams-producer-c \
-DLOCAL_KVSPIC_PATH=/path/to/amazon-kinesis-video-streams-pic
make
You can use either variable independently:
# Only override PIC (C Producer is still fetched from GitHub)
cmake .. -DLOCAL_KVSPIC_PATH=/path/to/amazon-kinesis-video-streams-pic
# Only override C Producer (PIC is fetched by C Producer from GitHub)
cmake .. -DLOCAL_KVSC_PATH=/path/to/amazon-kinesis-video-streams-producer-c
When LOCAL_KVSC_PATH is set, the C++ SDK uses add_subdirectory to include the local C Producer directly. When LOCAL_KVSPIC_PATH is set, it is forwarded to the C Producer build so PIC is also resolved locally. This means a single cmake + make builds all three layers from your working copies. Changes in PIC or C Producer source files are picked up on the next make without re-running cmake.
Development
The repository is using develop branch as the aggregation and all of the feature development is done in appropriate feature branches. The PRs (Pull Requests) are cut on a feature branch and once approved with all the checks passed, they can be merged by a click of a button on the PR tool. The master branch should always be build-able and all the tests should be passing. We are welcoming any contribution to the code base. The master branch contains our most recent release cycle from develop.
Release
The repository is under active development and even with incremental unit test coverage where some of the tests are actually full integration tests, we require more rigorous internal testing in order to 'cut' release versions. The release is cut against a particular commit that gets approved. The general philosophy is to cut a release when a set of commits contribute to a self-containing feature or when we add major internal functionality improvements.
Versioning
We deploy 3 digit version strings in a form of 'Major.Minor.Revision' scheme.
- Major version update - Major functionality changes. Might not have direct backward compatibility. For example, multiple public API parameter changes.
- Minor version update - Additional features. Major bug fixes. Might have some minor backward compatibility issues. For example, an extra parameter on a callback function.
- Revision version update - Minor features. Bug fixes. Full backward compatibility. For example, an extra fields added to the public structures with version bump.
Related
- What Is Amazon Kinesis Video Streams
- C SDK
- Example: Kinesis Video Streams Producer SDK GStreamer Plugin
License
This library is licensed under the Apache 2.0 License.
Explorar proyectos relacionados
Cargando…