Amazon IVS Encoder Configuration - Amazon Interactive Video Service

Amazon IVS Encoder Configuration

Amazon Interactive Video Service (IVS) allows developers to easily deliver low-latency video to viewers worldwide. With Amazon IVS, streamers need to handle only stream production, then send the stream to Amazon IVS. Amazon IVS handles video processing (ingesting and transcoding), delivery, and playback to viewers using the Amazon IVS player.

There is a wealth of solutions for live streaming. Whether you have a studio equipped with multiple cameras, visual switchers, graphics compositing, and a variety of audio mixing equipment, or you plan to start your first stream off a smartphone, you need to deal with some of the same concepts and encoding parameters.

This document describes how to configure video encoders to stream to Amazon IVS. The audience for this document is developers who want to build streaming functionality into their applications.

Prerequisites

Follow the steps in Getting Started with Amazon IVS, to create a channel and set up streaming. In the process, a channel ARN (Amazon Resource Name) and stream key are assigned, along with URLs for ingesting and playing back a stream. You will need to point your streaming application to the ingest URL.

Before reading this document, you should be familiar with:

Reducing Latency

Amazon IVS low-latency streaming is compatible with most streaming applications and requires only minor changes to your streaming-application configuration. For the lowest possible latency, you must use the Amazon IVS player; third-party HLS video players are not supported. See the Amazon IVS Player SDK documentation.

To prepare your streaming application for low-latency streaming, do the following. (Note: not all these options are available on every streaming application.)

  • On the video encoder, set IDR/Keyframe to a 2-second interval (or 1 second, for even lower end-to-end latency).

  • If available, set your encoder to zero-latency tuning within an x264 configuration.

  • Ensure that buffer size (VBV) does not exceed the average bitrate (kilobits-per-second) of the stream.

Avoid Third-Party Streaming/Forwarding Services

We strongly recommend you do not use third-party service to restream or forward content to Amazon IVS. This will incur extra latency. For low latency, stream directly to Amazon IVS.

Encoder Settings

Stream Ingest: Codecs, RTMPS, and Port 443

Codecs: Amazon IVS supports H.264 for video and AAC (LC) for audio.

Amazon IVS supports the most common secure ingest protocol used in streaming software and hardware, RTMPS (Real-Time Messaging Protocol over a TLS/SSL connection).

Your video encoder must connect to Amazon IVS ingest over the RTMPS protocol associated with outbound port 443/TCP. To ensure this, include the port in your ingest URL path; for example:

rtmps://<IVS-ingest-server>:443/app/<IVS-stream-key>

Resolution/Bitrate/FPS

The stream’s resolution largely determines its bitrate and frame rate (frames-per-second, or FPS). Use the following guidelines; these are our recommendations. Note the resolutions shown below are landscape orientation (horizontal x vertical), so reverse these for portrait orientation.

High Quality (Full HD) 1080p (1920x1080) Good Quality (HD) 720p (1280x720) Acceptable Quality (SD) 480p (852x480)
Bitrate 8500 Kbps 4500 Kbps 1500 Kbps
FPS 30 or 60 30 or 60 30
Keyframe interval 2 seconds 2 seconds 2 seconds

Bitrate, FPS, and resolution are interrelated. The optimal values depend on circumstances and can be complicated to determine. Our best guidance is to start with the values above and experiment if desired. The goal is clear and smooth motion of video components during streaming and good resolution within the available bandwidth. Increasing frame rate and/or resolution increases overall video quality, but this is necessarily limited by bandwidth.

Amazon IVS supports framerates up to 60 FPS. The higher the framerate, the better the quality -- as long as there is adequate bitrate bandwidth. Depending on the application, a low framerate can be fine; e.g., for a security camera.

Channel Types

Channel type determines the allowable resolution and bitrate. If you exceed the allowable resolution or bitrate, the stream probably will disconnect immediately. Amazon IVS supports two channel types:

  • STANDARD: Multiple qualities are generated from the original input, to automatically give viewers the best experience for their devices and network conditions. Vertical resolution can be up to 1080 and bitrate can be up to 8.5 Mbps. This is the default.

  • BASIC: Amazon IVS delivers the original input to viewers. The viewer’s video-quality choice is limited to the original input. Vertical resolution can be up to 480 and bitrate can be up to 1.5 Mbps.

Video Settings

We recommend the following settings. They are available to most H.264 video-encoding software or hardware APIs.

  • On the video encoder, set IDR/Keyframe to a 2-second interval (or 1 second, for even lower end-to-end latency).

  • H.264 level: Main

  • Scene change: Off (preferred)

  • Chroma subsample: YUV420P

  • CABAC: Preferred

Audio Settings

We support the following settings:

  • Codec: AAC

  • Bitrate: anything up to 192 Kbps

  • Sample rate: 44.1 Khz or 48 Khz (it is best to match your production audio flow)

  • Channels: Maximum 2 - Stereo (1: mono or 2: stereo audio channel support)

Use CBR, Not VBR

Always use CBR (Constant BitRate), not VBR (Variable BitRate), as the rate-control method for encoders. CBR is better suited for the fixed-bandwidth nature of networks, and it produces more predictable, stable video playback for client devices. With a consistent bitrate, it is easy for viewers to select a quality level that their connection can handle over time.

Depending on the complexity of the scene, VBR can result in spikes in bitrate, which can cause frame drops before the video reaches Amazon IVS and/or buffering in client players.

We strongly recommend you only use CBR. If you use VBR, your streams will be more subject to buffering and playback that is not smooth.

Use Progressive Signals

Use progressive signal flows; avoid any interlaced video in production flow and/or encoding. Progressive stream signals yield much better playback quality displaying a whole frame at a time, avoiding any motion artifacting that is produced when displaying an interlaced signal.

Network Requirements

You must have a stable internet connection that can maintain an adequate, constant upload stream. An unstable internet connection could result in stream stuttering and lagging for your viewers.

Use wired connections. WiFi and LTE connections can be spotty or suffer from interference or latency due to bad QoS/packet-queue prioritization. Whenever possible, rely on a hardwired connection for streams.

Plan to allocate 50% more bandwidth than the minimum required. The overhead is added to compensate for the bitrate fluctuations in encoding of a video bitstream.

Use a dedicated Internet VLAN to encoding machines. Keeping the encoder on a separate network prevents potentially disruptive effects, including: pollution by traffic, bandwidth bottlenecks and adverse security factors.

Closed Captioning

IVS supports closed captioning. As a streamer, if you want to offer captions to your audience, you must transmit caption data in an accepted format, either embedded in your stream or alongside your stream, through your video encoder.

Amazon IVS accepts captions in line 21 CEA-708/EIA-608 format and in CC1 NTSC field 1. You can transmit captions using one of the following methods:

  • CEA-708/EIA-608 embedded in the video elementary stream, as described in ATSC A/72 (SEI user_data). This format is common among television broadcast encoders.

  • CEA-708/EIA-608 transmitted via RTMPS onCaptionInfo script/AMF0 tag. This format is common among Internet broadcast encoders and media servers like Elemental Technologies and Wowza.

When transmitting via RTMPS, the payload must contain an ECMA array with two element pairs:

  • A string named type that contains the characters 708.

  • A string named data that contains a base64-encoded CEA-708/EIA-608 payload.

For example:

00000000 12 00 00 69 00 00 00 00 00 00 00 02 00 0d 6f 6e |...i..........on| 00000010 43 61 70 74 69 6f 6e 49 6e 66 6f 08 00 00 00 02 |CaptionInfo.....| 00000020 00 04 74 79 70 65 02 00 03 37 30 38 00 04 64 61 |..type...708..da| 00000030 74 61 02 00 3c 74 51 41 78 52 30 45 35 4e 41 4e |ta..<tQAxR0E5NAN| 00000040 4c 41 50 79 55 72 76 79 55 49 50 79 52 51 50 7a |LAPyUrvyUIPyRQPz| 00000050 49 35 66 7a 73 37 50 7a 76 4c 50 77 67 56 50 7a |I5fzs7PzvLPwgVPz| 00000060 33 36 66 7a 30 34 2f 78 6f 67 50 79 55 4c 2f 38 |36fz04/xogPyUL/8| 00000070 3d 00 00 09 00 00 00 74 |=......t|

If you use the Elemental video encoder, set it up as follows:

  • Set caption embed to “capture 608 Field 1.”

  • Embed captions with onCaptionInfo as the RTMPS tag in the output group.

Stream from Windows Desktop with FFmpeg

FFmpeg is a free, open-source project comprising a vast suite of software libraries for handling video, audio, and other multimedia files and streams.

See the FFmpeg website for installation and other information about FFmpeg. Use the latest static build (do not compile).

After installing, choose an audio/video input source for FFmpeg. You can look up what is available, as follows:

ffmpeg -list_devices true -f dshow -i dummy.

For more information, see here. Depending on what is available and what capture method is targeted, you should be able to capture the video/audio (embedded) directly from your selected device and encode the signals with FFmpeg. For example:

  • Webcam — To capture output from the Logitech C920 webcam:

    ffmpeg -f dshow -video_size 1920x1080 -framerate 30 -i video="HD Pro Webcam C920":audio="Microphone (HD Pro Webcam C920)" -c:v libx264 -b:v 6000K -maxrate 6000K -pix_fmt yuv420p -r 30 -s 1920x1080 -profile:v main -preset veryfast -g 120 -x264opts "nal-hrd=cbr:no-scenecut” -acodec aac -ab 160k -ar 44100 -f flv rtmps://&lt;IVS-ingest-server>/app/&lt;IVS-stream-key>
  • Video file — FFmpeg works with many video-file formats and capture cards. Here is an example of streaming based on a MP4 input:

    ffmpeg -re -i input.mp4 -c:v libx264 -b:v 6000K -maxrate 6000K -pix_fmt yuv420p -s 1920x1080 -profile:v main -preset veryfast -g 120 -x264opts "nal-hrd=cbr:no-scenecut” -acodec aac -ab 160k -ar 44100 -f flv rtmps://<IVS-ingest-server>/app/<IVS-stream-key>

For more information about what to enter for <IVS-ingest-server> and <IVS-stream-key>, see the information about setting up live-streaming software in Getting Started with Amazon IVS. For example:

  • Ingest server: rtmps://jds34ksdg3las.global-contribute.live-video.net/app/

  • Stream key: sk_us-west-2_abcd1234efgh5678ijkl

Stream from Android and iOS with Larix Broadcaster

Larix Broadcaster is a free Android and iOS streaming client. It encodes video/audio data from cameras and microphones into H.264/AAC format, encapsulates the stream in FLV (Flash Video), and transmits it over RTMPS.

Larix is a pre-packaged application that is available for download from Google Play and the Apple App Store.

After downloading and installing it, configure Larix as follows:

  1. Open Larix Broadcaster.

  2. Agree to three system prompts asking you to Allow Larix Broadcaster to:

    1. Take pictures and record video

    2. Record audio

    3. Access photos, media, and files on your device

  3. Under Settings > Connections, create a New Connection:

    1. Enter a configuration Name (anything you like).

    2. For URL, enter your Amazon IVS channel ingest server and stream key as one string:

      rtmps://<IVS-ingest-server>/app/<IVS-stream-key>.

      See the information about setting up live-streaming software in Getting Started with Amazon IVS.

  4. Under Settings > Video:

    1. Set Video Size to 1080p resolution or less. We recommend 720p (1280x720).

    2. Set FPS to 30 fixed rate.

    3. Under Encoder, set Bitrate to an appropriate bitrate to match your specified resolution (Video Size). For guidance, see Resolution/Bitrate/FPS.

    4. Do not change the keyframe frequency; leave it set to 2 seconds, the default.

  5. Exit Settings and return to the main view of the application. You should be able to start streaming to your channel on Amazon IVS.

Testing the Stream

Always verify that your stream works.

Navigate to the video stream in the Amazon IVS console, to watch what is being streamed and manage the live stream.