rFlex / SCRecorder

iOS camera engine with Vine-like tap to record, animatable filters, slow motion, segments editing
Apache License 2.0
3.06k stars 583 forks source link

Unable to export video using SCAssetExportSession #433

Open CearsKhush opened 5 years ago

CearsKhush commented 5 years ago

I have used screcorder for capturing the video and I am using SCAssetExportSession for exporting the video. I am able to export video only for the first time after that I am getting following error

some : Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12138), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x283903690 {Error Domain=NSOSStatusErrorDomain Code=-12138 "(null)"}}

I have checked some links over stackoverflow but none of that will works for me,I have tried following things also

        self.session.deinitialize()
        self.exportSession = SCAssetExportSession()

I had used following code :

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

}