We moved this page to our Documentation Portal. You can find the latest updates here. |
Customers can restream their HLS videos using Onapp CDN. However Onapp CDN does not offer video transcoding and transmuxing yet. Customer must transcode or transmux the video using their own media server and restream them Onapp CDN as HTTP Pull resource.
There are 2 Types of HLS videos:
- Livestream. For example a live stream of soccer event, or F1 racing, music festival, live television program, etc.
- VOD. For example, music videos, video clips on social media, movies, etc.
Each HLS video type has its own settings to fit its own requirements.
How set up a Livestream HLS
- Create HTTP PULL resource
- Set the media server publishing URL as resource origin
Example: The stream URL is example.com/channel/stream/playlist.m3u8, the resource origin will be example.com - Click HLS Optimization in Advance Settings
- Create HTTP Rule with the following rules:
- If extension equals ts, then Force edge to cache for 86400 seconds
- If extension equals m3u8, then Force edge to cache for 1 seconds
By enabling HLS Optimization the will be:
- Cached in Memory instead of disk. This will make the stream serving super fast to the viewer.
- Has 30s DNS TTL instead of 180s normal resource TTL. This will ensure that the viewer will be able to switch to better edge during the live stream faster if any incident occurred
By creating appropriate HTTP Rules, it will ensure that the stream is cached correctly:
- The .ts files will be cached for 86400s. This will ensure that the viewers always get the video segments from the CDN.
- The .m3u8 playlist files will be cached for only 1s. This will ensure that all viewers will get the same .m3u8 playlist without requesting to the origin.
If the livestream has a very high bandwidth (1Gbps or more), please contact support to enable local cache optimization on the resource. Please provide a test link for us.
How set up a VOD HLS
- Create HTTP PULL resource
- Set the media server publishing URL as origin
- Click HTTP Rules
- Create HTTP Rule with the following rules:
- If extension equals ts or m3u8, then Force edge to cache for 86400 seconds
This will ensure that the .ts video files will always in cache for a long period of time whenever clients need them.
Other considerations
- If there is Set-Cookie headers from the origin, set the resource to Ignore Set-Cookie
- If there is random id (session id) in the stream URL path (for example http://example.com/stream1/<session1>/playlist.m3u8), the stream publisher need to disable the session tracking on the media server (Refer here for Wowza Media Server https://www.wowza.com/docs/how-to-control-streaming-session-id-appended-to-encryption-urls-in-chunklist-responses-cupertinoappendqueryparamstoencurl)
- If there is random id (session id) in the stream URL query string (for example http://example.com/stream1/playlist.m3u8?<sessionid=1>), set the resource cache key to $host$uri.
- If the customer wants to block the stream access from outside, consider the following approaches:
- Use URL signing
- Use Hotlink policy
- Use geo blocking feature
- Use IP Blocking policy
- If the customer wants to serve the stream with HTTPS protocol, use one of the following approach:
- LetsEncrypt
- SNI
- Shared SSL
- If the stream will be played in the browser, contact support to enable the CORS headers.
- If the stream is being played on Samsung TV, please contact support to suppress the CDN headers on the resource. Please provide a test link for us.
How to test the stream
1. Curl the resource m3u8 playlist, ensure that the file is served from CDN
$ curl -i http://<resource published name>/<stream url>/playlist.m3u8
HTTP/1.1 200 OK
Server: nginx
Content-Type: audio/x-mpegurl
Content-Length: 2318
Connection: keep-alive
X-Cache: BYPASS
X-Storage: 7334311:8001
Accept-Ranges: bytes
X-Edge-IP: 1.2.4.102
X-Edge-Location: Dallas, US
2. Curl the resource ts video file, ensure that the file is served from CDN and are CACHED
$ curl -I http://<resource published name>/<stream url>/1.ts
HTTP/1.1 200 OK
Server: nginx
Content-Type: video/mp2t
Content-Length: 65800
X-Age: 3
X-Cache: HIT
X-Storage: 132073627:8001
Accept-Ranges: bytes
X-Edge-IP: 1.2.4.101
X-Edge-Location: Dallas, US
3. Play the stream in multiple players and check the CP reporting page. Ensure that cached traffic is increasing and higher than uncached traffic.