GPUImage2在录制的视频上没有图像

时间:2019-02-25 07:07:22

标签: swift gpuimage

GPUImage2在录制的视频上没有图像。 这是我的例子。如果能帮助我找到解决方案,我将不胜感激。

@IBAction func capture(_ sender: UIButton) {
    if (!isRecording) {
        do {
            self.isRecording = true
            let documentsDir = try FileManager.default.url(for:.documentDirectory, in:.userDomainMask, appropriateFor:nil, create:true)
            let fileURL = URL(string:"test.mp4", relativeTo:documentsDir)!
            do {
                try FileManager.default.removeItem(at:fileURL)
            } catch {
            }

            movieOutput = try MovieOutput(URL:fileURL, size:Size(width:480, height:640), liveVideo:true)
            camera.audioEncodingTarget = movieOutput
            movieOutput!.startRecording()
        } catch {
            fatalError("Couldn't initialize movie, error: \(error)")
        }
    } else {
        movieOutput?.finishRecording{
            self.isRecording = false
            self.camera.audioEncodingTarget = nil
            self.movieOutput = nil
        }
    }
}    

1 个答案:

答案 0 :(得分:1)

您忘记将目标添加到movieOutput。

  

camera.addTarget(movieOutput!)

    do {
        movieOutput = try MovieOutput(URL: currentVideoUrl, size: videoSize, liveVideo: true)
        camera.audioEncodingTarget = movieOutput
        camera.addTarget(movieOutput!)
        movieOutput!.startRecording()
    } catch {
        print(error.localizedDescription)
    }