我正在使用GPUImageMovie过滤并在我的设备中保存电影,但我的应用程序崩溃了
dispatch_sync(videoProcessingQueue,block);
GPUImageOutput.m 文件。我调试时它在
处中断self.movieWriter = GPUImageMovieWriter(movieURL:movieURL,尺寸:CGSizeMake(videoAssetTrack.naturalSize.width,videoAssetTrack.naturalSize.height))
这是我的代码:
var paths: [AnyObject] = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let filePath = paths[0].stringByAppendingString("/image.mov")
let asset: AVURLAsset = AVURLAsset(URL: NSURL(fileURLWithPath: filePath))
let videoAssetTrack: AVAssetTrack = asset.tracksWithMediaType(AVMediaTypeVideo)[0]
//CGAffineTransform videoTransform = CGAffineTransformMakeRotation(self.ValueOrientation);
self.movieFile1 = GPUImageMovie(URL: NSURL(fileURLWithPath: filePath))
self.movieFile1.runBenchmark = true
// self.filterExport = self.filterobject
self.movieFile1.addTarget(self.pixellateFilter)
self.pixellateFilter.removeAllTargets()
let filteredFile: String = paths[0].stringByAppendingPathComponent("/MovieFiltered.m4v")
unlink((filteredFile as NSString).UTF8String)
let movieURL: NSURL = NSURL.fileURLWithPath(filteredFile)
do {
try NSFileManager.defaultManager().removeItemAtPath(filteredFile)
print("File removed")
}catch{
print("Not Removed")
}
self.movieWriter = GPUImageMovieWriter(movieURL: movieURL, size: CGSizeMake(videoAssetTrack.naturalSize.width, videoAssetTrack.naturalSize.height))
self.pixellateFilter.addTarget(self.movieWriter)
self.movieWriter.shouldPassthroughAudio = true
self.movieFile1.audioEncodingTarget = self.movieWriter
self.movieFile1.enableSynchronizedEncodingUsingMovieWriter(self.movieWriter)
self.movieWriter.startRecording()
self.movieFile1.startProcessing()
weak var weakSelf = self
self.movieWriter.completionBlock = {() -> Void in
print("Recording done")
weakSelf!.movieWriter.finishRecording()
}
除了这个以外,我习惯了许多代码,但是应用程序总是在同一点崩溃。请给我解决方案。我也使用了这个代码..同样的错误......
var paths: [AnyObject] = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let filePath = paths[0].stringByAppendingString("/image.mov")
movieFile = GPUImageMovie(URL: NSURL(fileURLWithPath: filePath))
pixellateFilter = GPUImagePixellateFilter()
movieFile.addTarget(pixellateFilter)
let pathToMovie : String = paths[0].stringByAppendingPathComponent("filtered.mov")
do {
try NSFileManager.defaultManager().removeItemAtPath(pathToMovie)
print("File removed")
}catch{
print("Not Removed")
}
unlink((pathToMovie as NSString).UTF8String)
let movieURL: NSURL = NSURL.fileURLWithPath(pathToMovie)
movieWriter = GPUImageMovieWriter(movieURL: movieURL, size: CGSizeMake(480.0, 640.0))
pixellateFilter.addTarget(movieWriter)
movieWriter.shouldPassthroughAudio = true
movieFile.audioEncodingTarget = movieWriter
movieFile.enableSynchronizedEncodingUsingMovieWriter(movieWriter)
movieWriter.startRecording()
movieFile.startProcessing()
self.movieWriter.completionBlock = {() -> Void in
print("Recording done")
self.pixellateFilter.removeTarget(self.movieWriter)
self.movieWriter.finishRecording()
}
答案 0 :(得分:0)
我做错很少我忘了写
movieFile.audioEncodingTarget = nil
因为我的视频不包含声音。烨..