Skip to content

fix(rune-media): accept AVFoundation YCbCrMatrix#5 and #6 attachments as BT.601 on macOS - #1517

Merged
Hona merged 1 commit into
devfrom
fix/1111-ycbcr-matrix-5
Nov 23, 2026
Merged

Hona merged 1 commit into
devfrom
fix/1111-ycbcr-matrix-5

Conversation

@Hona

@Hona Hona commented Nov 23, 2026

Copy link
Copy Markdown
Member

Fixes #1111

Root cause

  • PixelBuffer::info (crates/rune-media/src/native_surface/macos.rs) only matched kCVImageBufferYCbCrMatrix_ITU_R_601_4 and kCVImageBufferYCbCrMatrix_ITU_R_709_2 on kCVImageBufferYCbCrMatrixKey.
  • CoreVideo has no named constant for H.264 / H.273 matrix_coefficients = 5 (BT.470BG / BT.601-7 625, emitted by ffmpeg/libx264), so AVFoundation attaches the raw code-point string "YCbCrMatrix#5", causing playback to fail with unsupported YCbCr matrix; use BT.601 or BT.709.

Changes

  • Map "YCbCrMatrix#5" (BT.470BG) and "YCbCrMatrix#6" (SMPTE 170M) in crates/rune-media/src/native_surface/macos.rs to Matrix::Bt601, per ITU-T H.264 Table E-5 and ITU-T H.273 Table 4 (both define Kr = 0.299, Kb = 0.114).
  • Keep existing None, kCVImageBufferYCbCrMatrix_ITU_R_601_4, and kCVImageBufferYCbCrMatrix_ITU_R_709_2 mappings unchanged, and continue rejecting BT.2020, SMPTE 240M, FCC, and unknown matrices.
  • Add macOS unit test ycbcr_matrix_5_and_6_map_to_bt601_and_other_codes_are_rejected in crates/rune-media/src/native_surface/macos_tests.rs.
  • Add changelog fragment changelog/unreleased/2026-11-23-macos-ycbcr-matrix-5.md.

Verification

  • macOS: cargo test -p rune-media --lib native_surface::macos (failed before fix on "YCbCrMatrix#5", passed after fix), cargo check -p rune-media --tests, cargo check -p rune -p rune-kit --tests.
  • Windows: cargo test -p rune-media (80 unit tests + 4 doctests passed).
  • CI check: scripts/file-size.sh (0 errors).
  • Not checked: live AVPlayer playback of a real ffmpeg-encoded H.264 file in a desktop window.

@Hona
Hona merged commit 27e43ad into dev Nov 23, 2026
1 check passed
@Hona
Hona deleted the fix/1111-ycbcr-matrix-5 branch November 23, 2026 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

video fails with "unsupported YCbCr matrix" for ffmpeg-made H.264 (matrix_coefficients 5)

1 participant