gpt4 book ai didi

ios - 输出相机帧缓冲区不会出现

转载 作者:行者123 更新时间:2023-11-28 15:05:30 25 4
gpt4 key购买 nike

我为相机类实现了 AVCaptureVideoDataOutputSampleBufferDelegate

设置所需的视频输入并开始 session ,摄像头工作正常,可以在预览中看到

我也想获得一些处理的像素缓冲区

fileprivate func configureVideoOutput() {
let videoOutput = AVCaptureVideoDataOutput()
videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "sample buffer"))

if self.session.canAddOutput(videoOutput) {
print("canAddOutput yes")
self.session.addOutput(videoOutput)
print("canAddOutput yes added")
} else {
print("canAddOutput no")
}
}

func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {
print("Got a frame!")
}

它打印 "canAddOutput yes added" ok

但它从不打印 "Got a frame!"

最佳答案

必须先设置输出类型

videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA]

编辑:将委托(delegate)函数改为

public func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
print("Got a frame 1!")
}

关于ios - 输出相机帧缓冲区不会出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48537702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com