SDAVAssetExportSession icon indicating copy to clipboard operation
SDAVAssetExportSession copied to clipboard

SDAVAssetExportSession takes long to save lengthy audio M4a files

Open alirazamsp opened this issue 4 years ago • 1 comments

` let session: SDAVAssetExportSession = SDAVAssetExportSession(asset: composition) session.audioSettings = [AVFormatIDKey:kAudioFormatMPEG4AAC,AVNumberOfChannelsKey:2,AVSampleRateKey:44100,AVEncoderBitRateKey:128000]

    previouslySavedDuration = startAudioTime
    session.outputURL = url
    session.outputFileType = AVFileType.m4a.rawValue


    session.exportAsynchronously(completionHandler:{
        DispatchQueue.main.async(execute: {
            switch session.status{
            case  .failed:
                print("failed \(String(describing: session.error))")
                completion(false)
            case .cancelled:
                print("cancelled \(String(describing: session.error))")
                completion(false)
            case .completed:
                completion(true)
            default:
                print("complete")
            }
        })
    } )`

Above is the piece of code I am using to export audio file as M4a. It takes long time to save audios of 3 minutes or long. Exporting time increases as the audio duration increase. How can I reduce this time ?

alirazamsp avatar Feb 26 '21 20:02 alirazamsp

Just from skimming the source code, it’s using a dispatch_queue to do a bunch of work. If you adjust the source code to use a higher priority dispatch queue that might speed things up

noah-nuebling avatar Dec 28 '21 19:12 noah-nuebling