我想将存储在AVPlayerItem中的.mp4-video导出到文件系统。 如果成功,我想把它变成一个NSData变量(但这不是问题的一部分,只是想告诉你为什么我想把它存储到文件系统中)。
//This is the AVPlayerItem-Object
let item = self.talentView.getCurrentItem()
//They return all true, so the item itself is not the issue
print(item.asset.isPlayable)
print(item.asset.isReadable)
print(item.asset.isExportable)
//Creating Path, where the file will be stored, also tried "video.mp4" at the appending string
var exportPath: NSString = NSTemporaryDirectory().appendingFormat("/video.mp4")
var exportUrl: NSURL = NSURL.fileURL(withPath: exportPath as String) as NSURL
let session = AVAssetExportSession(asset: item.asset, presetName: AVAssetExportPresetPassthrough)
session?.outputFileType = AVFileTypeMPEG4
session?.outputURL = exportUrl as URL
session?.exportAsynchronously(completionHandler: {
//case is always .failed
switch session!.status {
case .failed:
print("failed")
print(session!.error!)
default:
print("something else")
}
})
错误输出:
错误域= AVFoundationErrorDomain代码= -11838"操作已停止" UserInfo = {NSUnderlyingError = 0x170441230 {Error Domain = NSOSStatusErrorDomain Code = -12109"(null)"},NSLocalizedFailureReason =此媒体不支持该操作。,NSLocalizedDescription = Operation Stopped}
很奇怪,因为print(item.asset.isExportable)
返回true。
我已经研究了很多并尝试了各种类型的exportUrl,但导出总是失败。我不明白这个问题,也许有人有想法?