小编Mar*_*cel的帖子

通过AVAssetExportSession将资产导出到文件系统总是失败 - Swift 3

我想将存储在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: …
Run Code Online (Sandbox Code Playgroud)

avassetexportsession avasset swift avplayeritem swift3

9
推荐指数
0
解决办法
1043
查看次数