共享扩展中的AVAssetExportSession
我正在尝试在共享扩展和获取中选择的video上使用AVAssetExportSession
错误域= NSURLErrorDomain代码= -3000“无法创建文件”UserInfo = {NSLocalizedDescription =无法创建文件,NSUnderlyingError = 0x14811fdb0 {错误域= NSOSStatusErrorDomain代码= -12124“(null)”}}
但是我可以在同一个NSURL上手动创建文件而不会出错。 这是我正在使用的function
func reencodeVideo() { let videoAsset = AVURLAsset(URL: video.url) let videoTrack = videoAsset.tracksWithMediaType(AVMediaTypeVideo)[0] as AVAssetTrack print(videoTrack.estimatedDataRate) let exportSession = AVAssetExportSession(asset: videoAsset, presetName: AVAssetExportPreset1920x1080) guard let outputURL = uploadableFileURL else { return } let fileManager = NSFileManager.defaultManager() // let created = fileManager.createFileAtPath(outputURL.path!, contents: nil, attributes: nil) if let path = outputURL.path where fileManager.fileExistsAtPath(path) { print("file exists") } do { try fileManager.removeItemAtURL(outputURL) print("deleted") } catch { print(error) } exportSession?.outputURL = outputURL exportSession?.outputFileType = AVFileTypeQuickTimeMovie exportSession?.exportAsynchronouslyWithCompletionHandler{ print(exportSession?.status) } } private var uploadableFileURL: NSURL? { guard let tempFileName = video.url.lastPathComponent else { return nil } let fileManager = NSFileManager.defaultManager() guard let containerURL = fileManager.containerURLForSecurityApplicationGroupIdentifier(Constants.appGroupIdentifier) else { return nil } return containerURL.URLByAppendingPathComponent("videoFile.mov") }
我已在同一目录中成功创建了文件,但AVAssetExportSession在那里返回错误。 我有什么想法我做错了吗?
我尝试使用AVAssetReader
和AVAssetWriter
,并且AVAssetWriter
在尝试启动时返回相同的错误。 如果我正在使用Documents目录,则编码过程成功完成,仅在使用共享应用程序组容器时失败。
您的问题可能与使用文档文件夹和icloud同步有关。 请参阅https://forums.developer.apple.com/message/77495#77495
如果您执行以下操作:
guard let containerURL = fileManager.containerURLForSecurityApplicationGroupIdentifier(Constants.appGroupIdentifier) else { return nil } let libraryURL = containerURL.URLByAppendingPathComponent("Library", isDirectory: true) let cachesURL = libraryURL.URLByAppendingPathComponent("Caches", isDirectory: true) return cachesURL.URLByAppendingPathComponent("videoFile.mov")
我无法从您的代码中找出uploadableFileURL的来源,但以下内容适用于我:
if let video = videoAsset { let fm = NSFileManager.defaultManager().URLsForDirectory(.CachesDirectory, inDomains: .UserDomainMask) let url = fm[0].URLByAppendingPathComponent("\(NSDate())").URLByAppendingPathExtension("mp4") let exporter = AVAssetExportSession(asset: video, presetName: AVAssetExportPreset3840x2160) exporter?.outputURL = url exporter?.outputFileType = AVFileTypeMPEG4 exporter?.exportAsynchronouslyWithCompletionHandler() { _ in let data = NSData(contentsOfURL: url) } }
- Swift:尝试打印CLLocationSpeed时发生exception“意外地发现零,同时展开一个可选值”
- EXC_BAD_ACCESS在带参数的本地化字符串上崩溃
- Objective C可以在运行时(reflection)确定调用者对象引用吗?
- 如何在UITableView静态单元格中dynamic更改单元格高度
- Unwind Segue的自定义Segue类
- iOS8 Safari浏览器-webkit-overflow-scrolling:touch; 问题
- Swift CheatSheet —哈希
- iOS:根据UILabel的大小找到适合UILabel的正确字体大小
- 移动Safari – input插入符号不会随溢出滚动:触摸一起滚动