Example: Parsing and rendering Kinesis Video Streams fragments - Amazon Kinesis Video Streams
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Example: Parsing and rendering Kinesis Video Streams fragments

The Stream Parser Library contains a demo application named KinesisVideoRendererExample that demonstrates parsing and rendering Amazon Kinesis video stream fragments. The example uses JCodec to decode the H.264 encoded frames that are ingested using the Example: Kinesis Video Streams Producer SDK GStreamer Plugin - kvssink application. After the frame is decoded using JCodec, the visible image is rendered using JFrame.

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.


To examine and use the Renderer example library, you must have the following:

Running the renderer example

  1. 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
  2. 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.


      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.

  3. From your Java IDE, open src/test/java/com.amazonaws.kinesisvideo.parser/examples/KinesisVideoRendererExampleTest.

  4. Remove the @Ignore directive from the file.

  5. Update the .stream parameter with the name of your Kinesis video stream.

  6. Run the KinesisVideoRendererExample test.

How It Works

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 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 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.BufferedImage. For examples that show how to work with BufferedImage, see Reading/Loading an Image.