Error Domain=NSOSStatusErrorDomain Code=-12780 \“(null)\”

When I try to export the asset with AVAssetExport I get the following error only on videos received through whatsapp probably.
I could not find a working solution. I’ve also tried implementing code to fix video duration, but I did not fix it.
Error is : Error Domain=NSOSStatusErrorDomain Code=-12780 \”(null)\”

Here code

  • Swift 3: How to add watermark on video ? AVVideoCompositionCoreAnimationTool iOS 10 issue
  • AVFoundation exporting orientation wrong
  • iOS 5: Error merging 3 videos with AVAssetExportSession
  • Create video with AVVideoCompositionCoreAnimationTool and AVAssetExportSession SLOW
  • How can I add a watermark in a captured video on iOS
  • Need to show the image of video in mpmovieplayercontroller swift
  • PHCachingImageManager().requestAVAsset(forVideo: asset.phAsset!, options: nil, resultHandler: { (AVAssetRecivied, audioMix, info) in
                    let AVAssetMy = AVAssetRecivied!.normalizingMediaDuration()
                    let exportSession : AVAssetExportSession?
                    if (AVAssetMy as? AVURLAsset) != nil {
                    exportSession = AVAssetExportSession(asset: (AVAssetMy as? AVURLAsset)!, presetName: AVAssetExportPresetMediumQuality)
                    else {
                    exportSession = AVAssetExportSession(asset: (AVAssetMy as? AVComposition)!, presetName: AVAssetExportPresetMediumQuality)
                    exportSession?.outputURL = URL(fileURLWithPath: NSTemporaryDirectory() + NSUUID().uuidString + ".m4v")
                    exportSession?.outputFileType = AVFileTypeQuickTimeMovie
                    exportSession?.audioMix = audioMix
                    exportSession?.shouldOptimizeForNetworkUse = true
                    exportSession?.exportAsynchronously { () -> Void in
                        if exportSession?.status == .completed {
                        self.getFileSize(url: exportSession!.outputURL!)
                        if self.myMediaArray == nil {
                            self.myMediaArray = [["Video" : AVAsset(url: exportSession!.outputURL!)]]
                            DispatchQueue.main.async {
                        } else {
                            self.myMediaArray?.append(["Video" : AVAsset(url: exportSession!.outputURL!)])
                            DispatchQueue.main.async {

    Here is the method for adjusting the duration of the video

    func normalizingMediaDuration() -> AVAsset? {
        let mixComposition : AVMutableComposition = AVMutableComposition()
        var mutableCompositionVideoTrack : [AVMutableCompositionTrack] = []
        var mutableCompositionAudioTrack : [AVMutableCompositionTrack] = []
        let totalVideoCompositionInstruction : AVMutableVideoCompositionInstruction = AVMutableVideoCompositionInstruction()
        guard let video = tracks(withMediaType: AVMediaTypeVideo).first else {
            return nil
        guard let audio = tracks(withMediaType: AVMediaTypeAudio).first else {
            return nil
        mutableCompositionVideoTrack.append(mixComposition.addMutableTrack(withMediaType: AVMediaTypeVideo, preferredTrackID: kCMPersistentTrackID_Invalid))
        mutableCompositionAudioTrack.append(mixComposition.addMutableTrack(withMediaType: AVMediaTypeAudio, preferredTrackID: kCMPersistentTrackID_Invalid))
        let duration = video.timeRange.duration.seconds > audio.timeRange.duration.seconds ? audio.timeRange.duration : video.timeRange.duration
            try mutableCompositionVideoTrack[0].insertTimeRange(CMTimeRangeMake(kCMTimeZero,duration), of: video, at: kCMTimeZero)
            try mutableCompositionAudioTrack[0].insertTimeRange(CMTimeRangeMake(kCMTimeZero, duration), of: audio, at: kCMTimeZero)
            return nil
        totalVideoCompositionInstruction.timeRange = CMTimeRangeMake(kCMTimeZero,duration)
        return mixComposition


    The file is:
    1) Exportable
    2) Presets and format are compatible
    3) I tried to move the file to the document’s before I export 4) I tried to change the file extension.

    2 Solutions Collect From Internet About “Error Domain=NSOSStatusErrorDomain Code=-12780 \“(null)\””

    It’s a bug.
    Bug report :
    Alternatives are welcome…

    I ran into the same problem, and got the same error code -12780.
    The only thing that fixed it for me was:
    sending to exportSession?.outputURL a NSURL variable and putting as URL
    I have no idea why it worked and I hope you’ll find it helpful as well.