VionetoVioneto
Back to the magazine

VIONETO MAGAZINE Playback & technology

Check an HLS timestamp reset with EXT-X-DISCONTINUITY

Inspect MPEG-TS presentation timestamps with ffprobe, locate a reset at an HLS segment boundary, and mark the segment that starts the new sequence.

Two rising timestamp traces start from a low point on either side of a marked segment boundary.
The tag marks the segment after the boundary where the timestamp sequence restarts.Image: Vioneto · original illustration

An HLS programme switches from an opening slate to a feed from a second encoder. The picture format can stay the same even when the presentation timestamps restart. A problem may only show up when playback reaches that boundary. Start by checking whether the segments on either side belong to a continuous timestamp sequence.

Inspect each segment separately

For a test with your own files, take the last MPEG-TS segment before the boundary and the first one after it. Use ffprobe to print the PTS values for the first video stream. Run the command once with a.ts and again with b.ts as the final argument.

ffprobe -v error -select_streams v:0 -show_packets -show_entries packet=pts_time -of csv=p=0 a.ts

Our controlled example used two segments that each contained two seconds of video at 12 frames per second. Both ran from a PTS of 0 to about 1.917 seconds. The second segment therefore starts a new timestamp sequence. For real footage, inspect the other tracks and check how your encoder is meant to timestamp them. Frame reordering can produce a backwards-looking value in packet order, so look for evidence of a reset at the segment boundary itself.

Place the marker before the following segment

RFC 8216 calls for EXT-X-DISCONTINUITY before the segment that starts the changed timestamp sequence. The rule also covers changes to the file format and to the number, types or identifiers of tracks. Our sample marks the boundary after a.ts and before the entry for b.ts.

#EXTM3U #EXT-X-VERSION:3 #EXT-X-TARGETDURATION:2 #EXT-X-MEDIA-SEQUENCE:0 #EXTINF:2.000, a.ts #EXT-X-DISCONTINUITY #EXTINF:2.000, b.ts #EXT-X-ENDLIST

ffprobe 8.0.1 read 48 video frames from the marked local playlist. That confirms the result for these synthetic test files. On your own stream, play through the boundary in the players that matter and check audio, video, and seeking close to the change.

Test a quality switch if you have multiple renditions

Align the segments and discontinuity sequences so a player can locate the same programme point across renditions. For a sliding live playlist, also check how the discontinuity sequence changes as old entries are removed. This exercises the boundary that viewers encounter when the selected quality changes.

Check fMP4 initialization with EXT-X-MAP

Topics

Sources and further reading

  1. https://www.rfc-editor.org/rfc/rfc8216.html#section-4.3.2.3
  2. https://www.rfc-editor.org/rfc/rfc8216.html#section-6.2.1
  3. https://ffmpeg.org/ffprobe.html