gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:09:34 25 4
gpt4 key购买 nike

当我尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com