Skip to content

Commit 654da7f

Browse files
Vincent Herbstclaude
andcommitted
fix(dv): P5 colr override fills range gap instead of forcing limited
The Profile 5 color-signaling override forced AVCOL_RANGE_MPEG (limited) unconditionally on every P5 source. A P5 MP4 that already signals a range (including a legal full-range source) was stomped down to limited and shifted colours. Primaries / transfer / matrix stay forced: P5 is spec-fixed to IPT-PQ-c2 (BT.2020 / PQ / BT.2020-NCL) with no legal alternate, so forcing them is a repair, not an overwrite. Range is the only field with a legitimate alternate, so it now passes a present source signal through and only fills AVCOL_RANGE_MPEG when the source leaves it AVCOL_RANGE_UNSPECIFIED. The #19 repro (all color fields unspecified) still resolves to the full canonical P5 tuple, so no regression there. Refs #20 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 10f002a commit 654da7f

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

‎Sources/AetherEngine/Video/HLSVideoEngine.swift‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -612,17 +612,31 @@ public final class HLSVideoEngine: @unchecked Sendable {
612612
// Colour element directly into codecpar.color_* so the same
613613
// content as MKV plays cleanly; the mp4 demuxer has no
614614
// equivalent fallback. Forcing the canonical P5 color tuple
615-
// here makes the muxer write a `colr nclx 9/16/9` atom that
616-
// AVPlayer reads as the missing PQ signal. Safe to overwrite:
617-
// P5 has no legal alternate color signaling.
618-
let p5ColorOverride: MP4SegmentMuxer.ColorOverride? = (dvVariant == .profile5)
619-
? MP4SegmentMuxer.ColorOverride(
615+
// here makes the muxer write a `colr nclx` atom that AVPlayer
616+
// reads as the missing PQ signal.
617+
//
618+
// Primaries / transfer / matrix are spec-fixed for P5 (IPT-PQ-c2
619+
// has no legal alternate), so forcing them is a repair, not an
620+
// overwrite of valid data. Color range is the exception: P5 is
621+
// typically limited but full-range P5 is legal, so a source that
622+
// already signals a range keeps it (fill-the-gap, not stomp).
623+
// The #19 repro has range unspecified, so it still resolves to
624+
// limited; a properly-signaled full-range P5 is no longer forced
625+
// down to limited (issue #20, DrHurt).
626+
let p5ColorOverride: MP4SegmentMuxer.ColorOverride?
627+
if dvVariant == .profile5 {
628+
let sourceRange = codecpar.pointee.color_range
629+
p5ColorOverride = MP4SegmentMuxer.ColorOverride(
620630
primaries: AVCOL_PRI_BT2020,
621631
trc: AVCOL_TRC_SMPTE2084,
622632
space: AVCOL_SPC_BT2020_NCL,
623-
range: AVCOL_RANGE_MPEG
633+
range: sourceRange == AVCOL_RANGE_UNSPECIFIED
634+
? AVCOL_RANGE_MPEG
635+
: sourceRange
624636
)
625-
: nil
637+
} else {
638+
p5ColorOverride = nil
639+
}
626640
let videoConfig = HLSSegmentProducer.StreamConfig(
627641
codecpar: codecpar,
628642
timeBase: videoTimeBase,

0 commit comments

Comments
 (0)