iOS: How to fix half size frames saving movie with AVAssetWriter
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开发者_如何学C CVPixelBuffer settings).
What could be causing this kind of problem?
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!
精彩评论