我有一些编辑视频的代码,然后创建一个AVAssetExportSession来保存编辑过的视频.我想将它保存到相机胶卷,但无法弄清楚NSURL是什么.
var session: AVAssetExportSession = AVAssetExportSession(asset: myasset,presetName: AVAssetExportPresetHighestQuality) session.outputURL = ??? session.exportAsynchronouslyWithCompletionHandler(nil)
有谁知道如何确定将视频保存到相机胶卷的正确NSURL?在此先感谢您的帮助.
解决方法
只需使用session.outputURL = ….就无法将视频直接保存到相机胶卷.您必须将视频保存到文件路径(临时或其他),然后将该视频的视频写入相机使用writeVideoAtPathToSavedPhotosAlbum :,滚动:
var exportPath: Nsstring = NstemporaryDirectory().stringByAppendingFormat("/video.mov") var exportUrl: NSURL = NSURL.fileURLWithPath(exportPath)! var exporter = AVAssetExportSession(asset: myasset,presetName: AVAssetExportPresetHighestQuality) exporter.outputURL = exportUrl exporter.exportAsynchronouslyWithCompletionHandler({ let library = ALAssetsLibrary() library.writeVideoAtPathToSavedPhotosAlbum(exportURL,completionBlock: { (assetURL:NSURL!,error:NSError?) -> Void in // ... }) })