69QVideoFrameFormat
QAVFHelpers::videoFormatForImageBuffer(CVImageBufferRef buffer,
bool openGL)
71 auto cvPixelFormat = CVPixelBufferGetPixelFormatType(buffer);
72 auto pixelFormat = fromCVPixelFormat(cvPixelFormat);
74 if (cvPixelFormat == kCVPixelFormatType_32BGRA)
75 pixelFormat = QVideoFrameFormat::Format_SamplerRect;
77 qWarning() <<
"Accelerated macOS OpenGL video supports BGRA only, got CV pixel format"
81 QVideoFrameFormat format(QAVFHelpers::CVPixelBufferSize(buffer), pixelFormat);
83 auto colorSpace = QVideoFrameFormat::ColorSpace_Undefined;
84 auto colorTransfer = QVideoFrameFormat::ColorTransfer_Unknown;
87 QCFString(CVBufferCopyAttachment(buffer, kCVImageBufferYCbCrMatrixKey,
nullptr))) {
88 if (CFEqual(cSpace, kCVImageBufferYCbCrMatrix_ITU_R_709_2)) {
89 colorSpace = QVideoFrameFormat::ColorSpace_BT709;
90 }
else if (CFEqual(cSpace, kCVImageBufferYCbCrMatrix_ITU_R_601_4)
91 || CFEqual(cSpace, kCVImageBufferYCbCrMatrix_SMPTE_240M_1995)) {
92 colorSpace = QVideoFrameFormat::ColorSpace_BT601;
93 }
else if (CFEqual(cSpace, kCVImageBufferYCbCrMatrix_ITU_R_2020)) {
94 colorSpace = QVideoFrameFormat::ColorSpace_BT2020;
98 if (
auto cTransfer = QCFString(
99 CVBufferCopyAttachment(buffer, kCVImageBufferTransferFunctionKey,
nullptr))) {
101 using QCFNumber = QCFType<CFNumberRef>;
103 if (CFEqual(cTransfer, kCVImageBufferTransferFunction_ITU_R_709_2)) {
104 colorTransfer = QVideoFrameFormat::ColorTransfer_BT709;
105 }
else if (CFEqual(cTransfer, kCVImageBufferTransferFunction_SMPTE_240M_1995)) {
106 colorTransfer = QVideoFrameFormat::ColorTransfer_BT601;
107 }
else if (CFEqual(cTransfer, kCVImageBufferTransferFunction_sRGB)) {
108 colorTransfer = QVideoFrameFormat::ColorTransfer_Gamma22;
109 }
else if (CFEqual(cTransfer, kCVImageBufferTransferFunction_UseGamma)) {
111 QCFNumber(CVBufferCopyAttachment(buffer, kCVImageBufferGammaLevelKey,
nullptr));
113 CFNumberGetValue(gamma, kCFNumberFloat32Type, &g);
118 colorTransfer = QVideoFrameFormat::ColorTransfer_Linear;
120 colorTransfer = QVideoFrameFormat::ColorTransfer_BT709;
122 colorTransfer = QVideoFrameFormat::ColorTransfer_Gamma22;
124 colorTransfer = QVideoFrameFormat::ColorTransfer_Gamma28;
125 }
else if (CFEqual(cTransfer, kCVImageBufferTransferFunction_ITU_R_2020)) {
126 colorTransfer = QVideoFrameFormat::ColorTransfer_BT709;
127 }
else if (CFEqual(cTransfer, kCVImageBufferTransferFunction_ITU_R_2100_HLG)) {
128 colorTransfer = QVideoFrameFormat::ColorTransfer_STD_B67;
129 }
else if (CFEqual(cTransfer, kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ)) {
130 colorTransfer = QVideoFrameFormat::ColorTransfer_ST2084;
134 format.setColorRange(colorRangeForCVPixelFormat(cvPixelFormat));
135 format.setColorSpace(colorSpace);
136 format.setColorTransfer(colorTransfer);