ios - 限制 AVCaptureVideoDataOutputSampleBufferDelegate 调用
问题描述
有谁知道如何限制正在调用的 sampleBufferDelegate 调用?我想让它每秒只调用 15 次,但不知道如何处理这个......
private lazy var captureSession: AVCaptureSession = {
let fps: Int32 = 15
let session = AVCaptureSession()
session.sessionPreset = AVCaptureSession.Preset.photo
guard
let backCamera = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back),
let input = try? AVCaptureDeviceInput(device: backCamera)
else { return session }
do {
try backCamera.lockForConfiguration()
backCamera.activeVideoMinFrameDuration = CMTimeMake(1, fps)
backCamera.activeVideoMaxFrameDuration = CMTimeMake(1, fps)
backCamera.unlockForConfiguration()
} catch {
Logger.error(error.localizedDescription)
}
session.addInput(input)
return session
}()
public lazy var cameraLayer = AVCaptureVideoPreviewLayer(session: self.captureSession)
//--------------------------------------------------------------------------
// MARK: - View life cycle
//--------------------------------------------------------------------------
override func awakeFromNib() {
super.awakeFromNib()
self.cameraLayer.connection?.videoOrientation = self.transformOrientation(orientation: UIInterfaceOrientation(rawValue: UIApplication.shared.statusBarOrientation.rawValue)!)
self.layer.insertSublayer(self.cameraLayer, at: 0)
self.cameraLayer.videoGravity = .resizeAspectFill
let videoOutput = AVCaptureVideoDataOutput()
videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)]
videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "MyQueue"))
self.captureSession.addOutput(videoOutput)
self.captureSession.startRunning()
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(getManual(sender:)))
tapGestureRecognizer.cancelsTouchesInView = false
self.addGestureRecognizer(tapGestureRecognizer)
self.addSubViewToBoundaries(self.detectedImagesView, edgeInsets: .zero)
self.detectedImagesView.isUserInteractionEnabled = false
self.insertSubview(self.detectedImagesView, at: 1)
}
解决方案
想不通....最后,我实现了一个计时器,并且仅在计时器经过足够多的时间后才调用委托....
推荐阅读
- android - 如何查看/更新数据库版本?有没有像“fallbackToDestructiveMigration”这样的东西?
- docker - Gitlab容器注册表抛出TLS握手超时错误
- listview - 当项目源动态更改时,我在 listview 内的 Swipe 视图中遇到问题
- ios - 无法打开 ips 文件 - iOS 崩溃报告 - 似乎是 json 格式,而不是之前的崩溃格式
- python-3.x - pandas tz_convert 为同一时区提供不同的偏移量
- python - 编译包含 boost/python 的 C++ 文件时出错
- delphi - Delphi在两个项目中共享单元
- python - 使用 json 将字符串转换为 dict 时出错
- python - 在比较值时将来自一个数据帧的字符串添加到第二个数据帧的新列中
- flutter - Flutter,在另一个类中修改后发送并获取值