AVVideoYCbCrMatrix_ITU_R_709_2 not applied to HDR input via AVAssetReaderOutput when using kCVPixelFormatType_32BGRA

Number:rdar://FB9002885 Date Originated:2/12/2021
Status:Open Resolved:
Product:AVFoundation Product Version:iOS 14.3
Classification:Bug Reproducible:Always
When running an HDR asset through AVAssetReader with the intent to convert to SDR, we use the following settings on AVAssetReaderOutput:

kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA),
AVVideoColorPropertiesKey: @{                                                                               
    AVVideoColorPrimariesKey : AVVideoColorPrimaries_ITU_R_709_2,
    AVVideoTransferFunctionKey : AVVideoTransferFunction_ITU_R_709_2,
    AVVideoYCbCrMatrixKey : AVVideoYCbCrMatrix_ITU_R_709_2

The sample buffers vended by the output have the following properties:
    CVImageBufferColorPrimaries = "ITU_R_709_2";
    CVImageBufferTransferFunction = "ITU_R_709_2";
    CVImageBufferYCbCrMatrix = "ITU_R_2020";

In other words, AVVideoYCbCrMatrixKey is not getting applied. This is particularly a problem for AVCompositions consisting of both HDR and SDR assets, as it causes the SDR asset to appear darker than it should.

It seems that there are two ways to mitigate this.
- Using a different pixel format such as kCVPixelFormatType_420YpCbCr8Planar.
- Applying an AVVideoComposition with the same properties:
    colorPrimaries = AVVideoColorPrimaries_ITU_R_709_2;
    colorTransferFunction = AVVideoTransferFunction_ITU_R_709_2;
    colorYCbCrMatrix = AVVideoYCbCrMatrix_ITU_R_709_2;

Then, the buffers vended appear as follows:
    CVImageBufferColorPrimaries = "ITU_R_709_2";
    CVImageBufferTransferFunction = "ITU_R_709_2";
    CVImageBufferYCbCrMatrix = "ITU_R_709_2";


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!