错误域=NSOSStatusErrorDomain 代码=-12780 \"(null)\"; [英] Error Domain=NSOSStatusErrorDomain Code=-12780 \"(null)\"

查看:97
本文介绍了错误域=NSOSStatusErrorDomain 代码=-12780 \"(null)\";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 AVAssetExport 导出资产时,我可能只在通过 whatsapp 接收的视频上收到以下错误.

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.

错误是:

错误域=NSOSStatusErrorDomain 代码=-12780 \"(null)\"

Error Domain=NSOSStatusErrorDomain Code=-12780 \"(null)\"

这里是代码

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 {
                            self.collectionViewImage.reloadData()
                        }
                    } else {
                        self.myMediaArray?.append(["Video" : AVAsset(url: exportSession!.outputURL!)])
                        DispatchQueue.main.async {
                            self.collectionViewImage.reloadData()
                        }
                    }}
                }
            })

这里是调整视频时长的方法

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

    do{
        try mutableCompositionVideoTrack[0].insertTimeRange(CMTimeRangeMake(kCMTimeZero,duration), of: video, at: kCMTimeZero)
        try mutableCompositionAudioTrack[0].insertTimeRange(CMTimeRangeMake(kCMTimeZero, duration), of: audio, at: kCMTimeZero)
    }catch{
        return nil
    }

    totalVideoCompositionInstruction.timeRange = CMTimeRangeMake(kCMTimeZero,duration)

    return mixComposition
}
}

文件是:

1) 可导出
2) 预设和格式兼容
3) 我试图在导出之前将文件移动到文档中 4) 我试图更改文件扩展名.

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.

推荐答案

我遇到了同样的问题,并得到了同样的错误代码 -12780.唯一为我修复它的是:向 exportSession?.outputURL 发送一个 NSURL 变量并作为 URL我不知道它为什么有效,我希望你也会发现它有帮助.

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.

这篇关于错误域=NSOSStatusErrorDomain 代码=-12780 \"(null)\";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆