Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to export video using SCAssetExportSession #433

Open
CearsKhush opened this issue May 22, 2019 · 0 comments
Open

Unable to export video using SCAssetExportSession #433

CearsKhush opened this issue May 22, 2019 · 0 comments

Comments

@CearsKhush
Copy link

CearsKhush commented May 22, 2019

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

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant