Search code examples
videovideo-streaminghttp-live-streamingmpeg2-ts

HLS segment (.ts) internal format


I try to understand how HLS segmenter converts MPEG-TS packets into HLS chunks. Does HLS chunk incapsulates several MPEG-TS packets, or it's a completely different format and differs from MPEG-TS? For example, can I retrieve PCR (Program Clock Reference) or other MPEG-TS specific data?


Solution

  • According to the spec:

    Each Media Segment MUST be formatted as an MPEG-2 Transport Stream [ISO_13818], a WebVTT [WebVTT] file, or a Packed Audio file ...

    In other words: HLS is built on top of MPEG-TS. Video is always formatted as an MPEG Transport Stream. Subtitles use WebVTT. Audio can formatted either as an MPEG-TS or raw AAC/MP3 frames.

    When video/audio is formatted as MPEG-TS, each HLS segment is self contained (i.e. contains all necessary decoding information) and consists of many MPEG-TS packets (an MPEG-TS packet is just 188 bytes).

    Yes, you can retrieve PCR and everything else that's embedded in the MPEG-TS, for instance ID3 metadata, other multiplexed streams, CEA 608/708 and so on.

    The next version of HLS will allow fragmented MP4 to be used as an alternative to MPEG-TS for video/audio but at the moment support is limited.