Part 1: How to optimize ad delivery with AWS Elemental MediaTailor
This how-to blog series in three parts walks through the configuration of advanced features for ad insertion available with AWS Elemental MediaTailor. Links to each post are available and cross-referenced as the series progresses. Return to the AWS Media Blog in the coming days for additions to the series.
Content Delivery Networks (CDN) such as Amazon CloudFront play an important role in media streaming workloads by providing worldwide distribution of video content at scale. CloudFront also provides mechanisms to protect and secure video and ad content origins. This post details the use of CloudFront with AWS Elemental MediaTailor to optimize streaming workloads with ad insertion. This optimization is based on MediaTailor’s URL re-write feature in combination with the path match and caching behavior set up in CloudFront. Readers can follow the detailed step-by-step directions in this post to set up their own ad insertion workload.
The following high-level diagram outlines the components of an OTT streaming solution with server-side ad insertion.
Media streaming best practices suggest content segments should be served and cached by a CDN after fetching them from the origin. Subsequent requests for the same segment are served from the CDN cache with improved latency and reduced origin loading. However, caching is not the desired behavior to maintain manifest freshness and personalization. Manifest requests should always be routed back to the content origin. MediaTailor provides necessary mechanisms to implement these best practices in streaming workloads with ad insertion.
The creation of a MediaTailor configuration for ad insertion that works with the MediaTailor service requires at a minimum defining the location of the video content origin (Video content source), and the Ad Decision Server (ADS) URL (Ad decision server). When a client requests a personalized manifest, MediaTailor retrieves the content manifest from the origin defined in the Video content source field of the configuration. Examples of common origins include AWS Elemental MediaPackage for linear and VOD streams, MediaTailor channel assembly for linear streams, Amazon Simple Storage Service (Amazon S3) buckets for VOD, and other third-party origins. MediaTailor identifies ad breaks within the content manifest, requests replacement ads from the ADS, and replaces the original ad break with replacement ad segments to return a personalized manifest.
For efficient content delivery, an optional configuration field called Content segment prefix is available under Advanced settings. Use the URL of the CDN distribution created to serve content segments in this field. MediaTailor replaces the Video content source URL with the Content segment prefix URL in all client manifests it serves. In this ideal scenario, client players receive the content segments from the CDN, while MediaTailor fetches content manifests directly from the origin to reduce response latency and maintain manifest freshness.
Fetching manifests directly from the origin is not possible in some specific scenarios:
- VOD content in an Amazon S3 bucket that is not public, and can be accessed only through a CloudFront distribution endpoint with origin access policy (OAI)
- MediaPackage endpoints that have CDN authentication enabled
- Origins running with self-signed certificates
In such situations, use CDN distribution URL in the Video content source field and control the caching behavior for content and manifests within the distribution or use two separate distributions.
With SSAI, ad segment requests are served directly by MediaTailor. Ad files returned from the ADS are transcoded automatically by MediaTailor (using AWS Elemental MediaConvert) and stored in a service-owned Amazon S3 bucket. During the manifest manipulation process, ad segments are referenced by their service-owned Amazon CloudFront distribution (CDN) URL. If segment URL and delivery consistency is a requirement, it is configurable to serve the ads via a customer-managed CDN. To enable this, configure the Advanced settings > Ad segment prefix field with the CDN distribution URL that has a path route pointing client requests for ad segments to the MediaTailor ad origin.
MediaTailor playback endpoints can be set up for access via a CDN distribution to serve personalized client manifests. The CDN behavior should be set up to never cache manifests, and to always pass query string parameters to the MediaTailor service as they are subsequently passed to the ADS for the personalization of the ads. With CloudFront, customers can define multiple origins and respective caching behaviors within a single distribution so that the manifests, content segments, and ad segments are served from the same CloudFront distribution domain. This avoids common ad playback errors and ad blocking strategies discussed in the introductory post How to configure advanced features in AWS Elemental MediaTailor.
As a precursor to the step-by-step instructions, the following examples elaborate on how the Content segment prefix and Ad segment prefix settings change the client manifests served by MediaTailor. The examples reference a MediaTailor HLS client media manifest where the video content source is an AWS Elemental MediaPackage endpoint.
Impact of Content segment prefix on client media manifest
MediaTailor constructs the client media manifest using the origin manifest it fetches from the origin URL defined in Video content source. The ad-break segments identified in the content media manifest are replaced with the personalized ad segments, while the content segment and their URLs are written based on the Content segment prefix value in the configuration.
- If the Content segment prefixis left blank, MediaTailor constructs the client media manifest using the exact URL path to the origin content segment specified in the origin media manifest. The following example shows the MediaPackage URL for HLS content segments.
``` #EXTM3U #EXT-X-VERSION:6 #EXT-X-TARGETDURATION:6 #EXT-X-MEDIA-SEQUENCE:301 #EXT-X-DISCONTINUITY-SEQUENCE:3 #EXT-X-PROGRAM-DATE-TIME:2020-09-30T00:16:36.000Z #EXTINF:6.0, https://123.mediapackage.us-west-2.amazonaws.com/out/v1/ott/index_12_291.ts?m=1601477501 #EXT-X-PROGRAM-DATE-TIME:2020-09-30T00:16:42.000Z #EXTINF:6.0, https://123.mediapackage.us-west-2.amazonaws.com/out/v1/ott/index_12_292.ts?m=1601477501 #EXT-X-PROGRAM-DATE-TIME:2020-09-30T00:16:48.000Z #EXTINF:6.0, https://123.mediapackage.us-west-2.amazonaws.com/out/v1/ott/index_12_293.ts?m=1601477501 #EXT-X-PROGRAM-DATE-TIME:2020-09-30T00:16:54.000Z #EXTINF:6.0, https://123.mediapackage.us-west-2.amazonaws.com/out/v1/ott/index_12_294.ts?m=1601477501 #EXT-X-PROGRAM-DATE-TIME:2020-09-30T00:17:00.000Z #EXTINF:6.0, https://123.mediapackage.us-west-2.amazonaws.com/out/v1/ott/index_12_295.ts?m=1601477501 ```
- If the Content segment prefix is specified, MediaTailor constructs the client media manifest replacing the domain in the origin content segment URLs with the domain specified in the configuration’s Video content source In the following example, https://cdn.cloudfront.nethas replaced the content origin domain (https://123.mediapackage.us-west-2.amazonaws.com) shown in the previous example.
``` #EXTM3U #EXT-X-VERSION:6 #EXT-X-TARGETDURATION:6 #EXT-X-MEDIA-SEQUENCE:301 #EXT-X-DISCONTINUITY-SEQUENCE:3 #EXT-X-PROGRAM-DATE-TIME:2020-09-30T00:16:36.000Z #EXTINF:6.0, https://cdn.cloudfront.net/out/v1/ott/index_12_291.ts?m=1601477501 #EXT-X-PROGRAM-DATE-TIME:2020-09-30T00:16:42.000Z #EXTINF:6.0, https://cdn.cloudfront.net/out/v1/ott/index_12_292.ts?m=1601477501 #EXT-X-PROGRAM-DATE-TIME:2020-09-30T00:16:48.000Z #EXTINF:6.0, https://cdn.cloudfront.net/out/v1/ott/index_12_293.ts?m=1601477501 #EXT-X-PROGRAM-DATE-TIME:2020-09-30T00:16:54.000Z #EXTINF:6.0, https://cdn.cloudfront.net/out/v1/ott/index_12_294.ts?m=1601477501 #EXT-X-PROGRAM-DATE-TIME:2020-09-30T00:17:00.000Z #EXTINF:6.0, https://cdn.cloudfront.net/out/v1/ott/index_12_295.ts?m=1601477501 ```
Impact of Ad segment prefix on client media manifest
MediaTailor constructs the client media manifest with relative URLs for the ad segments. These relative URLs are beacon URLs for your ad break (beacons are tracking events used by the ADS to accumulate data on how many times an ad plays and to what percentage of completion). On the client request for the beacon URL in the client media manifest, MediaTailor redirects the client to the actual ad segment.
``` #EXTM3U #EXT-X-VERSION:6 #EXT-X-TARGETDURATION:6 #EXT-X-MEDIA-SEQUENCE:782 #EXT-X-DISCONTINUITY-SEQUENCE:21 #EXT-X-PROGRAM-DATE-TIME:2020-09-30T00:59:22.000Z #EXTINF:6.0, https://cdn.cloudfront.net/out/v1/ott/index_14_732.ts?m=1601477501 #EXT-X-PROGRAM-DATE-TIME:2020-09-30T00:59:28.000Z #EXTINF:6.0, https://cdn.cloudfront.net/out/v1/ott/index_14_733.ts?m=1601477501 #EXT-X-PROGRAM-DATE-TIME:2020-09-30T00:59:34.000Z #EXTINF:6.0, https://cdn.cloudfront.net/out/v1/ott/index_14_734.ts?m=1601477501 #EXT-X-PROGRAM-DATE-TIME:2020-09-30T00:59:40.000Z #EXTINF:5.6, https://cdn.cloudfront.net/out/v1/ott/index_14_735.ts?m=1601477501 #EXT-X-DISCONTINUITY #EXT-X-PROGRAM-DATE-TIME:2020-09-30T00:59:45.600Z #EXTINF:2.0, ../../../../segment/61567c73ce1c40e520739c23471f2997f20cf2b6/liveevent/80ff1b76-98de-4927-9999-62e6af842e39/2/786 #EXTINF:2.0, ../../../../segment/61567c73ce1c40e520739c23471f2997f20cf2b6/liveevent/80ff1b76-98de-4927-9999-62e6af842e39/2/787 #EXTINF:2.0, ../../../../segment/61567c73ce1c40e520739c23471f2997f20cf2b6/liveevent/80ff1b76-98de-4927-9999-62e6af842e39/2/788 ```
For the ad segments, you’ll notice the URL is a relative URL as mentioned previously:
``` ../../../../segment/61567c73ce1c40e520739c23471f2997f20cf2b6/liveevent/80ff1b76-98de-4927-9999-62e6af842e39/2/786 ```
The client will construct the full URL to request the ad segment:
``` https://cdn.cloudfront.net/v1/segment/61567c73ce1c40e520739c23471f2997f20cf2b6/liveevent/80ff1b76-98de-4927-9999-62e6af842e39/2/786 ```
MediaTailor processes the above beacon URL request and sends a tracking beacon to the ADS. It also generates an HTTP 302 redirect response for the client with the URL of the ad segment.
- If the Ad segment prefixis left blank, MediaTailor will use the service-owned CloudFront distribution URL for the ad segment as shown in the following:
- If the Ad segment prefixis defined in the configuration, MediaTailor will replace the ad segement URL domain with the domain specified in the Ad segment prefix field as shown in the following example:
``` https://cdn.cloudfront.net/tm/xyz67c73ce1c40e520739c23471f2997f20cf2b6/hq3nuvddl5c4vjfwvt525ry2c3johjmp/asset_480_2_0_00001.ts ```
If the same CDN distribution (CloudFront example shown previously) is used in Content segment prefix and Ad segment prefix, then the client manifest, content segments, and ad segments will be served from the same domain using specific behavior settings required for client manifest, content, and ad segment delivery. These configurations are addressed in the step-by-step directions that follow.
General guidelines for CDN integration with MediaTailor can be found at this location: https://docs.aws.amazon.com/mediatailor/latest/ug/integrating-cdn.html
Step-by-step guide to set up MediaTailor configuration and CloudFront distribution
The <Link>step-by-step instructions</Link> include configuration steps for MediaTailor and CloudFront. For readers that don’t have an existing ad insertion workload, additional necessary components are required for end-to-end testing, instructions for which can be found here.
This post explains how MediaTailor presents video content and ad segment URLs within client manifests. Examples and detailed explanation of MediaTailor’s URL re-write feature used in combination with CloudFront distribution encourages thought about how to improve ad insertion workloads. A step-by-step configuration guide is designed to simplify setup and testing of the described features in your own ad insertion workload.
This blog series and its implementation instructions should allow you to:
- Understand how MediaTailor can efficiently serve video and ad content in combination with a CDN.
- Configure a MediaTailor workload with CloudFront as the CDN, where client manifests, content, and ad segments are always served via a CloudFront distribution.