2017-02-16 68 views
0

我無法將過濾後的視頻保存到使用GPUImage 2的磁盤。我已經成功添加了一個過濾器,現在我需要將該視頻保存到磁盤,這是我遇到問題的位置。有關於這方面與GPUImage 1個答案,但我不能讓他們與GPUImage 2保存過濾後的電影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

在我的實踐我已經使用這個類的視頻輸出到文件中。

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") 
} 

}