AVPlayerItemVideoOutput Converting HDR Video to SDR not work

My app want Converting iphone12 HDR Video to SDR,to edit。 follow the doc Apple-HDR-Convert.

My code setting the pixBuffAttributes

       [pixBuffAttributes setObject:(id)(kCVImageBufferYCbCrMatrix_ITU_R_709_2) forKey:(id)kCVImageBufferYCbCrMatrixKey];
      [pixBuffAttributes setObject:(id)(kCVImageBufferColorPrimaries_ITU_R_709_2) forKey:(id)kCVImageBufferColorPrimariesKey];
      [pixBuffAttributes setObject:(id)kCVImageBufferTransferFunction_ITU_R_709_2 forKey:(id)kCVImageBufferTransferFunctionKey];
 
    playerItemOutput = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:pixBuffAttributes];

but I get the playerItemOutput's output buffer

 CFTypeRef colorAttachments = CVBufferGetAttachment(pixelBuffer, kCVImageBufferYCbCrMatrixKey, NULL);
    CFTypeRef colorPrimaries = CVBufferGetAttachment(pixelBuffer, kCVImageBufferColorPrimariesKey, NULL);
    CFTypeRef colorTransFunc = CVBufferGetAttachment(pixelBuffer, kCVImageBufferTransferFunctionKey, NULL);
     NSLog(@"colorAttachments = %@", colorAttachments);
    NSLog(@"colorPrimaries = %@", colorPrimaries);
    NSLog(@"colorTransFunc = %@", colorTransFunc);

log output: colorAttachments = ITU_R_2020 colorPrimaries = ITU_R_2020 colorTransFunc = ITU_R_2100_HLG

pixBuffAttributes setting output format invalid,please help!

Replies

did you fix this problem?

Finally figured it out with the help of this WWDC session: https://developer.apple.com/videos/play/wwdc2022/110565/?time=653 You can use the initializer with outputSettings instead of pixelBufferAttributes and the AVFoundations keys and values to use there do work like the document specifies: (pardon my Swift)

let output = AVPlayerItemVideoOutput(outputSettings: [
    AVVideoColorPropertiesKey: [
        AVVideoColorPrimariesKey: AVVideoColorPrimaries_ITU_R_709_2,
        AVVideoTransferFunctionKey: AVVideoTransferFunction_ITU_R_709_2,
        AVVideoYCbCrMatrixKey: AVVideoYCbCrMatrix_ITU_R_709_2
    ],
    kCVPixelBufferPixelFormatTypeKey as String: NSNumber(value: cvPixelBufferFormat),
    kCVPixelBufferIOSurfacePropertiesKey as String: [:],
    kCVPixelBufferMetalCompatibilityKey as String: true
] as [String: Any])