HLS Ad-Insertion

最終更新日:2023-07-13 13:51:13

1 Function Intro

1.1 Brief Introduction

Ads are important sources of income to video websites. Video websites are spending heavily on exclusive broadcast rights, to a large extent because they look good on the value of ad spaces with a large traffic entrance.
To reduce customers’ technology investment and help customers to enhance revenue, CDNetworks takes advantage of its technology and rolls out HLS AD-INSERTION, which supports to insert a specific ad content in a specific position in pre-roll, mid-roll and post-roll of a video. Video vendors can set different ad-insertion strategies for different videos based on the difference in video content (The highlights of each video are different so the time to insert an ad needs to be set flexibly; according to video content type, insert the ad which matches the video content. For example, insert game ads for game videos.). Video vendors can also set different strategies based on the preference of each user (for example insert car-related ads for users who have browsed the videos about cars recently.).

1.2 Applicable Product Lines

  • Media Acceleration VOD

1.3 Application Scenarios

Apply to the scenarios that implement HLS protocol and hope to carry out flexible ad-insertion based on each request.

2 Function Detail

2.1 Basic Principles

When the user clicks the video link on a video website, it will usually send a request for the URL of the video to the origin content management server. Then the content management server will respond to the user with a URL carrying the video ad parameters based on the prescribed rules.
After obtaining the m3u8 URL information which is provided by the origin content management server, the user sends a request for the m3u8 file to the CDN node. Upon receiving the user’s request, the CDN node first extracts the ad content URL and ad-insertion time and other information according to the ad-insertion parameters behind the question mark. Then the ad content URL is added to the m3u8 file based on the add-insertion time. At last it responds to the user with the modified m3u8 file. The user sends a request for the specific ad content at the specific time based on the m3u8 file provided by the CDN node. Thereby, the purpose of a flexible Ad-insertion implementation is reached.

For example:
A customer wants to insert 3 ads with contents of 1.ts, 2.ts and 3.ts in the pre-roll and mid-roll with 600s played and post-roll of the video respectively. The sample of the user’s request for the m3u8 file is:
http://ws.chinanetcenter.com/playlist.m3u8?ad=http%3a%2f%2fws.chinanetcenter.com%2f1.ts%26StartTime%3d0%26ad%3dhttp%3a%2f%2fws.chinanetcenter.com%2f2.ts%26StartTime%3d600%26ad%3dhttp%3a%2f%2fws.chinanetcenter.com%2f3.ts%26StartTime%3d-1
In the sample above, “ad” is an ad-insertion parameter, which indicates the inserted ad content URL. Custom parameter name is supported; “StartTime” is also an ad-insertion parameter, which indicates the time to insert the ad content URL. Custom parameter name is supported; the value of “ad” and “StartTime” is taken from utf-8 encoding.
When the CDN node receives the user’s request for m3u8 file, firstly it extracts the information behind the question mark such as ad content URL and the time to insert ad by utf-8 encoding:
http://ws.chinanetcenter.com/playlist.m3u8?ad=http://ws.chinanetcenter.com/1.ts&StartTime=0&ad=http://ws.chinanetcenter.com/2.ts&StartTime=600&ad=http://ws.chinanetcenter.com/3.ts&StartTime=-1

The extracted ad content URL and the time to insert ad:
(1) http:// ws.chinanetcenter.com /1.ts “StartTime” =0
(2) http:// ws.chinanetcenter.com /2.ts “StartTime” =600
(3) http:// ws.chinanetcenter.com /3.ts “StartTime” =-1

Remarks:
(1) when time= 0, it means it is a pre-roll ad.
(2) when time=600, it means it is a mid-roll ad which is inserted when the video is played for 600s.
(3) when time=-1, it means it is a post-roll ad.

After the CDN node extracts the ad content URL and the time to insert ad it first obtains and parses the m3u8 file. Then, according to the content format of the m3u8, it inserts the ad content URL into the corresponding position according to the insertion time. Finally, it responds to the user.

2.2 Workflow

         Figure 1 HLS AD-INSERTION Workflow Chart

CDNetworks海外新节点上线
(1) The user sends a request for video URL to the origin content management server;
(2) The origin content management server responds to the user with m3u8 file URL which carries ad-insertion parameters;
(3) After getting m3u8 file URL, the user sends a request for m3u8 file to the CDN node;
(4) After receiving the request, the CDN node firstly extracts the value carried by the ad-insertion parameters behind question mark, then implements utf-8 encoding and obtains the information such as ad content URL and the time to insert ad. If the file is not cached, the node will send a request for m3u8 file to origin;
(5) The origin responds to the CDN node with m3u8 file;
(6) The CDN node parses the m3u8 file,then according to the content format of the m3u8, it inserts the ad content URL into the corresponding position according to the insertion time, then responds to the user.
Instructions
(1) Customer Service confirms the ad-insertion parameter name behind the question mark with the customer. (the parameter contains “ad” and “StartTime” by default.)
(2) After confirming with the customer, Customer Service places a ticket for implementing the configurations.

3 Notice

(1) The values of parameters “ad” and “StartTime” need to be encoded in utf-8, which is the default encoding for HTTP protocol.
(2) The encapsulation format of an ad video must be “ts”, otherwise it cannot be inserted into m3u8 file.
(3) If the path of the “ts” file in m3u8 file is relative path, URI should be used as the ad address; if it is absolute path, URL should be used.
(4) Each ad URL must have a corresponding time parameter, otherwise the next ad URL cannot be obtained. This is due to the “StartTime” of the next ad URL being obtained instead and paired with the first URL, resulting in the middle ad being ignored and wrong ad-insertion time happens.
(5) The time to insert ad is generally the integral multiple of “ts” duration. If not, the ad will be inserted in front of the “ts” file whose cumulative duration exceeds the “StartTime”.