这是我已经尝试过的答案
//我的代码
filter = GPUImageGrayscaleFilter()
movieFile.addTarget(filter)
let documentsURL1 = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as! NSURL
let pathToMovie = documentsURL1.URLByAppendingPathComponent("temp.mov") as NSURL
var fileManager: NSFileManager = NSFileManager.defaultManager()
var error: NSError
var movieURL1 = pathToMovie
var urlStr: String = "\(movieURL1)"
NSUserDefaults.standardUserDefaults().setObject(urlStr, forKey: "movieUrl")
let path = NSBundle.mainBundle().pathForResource("vedio", ofType:"m4v")
let newFileURL = NSURL.fileURLWithPath(path!)!
var anAsset = AVAsset.assetWithURL(newFileURL)as!AVAsset
var videoAssetTrack = anAsset.tracksWithMediaType(AVMediaTypeVideo)[0]as! AVAssetTrack
var videoAssetOrientation_: UIImageOrientation = .Up
var isVideoAssetPortrait_: Bool = false
var videoTransform: CGAffineTransform = videoAssetTrack.preferredTransform
if videoTransform.a == 0 && videoTransform.b == 1.0 && videoTransform.c == -1.0 && videoTransform.d == 0 {
videoAssetOrientation_ = .Right
isVideoAssetPortrait_ = true
}
if videoTransform.a == 0 && videoTransform.b == -1.0 && videoTransform.c == 1.0 && videoTransform.d == 0 {
videoAssetOrientation_ = .Left
isVideoAssetPortrait_ = true
}
if videoTransform.a == 1.0 && videoTransform.b == 0 && videoTransform.c == 0 && videoTransform.d == 1.0 {
videoAssetOrientation_ = .Up
}
if videoTransform.a == -1.0 && videoTransform.b == 0 && videoTransform.c == 0 && videoTransform.d == -1.0 {
videoAssetOrientation_ = .Down
}
var naturalSize: CGSize
// Video size
naturalSize = videoAssetTrack.naturalSize
movieWriter = GPUImageMovieWriter(movieURL: movieURL1, size: naturalSize)
//filter?.addTarget(self.view as! GPUImageView)
movieWriter.shouldPassthroughAudio = true
if anAsset.tracksWithMediaType(AVMediaTypeAudio).count > 0 {
movieFile.audioEncodingTarget = movieWriter
}
movieFile.audioEncodingTarget = nil
movieFile.enableSynchronizedEncodingUsingMovieWriter(movieWriter)
movieWriter.startRecording()
movieFile.startProcessing()
movieWriter.completionBlock = {() -> Void in
self.movieWriter.finishRecording()
// self.performSelector("back", onThread: NSThread.mainThread(), withObject: nil, waitUntilDone: true)
}
但我无法在“文档目录”中保存我的视频,也会出错
由于未捕获的异常而终止应用 'NSInternalInconsistencyException',原因:'*** - [AVAssetWriter startWriting]状态为3'
时无法调用方法