Exporting Asset to Filesystem via AVAssetExportSession always fails - Swift 3
Asked Answered
T

0

12

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.

Trachytic answered 23/11, 2016 at 13:45 Comment(4)
I am facing the same issue. Did you get the solution for this? Please helpAudient
@shripad20: Any idea about the sameMojica
I found a solution or workaround, but it is already long time ago.I have to check the code first, and I will be on my Mac next week.Trachytic
@Trachytic you have solution?Nigrescent

© 2022 - 2024 — McMap. All rights reserved.