我已经使用screcorder
来捕获视频,而我正在使用SCAssetExportSession
来导出视频。出现以下错误后,我只能导出视频为第一次:
some:错误域= AVFoundationErrorDomain代码= -11800“操作无法完成” UserInfo = {NSLocalizedFailureReason =发生未知错误(-12138),NSLocalizedDescription =操作无法完成,NSUnderlyingError = 0x283903690 {Error Domain = NSOSStatusErrorDomain代码= -12138“(null)”}}
我已经检查了stackoverflow上的一些链接,但是这些链接都不适合我,我也尝试过关注
self.session.deinitialize()
self.exportSession = SCAssetExportSession()
我使用了以下代码:
func exportSessionVideo() {
self.Loader_show()
let videoName = randomString(length: 5) + ".mp4"
let exportedVideoURL = (applicationDocumentsDirectory()?.appendingPathComponent(videoName))!
exportSession = SCAssetExportSession()
exportSession = SCAssetExportSession(asset: session.assetRepresentingSegments())
exportSession.videoConfiguration.preset = SCPresetHighestQuality
exportSession.audioConfiguration.preset = SCPresetHighestQuality
exportSession.videoConfiguration.maxFrameRate = 35
exportSession.outputUrl = session.outputUrl
exportSession.outputFileType = AVFileType.mp4.rawValue
exportSession.delegate = self
exportSession.contextType = .auto
// let audioMix: AVMutableAudioMix = AVMutableAudioMix()
// var audioMixParam: [AVMutableAudioMixInputParameters] = []
//
// let aAudioAssetTrack: AVAssetTrack = session.assetRepresentingSegments().tracks.first!
// let videoParam: AVMutableAudioMixInputParameters = AVMutableAudioMixInputParameters(track: aAudioAssetTrack)
// videoParam.trackID = aAudioAssetTrack.trackID
//
// let videoVolume : Float = 1
//
// videoParam.setVolume(videoVolume, at: kCMTimeZero)
//
// videoParam.setVolumeRamp(fromStartVolume: videoVolume, toEndVolume: videoVolume, timeRange: aAudioAssetTrack.timeRange)
//
// audioMixParam.append(videoParam)
// audioMix.inputParameters = audioMixParam
// exportSession.audioConfiguration.audioMix = audioMix
exportSession.exportAsynchronously {
self.Loader_Hide()
let error = self.exportSession.error
if (self.exportSession.cancelled) {
showMessage("Export was cancelled")
} else if error == nil {
print("url: \(self.exportSession.outputUrl?.absoluteString ?? "nil url")")
let assetURL = self.exportSession.outputUrl
self.recorder.session = nil
self.recorder.previewView = nil
self.exportSession = SCAssetExportSession()
self.session.deinitialize()
self.recorder.session?.deinitialize()
self.dismiss(animated: true, completion: {
DispatchQueue.main.async(execute: {
let vc = loadVC(strStoryboardId: SB_CAMERA, strVCId: "CreatePostVC") as! CreatePostVC
vc.objEnum_PostType = .Video
vc.strPostURL = assetURL!.absoluteString
APP_DELEGATE.appNavigation?.present(vc, animated: true, completion: nil)
})
})
} else {
showMessage((error?.localizedDescription)!)
}
}
}