0

当我继续尝试录制视频然后完成录制时,我遇到了这样的崩溃

FirstGPUImage[768:179067] *** Terminating app due to uncaught 
exception 'NSInternalInconsistencyException', reason: 'Unable to create 
an OpenGL ES 2.0 context. The GPUImage framework requires OpenGL ES 2.0 
support to work.'

XCode 中的错误截图

不知道是不是我自己的代码或者GPUImageMovieWrite有问题,所以想请教一下为什么!

这是我的代码:

func startTest(){
    mCamera.addAudioInputsAndOutputs()//避免录制第一帧黑屏
    let name = Date().timeIntervalSince1970
    videoUrl = URL(fileURLWithPath: "\(NSTemporaryDirectory())folder_demo\(name).mp4")
    unlink(videoUrl?.path)
    var size = CGSize(width: 480, height: 640)
    movieWriter = GPUImageMovieWriter(movieURL:videoUrl, size:size )
    movieWriter?.assetWriter.movieFragmentInterval = kCMTimeInvalid
    movieWriter?.encodingLiveVideo = true
    movieWriter?.setHasAudioTrack(true, audioSettings: nil)
    ifFilter.addTarget(movieWriter)
    self.mCamera.audioEncodingTarget = self.movieWriter
    self.movieWriter?.startRecording()
    liveTimer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(updateTest), userInfo: nil, repeats: true)

}

   @objc func  updateTest(){
    weak var ws = self
    movieWriter?.finishRecording(completionHandler: {
        ws?.startTest()
        print(Date().timeIntervalSince1970)
    })

}
4

1 回答 1

0

我用以下方法解决了这个问题: 每次要完成记录时,都需要从写入中删除所有目标:

/// finish 
///
/// - Parameter finish: block
func liveFinishRecord(finish:@escaping ()->()){
    ifFilter.removeTarget(movieWriter)
    movieWriter?.finishRecording(completionHandler: {
        finish()
    })
}
于 2018-09-05T07:35:21.813 回答