gpt4 book ai didi

ios - didOutputSampleBuffer 委托(delegate)永远不会被调用 (iOS/Swift 3)

转载 作者:行者123 更新时间:2023-11-28 09:52:49 27 4
gpt4 key购买 nike

我正在尝试跟踪视频录制的样本缓冲率。

我有一个带有 AVCaptureFileOutputRecordingDelegateAVCaptureVideoDataOutputSampleBufferDelegate 的 View Controller ,然后像这样设置缓冲区输出:

sessionQueue.async { [weak self] in
if let `self` = self {
let movieFileOutput = AVCaptureMovieFileOutput()

let bufferQueue = DispatchQueue(label: "bufferRate", qos: .userInteractive, attributes: .concurrent)

let theOutput = AVCaptureVideoDataOutput()
theOutput.videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString): NSNumber(value:kCVPixelFormatType_32BGRA)]
theOutput.alwaysDiscardsLateVideoFrames = true
theOutput.setSampleBufferDelegate(self, queue: bufferQueue)

if self.session.canAddOutput(theOutput) {
self.session.addOutput(theOutput)
print("ADDED BUFFER OUTPUT")
}

if self.session.canAddOutput(movieFileOutput) {
self.session.beginConfiguration()
self.session.addOutput(movieFileOutput)
self.session.sessionPreset = AVCaptureSessionPresetHigh
if let connection = movieFileOutput.connection(withMediaType: AVMediaTypeVideo) {
if connection.isVideoStabilizationSupported {
connection.preferredVideoStabilizationMode = .auto
}
}

self.session.commitConfiguration()

self.movieFileOutput = movieFileOutput

DispatchQueue.main.async { [weak self] in
if let `self` = self {
self.recordButton.isEnabled = true
}
}
}
}
}

此外,我还设置了读取缓冲区的函数:

func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {
print("captured \(sampleBuffer)")
}

问题是,当运行相机时,它会像预期的那样正确记录(代码未显示,因为它正常工作)但永远不会调用 captureOutput 样本缓冲区。我究竟做错了什么?我认为这与我设置它的方式有关?

最佳答案

确保委托(delegate)签名使用 Swift 3 语法正确。

func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, 来自连接: AVCaptureConnection)

我使用的是 Swift 2.3 语法,编译器没有警告我这个问题。尝试输入 didOut sampleBuffer 并检查 XCode 是否自动更正该委托(delegate)方法的正确语法。

关于ios - didOutputSampleBuffer 委托(delegate)永远不会被调用 (iOS/Swift 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43681929/

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