简体   繁体   English

iOS:如何修复使用AVAssetWriter保存电影的半尺寸帧

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

I am writing a movie file with AVAssetWriter and AVAssetWriterInputPixelBufferAdaptor. 我正在用AVAssetWriter和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. 用于构建CVPixelBuffer的CGImage看起来很正常(如屏幕上显示),输出影片显示压缩到帧的上半部分的输入图像。 All of the widths, heights, and bytes_per_row are identical (for the CGImage, the AVAssetWriter settings, and the CVPixelBuffer settings). 所有宽度,高度和bytes_per_row都是相同的(对于CGImage,AVAssetWriter设置和CVPixelBuffer设置)。

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. 问题来自以下事实:当您向AVAssetWriterInputPixelBufferAdaptor提供设置以用于配置CVPixelBufferPool以生成CVPixelBuffers时,CVPixelBufferPool显然将设置用作请求而不是实际设置。 The CVPixelBuffer you get may have a different configuration. 您获得的CVPixelBuffer可能具有不同的配置。 This might be a bug in Apple's code, I'm not sure. 这可能是Apple代码中的一个错误,我不确定。

In any case you can read the actual bytes per row using CVPixelBufferGetBytesPerRow(CVPixelBuffer), and adjust your code accordingly. 在任何情况下,您都可以使用CVPixelBufferGetBytesPerRow(CVPixelBuffer)读取每行的实际字节数,并相应地调整您的代码。 Worked for me! 为我工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM