Restream HLS Video via OnApp CDN
Customers can restream their HLS videos using Onapp CDN. However, Onapp CDN does not provide video transcoding and transmuxing. Customer must transcode or transmux the video using their own media server and restream it via OnApp CDN as an HTTP Pull resource.
There are 2 types of HLS videos:
- Live Streaming (e.g., live streaming of a soccer event, F1 racing, music festival, live TV program, etc.).
- VoD (e.g., music videos, video clips on social media, movies, etc.).
Each HLS video type has its own settings to meet its own requirements.
How to Set Up a Live Streaming HLS
When creating an HTTP Pull resource, in the Origins field, specify the media server publishing URL (e.g., if the stream URL is example.com/channel/stream/playlist.m3u8, the resource origin is example.com).
- Move the Enable HLS Optimization slider to the right.
- Select the Enforce Cache Expiry checkbox if you would like to create a rule to enforce cache expiry. You can manage rules at the HTTP Caching Rules page.
- If you want to configure caching rules on your own, create HTTP Rules with the following settings:
- If the extension equals .ts, in the Act column, select Force edge to cache, and in the Seconds column, specify 3600 seconds.
- If the extension equals .m3u8, in the Act column, select Force edge to cache, and in the Seconds column, specify 1 second.
Creating appropriate HTTP Rules ensures that the stream is cached correctly:
- When .ts files are cached for 3600 seconds, the viewers always get the video segments from the CDN.
- When the .m3u8 playlist files are cached only for 1 second, all viewers get the same .m3u8 playlist without making requests to the origin.
If live streaming has very high bandwidth (1 Gbps or more), contact OnApp Support to enable the local cache optimization in the resource and provide a test link.
How to Set Up a VoD HLS
When creating an HTTP Pull resource, in the Origins field, specify the media server publishing URL.
- Create an HTTP rule with the following settings:
- If the extension is .ts or .m3u8, in the Act column, select Force edge to cache, and in the Seconds column, specify 86400 seconds.
It ensures that the .ts video files will always be in cache for a long period of time whenever clients need them.
- If there are Set-Cookie headers from the origin, move the Ignore Set-Cookie slider to the right at the Edit CDN Resource page or at the New CDN Resource page.
- If there is a random ID (session ID) in the stream URL path (for example, http://example.com/stream1/<session1>/playlist.m3u8), the stream publisher must disable the session tracking on the media server.
- If there is a random ID (session ID) in the stream URL query string (e.g., http://example.com/stream1/playlist.m3u8?<sessionid=1>), at the Edit CDN Resource page or at the New CDN Resource page, select $host$uri in the Proxy cache key drop-down list.
- If the customer wants to block the stream access from outside, at the Edit CDN Resource page or at the New CDN Resource page, use one of the following:
- URL Signing
- Hotlink Policy
- Country Access
- Access Policy - select Block by Default.
- Except for countries - select the countries which should be granted access.
- IP Access
- Access Policy - select Block by Default.
- Except for IP addresses - specify the IP addresses which should be granted access and separate them by a comma.
- If the customer wants to serve the stream with an HTTPS protocol, at the Edit CDN Resource page or at the New CDN Resource page, use one of the following:
- Let’s Encrypt
- SNI SSL
- Shared SSL
- If the stream is to be played in the browser, contact OnApp Support to enable the CORS headers.
- If the stream is played on Samsung TV, contact OnApp Support to suppress the CDN headers on the resource and provide a test link.
How to Test a Stream
- Curl the resource m3u8 playlist and make sure 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 and make sure that the file is served from CDN and is 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 Stream Bandwidth page. Ensure that the cached traffic is increasing and higher than the uncached traffic.