iOS: How to fix half size frames saving movie with AVAssetWriter

684 Views Asked by At

I am writing a movie file with AVAssetWriter and AVAssetWriterInputPixelBufferAdaptor.

The CGImage that is used to build the CVPixelBuffer looks normal (as displayed on the screen), the output movie shows the input image compressed into the top half of the frame. All of the widths, heights, and bytes_per_row are identical (for the CGImage, the AVAssetWriter settings, and the CVPixelBuffer settings).

What could be causing this kind of problem?

1

There are 1 best solutions below

0
On BEST ANSWER

The problem comes from the fact that when you supply settings to AVAssetWriterInputPixelBufferAdaptor for use in configuring the CVPixelBufferPool to generate CVPixelBuffers, the CVPixelBufferPool apparently uses the settings as a request rather than as the actual setting. The CVPixelBuffer you get may have a different configuration. This might be a bug in Apple's code, I'm not sure.

In any case you can read the actual bytes per row using CVPixelBufferGetBytesPerRow(CVPixelBuffer), and adjust your code accordingly. Worked for me!