Example: Parsing and rendering Kinesis Video Streams fragments
The Stream using parser library contains a
demo application named KinesisVideoRendererExample
that demonstrates
parsing and rendering Amazon Kinesis video stream fragments. The example uses JCodec
This example shows how to do the following:
-
Retrieve frames from a Kinesis video stream using the
GetMedia
API and render the stream for viewing. -
View the video content of streams in a custom application instead of using the Kinesis Video Streams console.
You can also use the classes in this example to view Kinesis video stream content that isn't encoded as H.264, such as a stream of JPEG files that don't require decoding before being displayed.
The following procedure demonstrates how to set up and use the Renderer demo application.
Prerequisites
To examine and use the Renderer example library, you must have the following:
-
An Amazon Web Services (AWS) account. If you don't already have an AWS account, see Getting Started with Kinesis Video Streams.
-
A Java integrated development environment (IDE), such as Eclipse Java Neon
or JetBrains IntelliJ Idea .
Running the renderer example
-
Create a directory, and then clone the example source code from the GitHub repository.
git clone https://github.com/aws/amazon-kinesis-video-streams-parser-library
-
Open the Java IDE that you are using (for example, Eclipse
or IntelliJ IDEA ), and import the Apache Maven project that you downloaded: -
In Eclipse: Choose File, Import, Maven, Existing Maven Projects. Navigate to the
kinesis-video-streams-parser-lib
directory. -
In IntelliJ Idea: Choose Import. Navigate to the
pom.xml
file in the root of the downloaded package.Note
If IntelliJ can't find your dependencies, you might have to do the following:
-
Build clean: Choose File, Settings, Build, Execution, Deployment, Compiler. Verify that Clear output directory on rebuild is selected, and then choose Build, Build Project.
-
Reimport the project: Open the context (right-click) menu for the project, and choose Maven, Reimport.
-
For more information, see the related IDE documentation.
-
-
From your Java IDE, open
src/test/java/com.amazonaws.kinesisvideo.parser/examples/KinesisVideoRendererExampleTest
. -
Remove the
@Ignore
directive from the file. -
Update the
.stream
parameter with the name of your Kinesis video stream. -
Run the
KinesisVideoRendererExample
test.
How It Works
The example application demonstrates the following:
Sending MKV data
The example sends sample MKV data from the
rendering_example_video.mkv
file, using
PutMedia
to send video data to a stream named
render-example-stream.
The application creates a PutMediaWorker
:
PutMediaWorker putMediaWorker = PutMediaWorker.create(getRegion(), getCredentialsProvider(), getStreamName(), inputStream, streamOps.amazonKinesisVideo); executorService.submit(putMediaWorker);
For information about the PutMediaWorker
class, see Call PutMedia in the Stream using parser library
documentation.
Parsing MKV fragments into frames
The example then retrieves and parses the MKV fragments from the stream using
a GetMediaWorker
:
GetMediaWorker getMediaWorker = GetMediaWorker.create(getRegion(), getCredentialsProvider(), getStreamName(), new StartSelector().withStartSelectorType(StartSelectorType.EARLIEST), streamOps.amazonKinesisVideo, getMediaProcessingArgumentsLocal.getFrameVisitor()); executorService.submit(getMediaWorker);
For more information about the GetMediaWorker
class, see Call GetMedia in the Stream using parser library
documentation.
Decoding and displaying the frame
The example then decodes and displays the frame using JFrame
The following code example is from the KinesisVideoFrameViewer
class, which extends JFrame
:
public void setImage(BufferedImage bufferedImage) { image = bufferedImage; repaint(); }
The image is displayed as an instance of java.awt.image.BufferedImageBufferedImage
, see Reading/Loading an Image