Address re-review: AAC re-encode, probe fallthrough, HDR detection

- Android non-AAC audio is now transcoded to AAC (matching iOS) via a
  source-decoder -> AAC-encoder pre-pass that captures the encoder's
  output format before the muxer starts, then writes buffered samples
  after the video pipeline finishes. Falls back to dropping audio if
  the transcode fails.
- compress.ts wraps probe() in try/catch and falls through to
  passthrough on failure instead of throwing.
- Probers expose isHDR (HLG/PQ via color transfer, plus Dolby Vision
  codecs/mimes); shouldCompress forces compression for HDR sources so
  the SDR BT.709 path always runs. Also sets
  KEY_COLOR_TRANSFER_REQUEST=SDR on the Android decoder (API 31+) so
  HDR sources tone-map to SDR pixels instead of being mislabeled.
This commit is contained in:
vineyardbovines
2026-06-20 14:43:57 -04:00
parent 34ee7bafda
commit fd387904d4
5 changed files with 270 additions and 8 deletions
@@ -23,8 +23,24 @@ struct VideoProber {
let formatDescriptions = try await videoTrack.load(.formatDescriptions)
var codec = "unknown"
var isHDR = false
if let formatDescription = formatDescriptions.first {
codec = fourCCToString(CMFormatDescriptionGetMediaSubType(formatDescription))
let subType = CMFormatDescriptionGetMediaSubType(formatDescription)
codec = fourCCToString(subType)
// Dolby Vision codecs are HDR by definition.
let dolbyVisionSubtypes: Set<String> = ["dvhe", "dvh1", "dvav", "dva1"]
if dolbyVisionSubtypes.contains(codec) {
isHDR = true
} else if let extensions = CMFormatDescriptionGetExtensions(formatDescription)
as? [String: Any]
{
let transferKey = kCMFormatDescriptionExtension_TransferFunction as String
if let transfer = extensions[transferKey] as? String {
let hlg = kCMFormatDescriptionTransferFunction_ITU_R_2100_HLG as String
let pq = kCMFormatDescriptionTransferFunction_SMPTE_ST_2084_PQ as String
isHDR = transfer == hlg || transfer == pq
}
}
}
let rotation = rotationFromTransform(preferredTransform)
@@ -66,7 +82,8 @@ struct VideoProber {
"codec": codec,
"hasAudio": hasAudio,
"frameRate": nominalFrameRate,
"rotation": rotation
"rotation": rotation,
"isHDR": isHDR
]
}