使用AVAssetExportSession导出专有视频文件-兼容性检查失败并导出

问题描述

我有一个使用专有格式但与H.264兼容的IP摄像机录制的视频文件。我可以使用一些在线工具将文件成功转换为.mov或.mp4,甚至无需指定源文件格式。

但是,当我尝试使用AVAssetExportSession进行转换时,它总是无法通过兼容性检查,并且还会错误导出。

以下是我正在使用的代码段:

let avAsset = AVURLAsset(url: inURL)
let preset = AVAssetExportPresetHighestQuality
let outputFileType = AVFileType.mov

AVAssetExportSession.determineCompatibility(ofExportPreset: preset,with: avAsset,outputFileType: AVFileType.mov) { isCompatible in
            
        if !isCompatible {
            print("File not compatible...")
        }

        let exportSession = AVAssetExportSession(asset: avAsset,presetName: AVExport)
            exportSession!.outputURL = outURL
            exportSession!.outputFileType = outputFileType

            exportSession!.exportAsynchronously(completionHandler: {() -> Void in
                switch exportSession!.status {
                case .Failed:
                    print("%@:",exportSession?.error as Any)
                case .cancelled:
                    print("Export canceled")
                case .completed:
                    print("Successful!")
                    print(exportSession!.outputURL as Any)
                default:
                    break
                }
            })
}

注意inURLoutURL都是使用URL(fileURLWithPath:“来自应用程序文档目录的URL路径+文件名”)生成的。

这是我经常收到的导出错误。.无论尝试哪种方式:

Optional(Error Domain=AVFoundationErrorDomain Code=-11800 "The operation Could not be completed" UserInfo={NSUnderlyingError=0x600001ca8d20 {Error Domain=NSOsstatusErrorDomain Code=-16979 "(null)"},NSLocalizedFailureReason=An unkNown error occurred (-16979),NSURL = MY_FILE_URL/record.mov,NSLocalizedDescription=The operation Could not be completed})

我查看了许多答案,但无法弄清楚是什么原因导致了问题,或者这不是有效的导出。

对此表示感谢。 TIA!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)