Is it possible to control the conversion of RGB to YUV matrix in VideoToolBox?

571 views Asked by At

I found that different Iphone hardware encoders have different matrices for converting input RGB to YUV.That is, in the function OSStatus VTCompressionSessionEncodeFrame(VTCompressionSessionRef session, CVImageBufferRef imageBuffer, CMTime presentationTimeStamp, CMTime duration, CFDictionaryRef frameProperties, void *sourceFrameRefcon, VTEncodeInfoFlags *infoFlagsOut); the imageBuffer format is RGB.Before encoding, VideoToolBox will convert RGB to YUV and send it to the encoder.I want to know what kind of matrix VideoToolBox uses for RGB conversion to YUV, and how to control the selection of the conversion matrix. Among the input parameters of the hardware encoder VideoToolbox, only kVTCompressionPropertyKey_YCbCrMatrix is related to color conversion.But this parameter does not control the input RGB to YUV matrix. Because I tried to enter a different value, it didn't change.This leads to the inability to match the matrix during decoding, which causes chromatic aberration.I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this.

2

There are 2 answers

0
马学睿 On BEST ANSWER
    CFMutableDictionaryRef attrs = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    CFDictionarySetValue(attrs, kVTPixelTransferPropertyKey_DestinationYCbCrMatrix, kCVImageBufferYCbCrMatrix_ITU_R_601_4);//kCVImageBufferYCbCrMatrix_ITU_R_709_2
    status = VTSessionSetProperty(_encoderSession, kVTCompressionPropertyKey_PixelTransferProperties, attrs);
0
马学睿 On

The problem has been resolved. Set kVTCompressionPropertyKey_PixelTransferProperties to control the conversion of RGB to YUV matrix in VideoToolBox