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

标签 swift xcode swift3 avasset avassetexportsession

当我尝试使用 AVAssetExport 导出 Assets 时,仅在通过 Whatsapp 接收的视频上可能会出现以下错误。

我找不到可行的解决方案。我还尝试过实现代码来修复视频时长,但我没有修复它。

错误是:

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()
                        }
                    }}
                }
            })

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

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) 我尝试更改文件扩展名。

最佳答案

这是一个错误。 错误报告:https://bugreport.apple.com/web/?problemID=34574848 欢迎其他选择...

关于swift - 错误域=NSOSStatusErrorDomain 代码=-12780\"(null)\",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46247868/

相关文章:

ios - 类型 'string' 不符合协议(protocol) NilLiteralConvertible

ios - 如何让 Visual Studio 显示 iOS Xcode .m 文件的格式化颜色

ios - Xcode 6 UITableView 使 View 变黑

iphone - 将路由器代码升级到 Alamofire 4.0 和 Swift 3

ios - 'init' 不可用 :use 'withMemoryRebound(to:capacity:_)' to temporarily view memory as another layout-compatible type

ios - 如何从 UIActivity Controller 中删除 "Add to iCloud Drive"?

ios - 以编程方式在 UITableViewCell 中制作 UIButton 时出现问题

ios - 为什么 NSUserDefaults 在我的应用和共享扩展之间不起作用?

ios - 多个 View Controller 上的相同 UIProgressView

ios - Cordova ,错误 : does not appear to be an xcode project (no xcode project file) when installing plugins