我一直在尝试创建使用GPUImage库来记录摄像机中的视频,过滤并保存到相机卷中。
GPUImageMovieWriter给我带来了一些问题。这是我的代码:
//Set up the GPUImageVideoCamera
videoCamera = GPUImageVideoCamera(sessionPreset: AVCaptureSessionPreset640x480, cameraPosition: .Back)
videoCamera.outputImageOrientation = .Portrait;
videoCamera.horizontallyMirrorFrontFacingCamera = true
videoCamera.horizontallyMirrorRearFacingCamera = false
//Create filter with view
filter = GPUImageFilter()
filterView = GPUImageView(frame: self.view.frame)
filterView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill;
self.view.addSubview(filterView)
pathToMovie = NSHomeDirectory().stringByAppendingPathComponent("stream.mp4")
unlink((pathToMovie as NSString).UTF8String)
var movieURL = NSURL.fileURLWithPath(pathToMovie)
movieWriter = GPUImageMovieWriter(movieURL: movieURL, size: CGSizeMake(640, 480))
movieWriter.encodingLiveVideo = true
//Attach targets
videoCamera.addTarget(filter)
filter.addTarget(filterView)
filter.addTarget(movieWriter)
//Start capture
videoCamera.startCameraCapture()
movieWriter.startRecording()该应用程序使用以下调试器输出崩溃(当调用startRecording()方法时):
当状态为3时,AVAssetWriter startWriting无法调用方法
有什么线索知道为什么会发生这种事吗?为什么AVAssetWriter的状态是.Failed?
注意,所有变量都是我类的属性。
发布于 2017-03-10 11:53:06
也有同样的错误。movieURL的构建似乎是错误的。修正了当代码更改为
movieURL = NSURL.fileURLWithPath(NSHomeDirectory())
.URLByAppendingPathComponent("stream.mp4")!
unlink(movieURL.path!)https://stackoverflow.com/questions/29106438
复制相似问题