[FEAT] Add pat + pmt to beginning of each HLS output TS segment
YouTube requires each segment in an HLS stream contains both PAT & PMT, and these should be the first two TS packets in each segment, I haven't ran the segments through an analyser to check if they do today so apologies if it already does this, but if doesn't, is this a new flag that could possibly be added to the HLS output plugin please?
YouTube requires each segment in an HLS stream contains both PAT & PMT, and these should be the first two TS packets in each segment,
This is not a YouTube requirement, this is specified in the HLS standard and this is consequently what is done in TSDuck.
Apart from any consideration from standards, this is simply a matter of logic. Any packet before the PAT and PMT would be useless in an SPTS file.
Additional notes:
- The standard incorrectly assumes the PMT fits into one TS packet. In practice, this is the case with all simple streams as commonly found in basic Internet streaming. However, when grabbing a complex broadcast stream, the PMT may be larger. Any decent TS player should demux sections from the streams according to MPEG rules and never assume that a section always fits into one single TS packet.
- With the
hlsoutput plugin from TSDuck, the output segments are split from the input stream, after going through all plugins. If the input does not start with a PAT and PMT, the first output segment will start with the beginning of the stream, not a PAT/PMT pair. For subsequent segments, thehlsoutput plugin always keeps a copy of the last PAT and PMT and adds a copy of them at the beginning of each segment.
In case the start of the first segment is an issue, I added the option --align-first-segment. Using this option, all TS packets before the first PAT, PMT, video PES packet boundary (and optionally I-frame) are dropped. Thus, the start of the first segment is HLS-conformant, at the expense of losing some initial TS packet, your choice.
Automatically closed after 176 days without update and "close pending" label set.