From b83d744fdd88c48b5afd75236d8b535b02ffff9f Mon Sep 17 00:00:00 2001 From: jcm Date: Tue, 30 Apr 2024 13:05:17 -0500 Subject: [PATCH] set primaries on pixel buffer to hopefully fix flickering --- CaptureSample/Encoder.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CaptureSample/Encoder.swift b/CaptureSample/Encoder.swift index 4f9f573..42ca717 100644 --- a/CaptureSample/Encoder.swift +++ b/CaptureSample/Encoder.swift @@ -41,6 +41,7 @@ class VTEncoder { var hasStarted = false var isStarting = false var decodes = true + var options: Options private let logger = Logger.encoder @@ -48,6 +49,7 @@ class VTEncoder { self.destWidth = options.destWidth self.destHeight = options.destHeight let sourceImageBufferAttributes = [kCVPixelBufferPixelFormatTypeKey: options.pixelFormat as CFNumber] as CFDictionary + self.options = options let err = VTCompressionSessionCreate(allocator: kCFAllocatorDefault, width: Int32(options.destWidth), @@ -243,6 +245,15 @@ class VTEncoder { func encodeFrame(buffer: CVImageBuffer, timeStamp: CMTime, duration: CMTime, properties: CFDictionary?, infoFlags: UnsafeMutablePointer?) { if self.stoppingEncoding != true { var pixelBufferToEncodeFrom: CVPixelBuffer + if let primaries = options.colorPrimaries { + CVBufferSetAttachment(buffer, kCVImageBufferColorPrimariesKey, primaries, .shouldPropagate) + } + /*if let matrix = options.yuvMatrix { + CVBufferSetAttachment(buffer, kCVImageBufferYCbCrMatrixKey, matrix, .shouldPropagate) + }*/ + /*if let tf = options.transferFunction { + CVBufferSetAttachment(buffer, kCVImageBufferTransferFunctionKey, tf, .shouldPropagate) + }*/ if pixelTransferSession != nil { if self.pixelTransferBuffer == nil { self.pixelTransferBuffer = copyPixelBuffer(withNewDimensions: self.destWidth, y: self.destHeight, srcPixelBuffer: buffer)