swiftspatialavassetwriteravassetavassetreader

SDAVAssetExportSession or AVAssetWriter fail to process iphone16 video with spatial audio tracks


I have been using SDAVAssetExportSession to compress videos in an app I am building, everything goes very smoothly until I have my new Iphone16, on the device, the spatial audio in camera setting is turned on by default, then the SDAVAssetExportSession starts to fail. I know it has something to do with audioSetting. the current setting is something like this:

exportSession.audioSettings = [
    AVFormatIDKey: kAudioFormatMPEG4AAC,
    AVNumberOfChannelsKey: 2,
    AVSampleRateKey: 44100,
    AVEncoderBitRateKey: 128000
]

And also, this is passed to the underlying object AVAssetReader or AVAssetWriter. I am not experienced in this area, and I really had a hard time trying to figure out.

Does anyone know how to set up AVAssetReader or AVAssetWriter to process video with spatial audio tracks ? thanks in advance.


Solution

  • for anyone who is stumbled on this issue:

    it is happening because the video asset has more than 1 audio track, I guess the first is the plain old stereo track to be compatible with older players, while the rest is a spatial audio track that contains more channels.

    then things now become easier -- just process the first audio track, and neglect the rest.