NextLevel / NextLevelSessionExporter

🔄 Export and transcode media in Swift
http://nextlevel.engineering
MIT License
262 stars 49 forks source link

Error 3 (cancelled) on attempt to export video from iPhone 16 with APAC audio codec #49

Open Igor-Poltavtsev opened 1 month ago

Igor-Poltavtsev commented 1 month ago

We have an issue on v.0.4.6 on exporting video created on iPhone 16 with APAC audio codec. Any suggestions?

belgiandubbel commented 1 month ago

I concur - have same issue on an iPhone 16 Pro with videos recorded on the iPhone 16 Pro device. The problem seems to be Record Sound = Spacial in Settings.app | Camera. The videos have 2 audio tracks, one of them the problematic APAC track. I have partially solved it for now by modifying NextLevelSessionExporter.setupAudioOutput() by filtering out the APAC track before submitting it to AVAssetReaderAudioMixOutput:

NextLevelSessionExporter.swift:418 - setupAudioOutput()

...
        var audioTracksToUse: [AVAssetTrack] = []
        // Remove APAC tracks
        for audioTrack in audioTracks {
            let mediaSubtypes = audioTrack.formatDescriptions.filter { CMFormatDescriptionGetMediaType($0 as! CMFormatDescription) == kCMMediaType_Audio }.map { CMFormatDescriptionGetMediaSubType($0 as! CMFormatDescription) }
            for mediaSubtype in mediaSubtypes where mediaSubtype != kAudioFormatAPAC {
                audioTracksToUse.append(audioTrack)
            }
        }
        self._audioOutput = AVAssetReaderAudioMixOutput(audioTracks: audioTracksToUse, audioSettings: nil)

...
Igor-Poltavtsev commented 1 month ago

Thanks, @belgiandubbel we applied similar solution and seems it works. We modify incoming assets - remove track with apac codec. After NextLevelSessionExporter will be updated we just remove our custom solution.