我在使用GPUImage 2将过滤后的视频保存到磁盘时遇到问题。我已经成功添加了一个过滤器,现在我需要将该视频保存到磁盘,这是我遇到问题的地方。关于这个主题有更多的答案与GPUImage 1,但我不能让他们使用GPUImage 2
过滤:
let bundleURL = Bundle.main.resourceURL!
let movieURL = URL(string: "test.mov", relativeTo: bundleURL)
do {
movie = try MovieInput(url: movieURL!, playAtActualSpeed: true)
filter = HueAdjustment()
filter.hue = hue
movie --> filter --> renderView
movie.runBenchmark = true
movie.start()
} catch {
print("Couldn't process movie error: \(error)")
}
尝试根据sampleLiveRecording保存它,这似乎不适合过滤的电影。
{
do {
let documentsDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let fileURL = URL(string: "testRender.mov", relativeTo: documentsDir)!
do {
try FileManager.default.removeItem(at: fileURL)
} catch {}
movieOutput = try MovieOutput(URL: fileURL, size: Size(width: 448, height: 426), liveVideo: false)
filter --> movieOutput!
movieOutput!.startRecording()
} catch {
fatalError("Couldn't Initialize Movie: \(error)")
}
}
更新:我没有找到答案,但我恢复使用GPUImage 1。
答案 0 :(得分:0)
在我的练习中,我已将此课程用于输出视频文件。
private class FileOutput {
enum State: Int {
case created
case recording
case finishing
}
var state: State = .created
let writingQueue = DispatchQueue(label: "FileOutputQueue", attributes: [])
var fileURI: URL
var duration: Double {
return fileOutput.recordDuration
}
var didFinishWriting: ( () -> () )? = nil
fileprivate let fileOutput: MovieOutput
init( camera: Camera, fileURI: URL ) throws {
do {
self.fileURI = fileURI
fileOutput = try MovieOutput(URL: fileURI,
size: Size(width: 1080, height: 1920),
liveVideo: true)
let movieOutputFilter = BasicOperation()
movieOutputFilter.overriddenOutputRotation = .rotate180
camera --> movieOutputFilter --> fileOutput
} catch {
throw NSError(domain: "com.test.camera", code: 1200000, userInfo: nil)
}
}
func start() {
if state == .created {
state = .recording
let _ = writingQueue.sync {
self.fileOutput.startRecording()
}
}
}
func finish() {
if state == .recording {
state = .finishing
let _ = writingQueue.sync {
self.fileOutput.finishRecording {
[weak self] in
self?.didFinishWriting?()
self?.didFinishWriting = nil
}
}
}
}
deinit {
didFinishWriting = nil
print("FileOutput deinited")
}
}