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

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.'


A screenshot of the error in 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)
    })

}

最佳答案

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

/// finish
///
/// - Parameter finish: block
func liveFinishRecord(finish:@escaping ()->()){
    ifFilter.removeTarget(movieWriter)
    movieWriter?.finishRecording(completionHandler: {
        finish()
    })
}

关于ios - GPUImage:继续录制影片崩溃“无法创建OpenGL ES 2.0上下文”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52179054/

10-13 04:29