audioffmpegvideo-streaminghttp-live-streamingaac

How is the AAC encoder priming delay handled in HLS?


As per Apple, in AAC encoding 2112 priming samples are added at the beginning of audio. When creating HLS stream with AAC audio, will these priming samples be added to the beginning of each HLS segment or only to the first HLS segment? And, how does this AAC encoder delay affect HLS DISCONTINUITY tags later in the HLS stream?

https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFAppenG/QTFFAppenG.html


Solution

  • I depends on the AAC you use.

    For 'old-style' AAC-LC you only have priming samples at the beginning of the stream and not at the beginning of each segment. But the delay is carried through the entire stream.

    Typically a new piece of media is displayed after a DISCONTINUITY tag - for example an advertisement - so you will receive another set of priming samples.

    Your AAC audio decoder needs to discard the priming samples (first 2112) PCM output samples after startup and after DISCONTINUITY.

    If you use the more modern xHE-AAC - you don't have to worry about priming samples anymore.

    Another wrinkle - in the early days it was just assumed that AAC-LC has 2112 priming samples. Now the number can be different and it can be signaled in the MP4 container as Edit-List.