Add 30 frames per secons in assetWriter

Hello,

I have converted UIImage to CVPixelBuffer. I am creating a video writing app. In some cases, the same CVPixelBuffer should last in the video for 2 seconds or more.

However, I need to add 30 CVPixelBuffers per second because the video, to work on social media, must be 30 frames per second.

The problem is that whenever I try to add frames to long videos, like 50-minute videos, it gives an error.

The error is something like "Operation cannot be completed".

Give me an example of a loop to add 30 CVPixelBuffers per second to a currently written video.

Example:

while true {
    if videoInput.isReadyForMoreMediaData {
        break
    }

    if videoInput.isReadyForMoreMediaData,
       let buffer = videoProvider.getNextFrame() {
        adaptor.append(buffer, withPresentationTime: CMTime(value: 1, timescale: 30))
    }
}

I await your response.

Add 30 frames per secons in assetWriter
 
 
Q