Amazon Kinesis Video Streams
Developer Guide

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: Using GStreamer with Kinesis Video Streams 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
  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.


      You may need to do the following if IntelliJ cannot find your dependencies:

      • Build clean: Choose File, Settings, Build, Execution, Deployment, Compiler. Ensure that Clear output directory on rebuild is checked, and then choose Build, Build Project.)

      • Reimport the project: Right-click on 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

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