Video Playback with HLS

You can use HTTP Live Streaming (HLS) or Dynamic Adaptive Streaming over HTTP (DASH) to playback the live video or on demand.

In this step, you will use AWS CLI to get the HLS streaming session URL and playback the video.

Live playback with HLS

First, you will try live streaming using HLS.

Execute the following command from the terminal of the PC for operation or Cloud9.

aws kinesisvideo get-data-endpoint --stream-name kvs-workshop-stream --api-name GET_HLS_STREAMING_SESSION_URL

You will get the following result.

    "DataEndpoint": ""

Store this value in an environment variable.

export KVS_DATA_ENDPOINT=< DataEndpoint >

Execute the following command.

aws kinesis-video-archived-media get-hls-streaming-session-url --endpoint-url $KVS_DATA_ENDPOINT \
--stream-name kvs-workshop-stream \
--playback-mode LIVE

Copy the URL of HLSStreamingSessionURL in the following result.

    "HLSStreamingSessionURL": ""

If you get an error like below, the video is not being streamed to the cloud and you should re-execute the command to upload the video to the stream that you did in 1-3.

An error occurred (ResourceNotFoundException) when calling the GetHLSStreamingSessionURL operation: No fragments found in the stream for the streaming request.

Paste the URL on Safari, Edge, QuickTime Player, or player that supports streaming in HLS format, such as hls.js.

You will see the real-time streaming video as shown below.

HLS Playback

On demand playback with HLS

Next, try to play back the past video on demand.

Execute the following commands on the terminal of the operation PC.

# for Linux only
FIVE_MIN_AGO=$(date -d "5 minute ago" -u "+%FT%T+0000")
FOUR_MIN_AGO=$(date -d "4 minute ago" -u "+%FT%T+0000")

# for macOS only
FIVE_MIN_AGO=$(date -v -5M -u "+%FT%T+0000")
FOUR_MIN_AGO=$(date -v -4M -u "+%FT%T+0000")

# in case you don't have the "date" command

# common to all OSes
aws kinesis-video-archived-media get-hls-streaming-session-url --endpoint-url $KVS_DATA_ENDPOINT \
--stream-name kvs-workshop-stream \
--playback-mode ON_DEMAND \
--hls-fragment-selector "FragmentSelectorType=SERVER_TIMESTAMP,TimestampRange={StartTimestamp=$FIVE_MIN_AGO,EndTimestamp=$FOUR_MIN_AGO}"

You can get the HLSStreamingSessionURL as before, so if you play it, you can see the video of from 5 minutes ago.

Great! You completed Lab-1. Next, let’s move on to Lab-2.