Closed iTofu closed 7 years ago
I may found the reason, it was my fault. It may because queue's qos was too low: .global(qos: .background)
, it works well with this qos:
DispatchQueue.global().async {
}
And operation that update UI should be in main queue, so all code should like this:
var videoCamera: GPUImageVideoCamera!
var filter: GPUImageOutput!
var filterView: GPUImageView!
func setupPreview() {
DispatchQueue.global().async {
self.videoCamera = GPUImageVideoCamera(sessionPreset: AVCaptureSessionPreset1280x720, cameraPosition: .front)
self.videoCamera.do({
$0.horizontallyMirrorFrontFacingCamera = true
$0.outputImageOrientation = UIApplication.shared.statusBarOrientation
$0.addAudioInputsAndOutputs()
})
self.resetFilter(withType: self.filterType)
self.filterView = GPUImageView().then({
$0.fillMode = kGPUImageFillModePreserveAspectRatioAndFill
})
DispatchQueue.main.async {
self.recordView?.addSubview(self.filterView)
self.filterView.snp.makeConstraints({ (make) in
make.edges.equalToSuperview()
})
self.recordView?.alpha = 0
UIView.animate(withDuration: 0.5, animations: { [weak self] in
self?.recordView?.alpha = 1.0
})
}
self.videoCamera.addTarget(self.filter as! GPUImageInput!)
self.filter.addTarget(self.filterView)
self.videoCamera.startCapture()
}
}
And thanks for GPUImage's author @BradLarson , I like this repo :)
ENV:
Code:
And I got this error message:
Crash Info: