Sunday, June 7, 2026
HomeiOS Developmentios - AVAssetExportSession is exporting audio with unhealthy time vary

ios – AVAssetExportSession is exporting audio with unhealthy time vary

[ad_1]

I am attempting to trim an audio file, utilizing the next snippet:

        let asset = AVURLAsset(url: sourceURL, choices: [AVURLAssetPreferPreciseDurationAndTimingKey: true])

        guard let exportSession = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetAppleM4A) else {
            throw AVUtilsError.assetExportSessionCreationFailure
        }

        let startCMTime = CMTime(seconds: startTime, preferredTimescale: CMTimeScale.max)
        let durationCMTime = CMTime(seconds: length, preferredTimescale: CMTimeScale.max)
        let timeRange = CMTimeRange(begin: startCMTime, length: durationCMTime)

        exportSession.timeRange = timeRange
        exportSession.outputURL = outputFileURL
        exportSession.outputFileType = .m4a

        exportSession.exportAsynchronously {
            completion(exportSession.error)
        }

It is working appropriately with virtually all information, however with a minority of information, (e.g. this one: https://site visitors.libsyn.com/safe/forcedn/theoakwynpodcast/The_Oakwyn_Podcast_ep102__V1.mp3) the instances are misaligned with the trimming begin/finish factors that I put visually in AVPlayer.

Am I lacking one thing or is that this a short-coming of AVFoundation?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments