Cómo recortar un video rápido por un time determinado

Estoy trabajando en una tarea en la que tengo que recortar el video grabado desde un punto de inicio particular hasta un punto final determinado como fue ingresado o seleccionado por el usuario. ¿Cómo debería suponer que hago eso? Como utilicé UIVideoEditorController antes pero no UIVideoEditorController , quiero usar la vista pnetworkingeterminada y quiero recortar el video directamente.

 let FinalUrlTosave = NSURL(string: "\(newURL)") exportSession!.outputURL=FinalUrlTosave exportSession!.shouldOptimizeForNetworkUse = true // exportSession.outputFileType = AVFileTypeQuickTimeMovie exportSession!.outputFileType = AVFileTypeQuickTimeMovie; let start:CMTime let duration:CMTime var st = starttime.doubleValue var ed = endTime.doubleValue start = CMTimeMakeWithSeconds(st, 600) duration = CMTimeMakeWithSeconds(ed, 600) // let timeRangeForCurrentSlice = CMTimeRangeMake(start, duration) let range = CMTimeRangeMake(start, duration); exportSession!.timeRange = range exportSession!.exportAsynchronouslyWithCompletionHandler({ switch exportSession!.status{ case AVAssetExportSessionStatus.Failed: print("failed \(exportSession!.error)") case AVAssetExportSessionStatus.Cancelled: print("cancelled \(exportSession!.error)") default: print("complete....complete") // self.SaveVideoToPhotoLibrary(destinationURL1!) } }) 

Estoy tratando de lograr mi objective usando esto, pero sin éxito.

post de error: – failed Optional(Error Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on this server." UserInfo={NSErrorFailingURLStringKey=file:///var/mobile/Containers/Data/Application/E68D3BFD-6923-4EA6-9FB3-C020CE4AA9D4/Documents/moment/jGq_9AUFa47s2ZiiPP4x.mp4, NSErrorFailingURLKey=file:///var/mobile/Containers/Data/Application/E68D3BFD-6923-4EA6-9FB3-C020CE4AA9D4/Documents/moment/jGq_9AUFa47s2ZiiPP4x.mp4, NSLocalizedDescription=The requested URL was not found on this server., NSUnderlyingError=0x1553c220 {Error Domain=N

Error ocurrido la segunda vez: – failed Optional(Error Domain=NSURLErrorDomain Code=-3000 "Cannot create file" UserInfo={NSUnderlyingError=0x14e00000 {Error Domain=NSOSStatusErrorDomain Code=-12124 "(null)"}, NSLocalizedDescription=Cannot create file})

Encontré mi solución usando este método y funciona como un encanto …

 func cropVideo(sourceURL1: NSURL, statTime:Float, endTime:Float) { let manager = NSFileManager.defaultManager() guard let documentDirectory = try? manager.URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true) else {return} guard let mediaType = "mp4" as? String else {return} guard let url = sourceURL1 as? NSURL else {return} if mediaType == kUTTypeMovie as String || mediaType == "mp4" as String { let asset = AVAsset(URL: url) let length = Float(asset.duration.value) / Float(asset.duration.timescale) print("video length: \(length) seconds") let start = statTime let end = endTime var outputURL = documentDirectory.URLByAppendingPathComponent("output") do { try manager.createDirectoryAtURL(outputURL, withIntermediateDirectories: true, attributes: nil) let name = Moment.newName() outputURL = outputURL.URLByAppendingPathComponent("\(name).mp4") }catch let error { print(error) } //Remove existing file _ = try? manager.removeItemAtURL(outputURL) guard let exportSession = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetHighestQuality) else {return} exportSession.outputURL = outputURL exportSession.outputFileType = AVFileTypeMPEG4 let startTime = CMTime(seconds: Double(start ?? 0), prefernetworkingTimescale: 1000) let endTime = CMTime(seconds: Double(end ?? length), prefernetworkingTimescale: 1000) let timeRange = CMTimeRange(start: startTime, end: endTime) exportSession.timeRange = timeRange exportSession.exportAsynchronouslyWithCompletionHandler{ switch exportSession.status { case .Completed: print("exported at \(outputURL)") self.saveVideoTimeline(outputURL) case .Failed: print("failed \(exportSession.error)") case .Cancelled: print("cancelled \(exportSession.error)") default: break } } } }