gpt4 book ai didi

ios - GPUImage 视频录制

转载 作者:可可西里 更新时间:2023-11-01 01:41:45 25 4
gpt4 key购买 nike

我一直在尝试创建使用 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() 方法时):

[AVAssetWriter startWriting] Cannot call method when status is 3

关于为什么会发生这种情况的任何线索?为什么 AVAssetWriter 的状态是.Failed?

请注意,所有变量都是我的类的属性。

最佳答案

同样的错误。似乎 movieURL 构建错误。将代码更改为时已修复

movieURL = NSURL.fileURLWithPath(NSHomeDirectory())
.URLByAppendingPathComponent("stream.mp4")!
unlink(movieURL.path!)

关于ios - GPUImage 视频录制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29106438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com