I can't add more than 2 thousand and a few CMSAMPLEBUFFER in AVAssetWrite

Hello,

I am deaf-blind and I program with a braille display. Currently, I am experiencing a difficulty with one of my APPs.

Basically, I'm converting AVAudioPCMBuffer for CMSampleBuffer and so far so good. I want to add several CMSampleBuffer in a video written with AVAssetWrite .

The problem is that I can only add up to more or less 2 thousands CMSampleBuffer .

I'm trying to create a video. In this video, I put photos that are in an array and then I put audio from CMSampleBuffer.

But I can't add many CMSampleBuffer and only goes up to 2 thousand something.

I do not know what else to do.

Help me.

Below is a small excerpt of the code:

let queue = DispatchQueue(label: "AssetWriterQueue")
let audioProvider = SampleProvider(buffers: audioBuffers)
let videoProvider = SampleProvider(buffers: videoBuffers)

let audioInput = createAudioInput(audioBuffers: audioBuffers)
let videoInput = createVideoInput(videoBuffers: videoBuffers)
let adaptor = createPixelBufferAdaptor(videoInput: videoInput)

let assetWriter = try AVAssetWriter(outputURL: url, fileType: .mp4)
assetWriter.add(videoInput)
assetWriter.add(audioInput)
assetWriter.startWriting()
assetWriter.startSession(atSourceTime: .zero)

await withCheckedContinuation { continuation in
    videoInput.requestMediaDataWhenReady(on: queue) {
        let time = videoProvider.getPresentationTime()
        
        if let buffer = videoProvider.getNextBuffer() {
            adaptor.append(buffer, withPresentationTime: time)
        } else {
            videoInput.markAsFinished()
            continuation.resume()
        }
    }
}

await withCheckedContinuation { continuation in
    audioInput.requestMediaDataWhenReady(on: queue) {
        if let buffer = audioProvider.getNextBuffer() {
            audioInput.append(buffer)
        } else {
            audioInput.markAsFinished()
            continuation.resume()
        }
    }
}
I can't add more than 2 thousand and a few CMSAMPLEBUFFER in AVAssetWrite
 
 
Q