#6237·mediamtx

LL-HLS: PART-TARGET/PART-HOLD-BACK mutate between playlist reloads, permanently killing Apple clients (plus: delta playlists violate Skip Boundary)

Author: yu-seungwoo-777Created Sep 20, 2026Updated Sep 28, 2026

Environment

  • mediamtx v1.21.0 (also verified against current main of gohlslib, see line refs)
  • hlsVariant: lowLatency, hlsSegmentDuration: 2s, hlsPartDuration: 1s, window 60 segments
  • Publisher: RTMP live (30fps H.264 + AAC), remuxed/transcoded by a GStreamer pipeline
  • Client: Apple CoreMedia (WebKit / Safari)

Summary

Two LL-HLS playlist-generation defects kill Apple clients permanently. Defect 1 is the fatal one in our setup: PART-TARGET / PART-HOLD-BACK change between playlist reloads, which CoreMedia rejects with -12642 "illegal PART-HOLD-BACK change" → -12880 "Can not proceed after removing variants" → FailedToPlayToEnd → permanent pause (no retry, no error surfaced to the page).

Defect 1 (fatal): PART-TARGET / PART-HOLD-BACK mutation

gohlslib muxer_stream.go (current main, ~line 770):

go
// while segment target duration can be increased indefinitely,
// part target duration cannot, since
// "The duration of a Partial Segment MUST be at least 85% of the Part Target Duration"
// so it's better to reset it every time.
if s.isLeading {
    partTargetDuration := partTargetDuration(s.segments, s.nextSegment.(*muxerSegmentFMP4).parts)
    if s.partTargetDuration == 0 {
        s.partTargetDuration = partTargetDuration
    } else if partTargetDuration != s.partTargetDuration {
        s.onEncodeError(fmt.Errorf("part duration changed from %v to %v - this will cause an error in iOS clients",
            s.partTargetDuration, partTargetDuration))
        s.partTargetDuration = partTargetDuration   // <-- mutates anyway
    }
}

The library logs "this will cause an error in iOS clients" and then mutates the value anyway. partTargetDuration() returns the max observed part duration over the current window, so a single long part ratchets the estimate up, and when that part rotates out of the window the value drops back — both PART-TARGET and PART-HOLD-BACK (computed as partTargetDuration × 2.5, line ~468) then change between reloads.

Observed on a live stream: PART-HOLD-BACK=2.61750 ↔ 2.72000, PART-TARGET=1.045 → 1.046 → 1.047, with the warning firing 61 times in one hour:

WAR [HLS] [muxer ch/…/program_monitor] part duration changed from 1.045s to 1.047s - this will cause an error in iOS clients

Client-side at the same moments:

StreamPlaylist _StreamPlaylistLogError: illegal PART-HOLD-BACK change
signalled err=-12642
segPumpParseIndexFile: alternate [] could not be parsed; removing it from alternate list
adding -12880 CoreMediaErrorDomain Can not proceed after removing variants
FailedToPlayToEnd → timeControlStatus=Paused (permanent freeze)

Causality isolation: with a static slate source (constant part durations → no re-estimation) the same client, same server, same configuration survived 100% of playback/unmute cycles; with the live transcode path (part durations quantized around frame boundaries, e.g. 1.03–1.07s) the client froze in 18–20 of 20 trials. Playback kept being served normally during the freeze (media sequence kept advancing) — the kill is purely client-side playlist validation.

RFC 8216bis requires the declared server-control values to remain consistent; CoreMedia treats a changed PART-HOLD-BACK as a parse error.

Suggested fix: freeze PART-TARGET/PART-HOLD-BACK after first publication (or quantize the estimate with hysteresis so it never changes once advertised).

Defect 2: delta playlists violate the Skip Boundary invariant

_HLS_skip=YES is answered with a delta unconditionally (~lines 319–324), and SKIPPED-SEGMENTS is computed from the oldest segment (~lines 481–505):

go
var curDuration time.Duration
shown := 0
for _, segment := range s.segments {   // oldest first
    curDuration += segment.getDuration()
    if curDuration >= skipBoundary {
        break
    }
    shown++
}
skipped = len(s.segments) - shown

RFC 8216bis §6.2.5.1: only segments farther than the Skip Boundary from the end of the playlist may be replaced — the reservation must be computed from the live edge, not the oldest entry. Captured live (slate source, ~1.06s segments, CAN-SKIP-UNTIL=18):

full playlist:  #EXT-X-MEDIA-SEQUENCE:0, 25 × #EXTINF
_HLS_skip=YES:  #EXT-X-SKIP:SKIPPED-SEGMENTS=17  → 8 segments shown (≈8.5s) < declared 18s boundary

This produces the other -12642 variant (EXT-X-SKIP too close to live edge), which we have observed in a production log alongside the same failure cascade.

Suggested fix: compute skipped from the live edge backwards (allowed = floor((windowMediaTime − skipBoundary) / targetDuration)), and gate the delta response on msn so edge-near requests get a full playlist.

Reproduction

  1. Run mediamtx v1.21.0 with the LL-HLS config above; publish a 30fps RTMP stream whose frame arrival has normal jitter (e.g. through a transcoder).
  2. Watch the media playlist: PART-TARGET/PART-HOLD-BACK change while part duration changed warnings accumulate.
  3. Play the stream in Safari/WebKit and unmute: CoreMedia dies per Defect 1.
  4. Separately, curl the variant playlist with &_HLS_skip=YES to capture the Defect 2 arithmetic.

Happy to provide full CoreMedia log stream captures and packet-level playlist archives if useful.