I want to export a .mp4-video stored in an AVPlayerItem to the filesystem. If that succeeds, I want to get it into a NSData-variable (but that is not part of the question, just wanted to tell you why I want to store it into the Filesystem in the first place).
//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")
}
})
The error output:
Error Domain=AVFoundationErrorDomain Code=-11838 "Operation Stopped" UserInfo={NSUnderlyingError=0x170441230 {Error Domain=NSOSStatusErrorDomain Code=-12109 "(null)"}, NSLocalizedFailureReason=The operation is not supported for this media., NSLocalizedDescription=Operation Stopped}
It's strange, because print(item.asset.isExportable)
returns true.
I already experimented with various types of the exportUrl, but the export always failed.