AWS for M&E Blog

Optimizing Encodes for Picture Quality with AWS Elemental MediaLive

Being able to provide high-quality encoding for a variety of content types can be a challenge. We’re providing a recommended baseline configuration that can be used with AWS Elemental MediaLive to deliver broadcast-grade video quality (VQ) output for all content types. We’ll also illuminate insights into the impact of varying encoding parameters so you can make your own further optimizations to VQ.

When encoding video, the primary parameters that will influence video quality are the choice of the video codec, bitrate, resolution and framerate. They will vary depending on your application and the type of delivery network that is being used. For example, for an IPTV style of delivery over managed networks to set top boxes (IP based receiver/decoder), only a single encode and output is required with a fixed resolution and framerate to a specific set of target devices. This allows tight optimization of the encode based on the output from the target set top box.

For an over the top (OTT) delivery over unmanaged networks (internet), to a wide variety of devices the video will need to be encoded into an adaptive bitrate (ABR) ladder of encodes, which are then packaged for delivery. For each of the encodes in the ladder the resolution, bitrate, and framerate of the encode may be varied. The construction of the ABR ladder of encodes and bitrates should consider the target devices, display size and performance of the network delivering content to the device.

For devices in a home environment, with wired internet access, you may expect to be able to reach and remain at the higher rates. Whereas a mobile device travelling may need to adapt frequently in response to changes in the speed of the available network connection.

AWS Elemental MediaLive is a broadcast-grade live video processing service that creates high-quality streams for delivery to broadcast TVs and internet-connected devices. It continues to evolve to improve video quality and extend support of new codecs and features. Today it supports live encoding using MPEG-2, AVC, HEVC, AV1, up to 4 K resolution, SDR/HDR colour space and 8/10 bit 4:2:0 or 4:2:2 video. MediaLive uses advanced techniques including artificial intelligence models in order to select the optimal encoding toolsets for the content being encoded.

When key parameters of codec, resolution, bitrate and framerate have been set for encoding the next step is to look at how we can optimize the encoding parameters to obtain a high quality encode within defined constraints.

The following table provides a recommended baseline configuration for use with MediaLive which should provide broadcast-grade picture quality for a wide variety of content types. The table provides the navigation path to reach needed parameters, and the notes provide a brief view of the impact of each parameter.

The settings we suggest in the table apply equally for AVC, HEVC codecs (as they are mostly adapted), as well as the SDR and HDR colour spaces unless noted otherwise. If the encode is for a specific type of content (for example, movies, sport, animation, eSports, and user generated content) or to reach other goals (such as minimising encoding latency) there are further optimizations that could be considered in the detailed analysis. This analyses key encoding parameters of the encode allowing you to more tightly optimize the encoding for specific content types.

Encode Parameter: Location and Baseline setting, Impact of setting: Input Processing: Deblocking Filter Input -General Input Settings - Deblock filter: Enabled, Filter Strength: 3. Normally not required to be enabled - only enable if the source content has significant visible artifacts consistently, for example due to content including video from a low bitrate contribution or noisy source. Rate Control: Output- Video - Rate control - Rate control mode: QVBR, Additional settings - QVBR quality level: Auto QVBR is recommended for modern applications, with a maximum bitrate defined. Older devices may require a CBR encode for compatibility purposes. Bandwidth Reduction Filter Output: Video- Additional Encoding Settings: Enable Filter Strength: Auto This is an in-encoding loop filter which can helps remove imperceptible details in the source content without impacting overall detail. HRD Buffer size: Output- Video- Rate control- Additional settings- Buffer size: 2 x Max Bitrate. If blank, default is 2x max bitrate which is recommended. For low latency use cases then this can be reduced but not below 0.5x max bitrate. HRD Buffer Initial Fill: Output- Video- Rate control- Additional settings- Buffer Fill Percentage: 90%. Check the decoder supports buffer size selected. Lookahead: Output- Video- Codec Details- Additional Settings- Look Ahead Rate Control: High. High is recommended to allow optimal VQ. Setting it to Low will improve latency but trades video quality in demanding scenes. Low works well if there are no or few scene changes in processed video. GOP Size: Output- Video- GOP structure- GOP size: 2 to 4 seconds. The GOP size can be increased to improve quality, but the trade-off is increasing latency for both adaption with OTT delivery or channel change time for broadcast delivery. GOPs below 2 seconds offer lower latency but will also reduce VQ. Closed GOP Cadence: Output- Video- GOP structure- Additional settings- Close GOP cadence: 1 For non-OTT distribution you might have Closed GOP cadence of 2 (so every 2 GOPs we create a closed GOP). For OTT distributions this number must be an integer multiple of the GOP and segment length. So, if GOP = 2 seconds and segment = 4 seconds, Closed GOP cadence can be = 1 or 2. If GOP = 2 seconds and segment = 2 seconds, Closed GOP cadence has to be = 1. Dynamic Sub-GOP: Output- Video- GOP Structure - Additional settings- Sub-GOP Length: Dynamic This feature allows the encoder to vary the number of B-Frames within the GOP to better align with any changes in visual complexity. This allows the encoder to create a Sub-GOP to optimize VQ whilst maintaining the overall GOP cadence. B Frames: Output- Video- GOP Structure - Number B-Frames:1 or 2 for highly motion content, 3 for anything else. Our recommendation is 1 or 2 B-Frames for very high motion content (sports, gaming, chaotic movie or series). Start with 1, move to 2 if it give you better results after testing. Use 3 B-Frames for everything else. Number of Reference Frames: Output- Video- GOP Structure - Additional settings- Num Ref Frames: 3 The number of reference frames tells the encoder how many other frames a given frame is capable of referencing. So, if Reference Frames is set to 3, for example, any given P or B-Frame will be able to reference up to 3 other frames. The number of frames set in this field influences the strategies the encoder uses to choose a reference. Setting to anything higher typically provides no visible quality gains but it could have an impact on processing speeds. (AVC only). B Frame Reference: Output- Video- GOP Structure- Additional settings- Num Ref Frames: Enabled if B-Frames >= 3, Disabled if B-Frames < 3 Allows the encoder to use B frames as a reference, requires support at the decoder. (AVC only) Scene Change Detection: Output- Video- GOP Structure- Additional settings- Scene Change Detection: Enabled. Allows encoder to insert an I frame mid-GOP if this offers encoding benefits without breaking the GOP cadence. Entropy Encoding: Output- Video- Codec Details- Additional Settings- Entropy Encoding: CABAC . CABAC is normally recommended for distribution encodes as it provides higher encoding efficiency than CAVLC. If support is required for legacy devices using the AVC codec, CAVLC may be required. Video Encoding Quality: Output- Video- Additional Encoding Settings- Quality Level: Enhanced Quality. For AVC encoding only, this enabling the use of more demanding encoding toolsets. Optimisations recommended in this table should be used first before using this as a final optional step as the VQ gains are small. Use Enhanced as a last resort. In most cases Standard mode will be sufficient. Adaptive Quantisation: Output- Video- Codec Details- Additional Settings- Adaptive quantization: Auto. Spatial AQ, Temporal AQ, Flicker AQ: enable. Dynamically adapts the other quantisation modes (Spatial Adaptive, Temporal Adaptive, Flicker Adaptive) for optimum PQ.

Figure 1: Recommended baseline encoding parameters.

Conclusion

This blog provides a baseline encoding configuration which can be used to give the best possible VQ for all content types. We have explained the impact of these settings, and for those wanting to optimize tightly for specific content types and applications the detailed analysis provides further insight.

Contact an AWS Representative to learn how we can help accelerate your business.

Further reading

Ben Formesyn

Ben Formesyn

Ben Formesyn is a Senior Specialist Solution Architect, Media Service and Edge at AWS. Ben has 20 years of experience in Broadcast and Content Delivery.

Roman Chekmazov

Roman Chekmazov

Sr. Solution Architect for AWS Elemental