This document is intended to help users for their own HLS configuration, you will found following few tips which will guide you for a better understanding.
What is HLS ? (HTTP Live Streaming)
HLS is working totally differently compared to other technologies commonly used for streaming (Icecast, Shoutcast…). In few words, HLS consists in pushing audio segments to a normal HTTP server, and at listener side a dedicated application or compatible browser will download each segment and aggregate them for decoding.
One of the great improvement brought by HLS is the possibility to send several synchronized bitrates. At client side, the application or compatible browser will automatically download segments according to available bandwidth, and change to another bitrate in real time without any sound interruption if more or less bandwidth is available.
Codecs and sample rates…
HLS supports several codecs: MP3, AAC, HE-AAC. We don’t recommend to use HE-AAC v2 because of incompatibility with some old mobile phones. Practically, if your goal is to send several bitrates, you will have to respect those points for all synchronized bitrates:
- Always use same codec type (AAC, or HE-AAC...)
- Always use same sample rate
If you don’t respect those tips, at listening side you will notice drops when automatically switching from one bitrate to another.
Always SFTP and not FTP!
For sending segments to your web server, you will have to use SFTP protocol and not FTP because the FTP will have to open and close a connection for each segment to send. Because of security protections, your web provider will in most cases automatically blacklist you and block your FTP connection because it will interpret those many connections as an attack...
Encoder Setup
Supposing you want to push 2 bitrates, you will have to create 2 streaming instances in SOUND4 Streaming encoder. Here is how to proceed:
- Create a first HLS instance (Main), and setup all parameters:
- Protocol: HLS sftp
- Encoder : AAC or HE-AAC
- Bitrate: Select a possible bitrate according to your encoder choice (ie: 128).
- Adaptive process: This feature is intended to optimize sound bandwidth for very low bitrate, when the receiver's mobile device will switch to low bitrate the listener will not notice a big difference (ie: from HE-AAC 128 to HE-AAC 32 if adaptive process is activated on 32 kbps stream).
- Host/Path: hostname and path to the segments on the Web Server, ie: myserver.com/hls/fragments
- Mount/ID/BaseName: Segment File basename. We recommend using the quality of this encoding as basename, ie: High (or med or low)
- Port: “Default” if you are using default SFTP port
- User and Password: Current SFTP user and server password
- Sample rate: must be the same for all HLS synchronized streams
- HQ: When activated, SOUND4 encoder will run in highest resolution and deliver best quality
- Fragment time: We recommend 6.4 seconds duration segments which is a proven value for audio streaming
- Fragment count: This value defines how many segments will have to be preloaded to avoid the loss of stream (in case of bandwidth difficulties in receiving). We recommend 5 which correspond to 32 seconds preloading.
- SSH Server Fingerprint: this is the SSH public key hash, this hash will be automatically updated from your SFTP server when you will activate stream at first time, so you normally don’t have to provide it. Note: for security reason, some web providers update keys periodically, ask your provider if this may happen. If this happens, you may either enter the new key, or erase it to get the new one automatically.
- Create a second HLS Instance for another bitrate (HLS Sync)
- Protocol: HLS Sync
- Encoder: Same as you previously set in “Main HLS Stream”
- Bitrate: Select a possible bitrate according to your encoder choice (ie: 64)
- Adaptive process: see above.
- Host/Path: not required
- Mount/ID/BaseName: see above, ie: Low
- Port: Not required
- User and Password: Not required
- Sample rate: must be same for all HLS synchronized streams
- HQ: see above
- Fragment time: Not required
- Fragment count: Not required
- SSH Server Fingerprint: Not required
Then you can create other Synch HLS instances for different bitrates, usually our users are commonly using 3 different bitrates (ie in HE-AAC: 128, 64 and 32).
Note: Order of streams instances will not have any effect in HLS receiving, so you can get Main in 128, second in 32 and third in 64... Order in receiving will have to be defined in your m3u8 file at server side, as discussed below.
Now if you setup all correctly you can activate “General” Streaming function and activate “Main HLS instance”, then in status you should see “running” for each instance.
When started, SOUND4 Stream will push to the server separate .m3u8 files according to HLS streams you set previously, then upload of segments will start…
Server side: Create your m3u8 file for whole stream description available
To be able to decode available streams, your HLS compatible application or browser will need to know the list of available streams as well as the codec and bitrate, this information will have to be listed in a “general m3u8 file” which you will now create and upload manually to your site in your root HLS directory. The filename can be anything, with m3u8 extension, eg master.m3u8
Example of information contained in a m3u8 file:
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=32000,CODECS="mp4a.40.5"
fragments/low.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=64000,CODECS="mp4a.40.5"
fragments/med.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=128000,CODECS="mp4a.40.5"
fragments/high.m3u8
Practically, your HLS or compatible browser will always start by listening to the first stream in the list. Here, it is a 32 kbps stream, then if the bandwidth allows it, it will automatically switch to higher quality streams.
We recommend you to always put lower stream quality in first, then loading stream time will be faster.
In the example you can see that codec is set by a code “mp4a.40.5”, here is the list of codes to be used according to the one you define in SOUND4 Stream:
- AAC: mp4a.40.2
- HeAAC: mp4a.40.5
- HeAAC-v2: mp4a.40.29 (not recommended because of incompatibility with some mobiles or browser)
- MP3: mp4a.40.34
BANDWIDTH parameter is an estimation of max bandwidth (bits per second) needed by this codec, normally it should be a bit higher than codec bitrate (+10%), but all our tests did not prove this necessity.
Your HLS player will directly use the file you created:
(http://myserver.com.com/hls/master.m3u8 in our example) to dynamically select the stream adapted to the current bandwidth
HLS apps & browser integration
On server side, HTTP server is all what is needed. It should be sized for high demand delivery, according to your needs.
SOUND4 does not provide a client HLS application because it is not our job but that of your webmaster or your web host.
Basically, some browsers are directly compatible (Apple), but for others we recommend using HLS player scripts. We have successfully tested Viblast (https://viblast.com/player/), of course there are others ...
About metadata...
There is no metadata standard in HLS, usually metadata are broadcasted in parallel of HLS stream, this implementation must be handled by your webmaster or web host.