Skip to content

Commit

Permalink
set primaries on pixel buffer to hopefully fix flickering
Browse files Browse the repository at this point in the history
  • Loading branch information
jcm committed Apr 30, 2024
1 parent b9881ac commit b83d744
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions CaptureSample/Encoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ class VTEncoder {
var hasStarted = false
var isStarting = false
var decodes = true
var options: Options

private let logger = Logger.encoder

init?(options: Options) async throws {
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),
Expand Down Expand Up @@ -243,6 +245,15 @@ class VTEncoder {
func encodeFrame(buffer: CVImageBuffer, timeStamp: CMTime, duration: CMTime, properties: CFDictionary?, infoFlags: UnsafeMutablePointer<VTEncodeInfoFlags>?) {
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)
Expand Down

0 comments on commit b83d744

Please sign in to comment.