Swift 错误域=NSOSStatusErrorDomain代码=-12780\";(空)\";
当我尝试使用AVAssetExport导出资产时,我仅在通过whatsapp接收的视频上收到以下错误 我找不到有效的解决办法。我还尝试实现代码来修复视频持续时间,但我没有修复它 错误是: 错误域=NSOSStatusErrorDomain代码=-12780\“(空)\” 这里是代码Swift 错误域=NSOSStatusErrorDomain代码=-12780\";(空)\";,swift,xcode,swift3,avasset,avassetexportsession,Swift,Xcode,Swift3,Avasset,Avassetexportsession,当我尝试使用AVAssetExport导出资产时,我仅在通过whatsapp接收的视频上收到以下错误 我找不到有效的解决办法。我还尝试实现代码来修复视频持续时间,但我没有修复它 错误是: 错误域=NSOSStatusErrorDomain代码=-12780\“(空)\” 这里是代码 PHCachingImageManager().requestAVAsset(forVideo: asset.phAsset!, options: nil, resultHandler: { (AVAssetReci
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)我试图更改文件扩展名 这是一个错误。 错误报告: 欢迎选择…这是一个bug。 错误报告:
欢迎选择…我遇到了相同的问题,得到了相同的错误代码-12780。 唯一能帮我解决这个问题的是: 发送到exportSession?.outputURL一个NSURL变量并作为URL放入
我不知道它为什么会起作用,我希望你也会发现它很有用。我遇到了同样的问题,得到了同样的错误代码-12780。 唯一能帮我解决这个问题的是: 发送到exportSession?.outputURL一个NSURL变量并作为URL放入 我不知道它为什么会起作用,我希望你也会觉得它很有用。我只是花了一次tsi(事件),据报道我的方法有一个漏洞,不允许导出某些特定的视频。他们欢迎其他选择!我只是花了一个tsi(事件),我被报告在方法中有一个错误,不允许导出某些特定的视频。他们欢迎其他选择!