第1年8月1日 ios yuv pixelbuffer

1.

Y通道(Luminance)与 UV通道(Chrominance)分开填充数据,而且需要注意后者是UV交错排列的。在填充数据時还需要考虑到数据对齐的问题,当视频帧的宽高并不是某个对齐基数的倍数時(比如16),内部具体如何分配内存是不确定的,保险的做法就是逐行数据填充。这里我放上填充Chrominance通道数据的例子:

size_t bytesPerRowChrominance = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 1);

long chrominanceWidth = CVPixelBufferGetWidthOfPlane(pixelBuffer, 1);
long chrominanceHeight = CVPixelBufferGetHeightOfPlane(pixelBuffer, 1);

// Chrominance
uint8_t *uvDestPlane = (uint8_t *) CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 1);
memset(uvDestPlane, 0x80, chrominanceHeight * bytesPerRowChrominance);

for (int row = 0; row < chrominanceHeight; ++row) {
    memcpy(uvDestPlane + row * bytesPerRowChrominance,
            uvDataPtr + row * _outVideoWidth,
            _outVideoWidth);
}

free(uvDataPtr);


https://www.cnblogs.com/psklf/p/7700834.html

+ (CVPixelBufferRef) copyDataFromBuffer:(const unsigned char*)buffer toYUVPixelBufferWithWidth:(size_t)w Height:(size_t)h

http://blog.sina.com.cn/s/blog_6ea16f840102vuhy.html
posted @ 2021-08-01 19:46  lianhuaren  阅读(102)  评论(0编辑  收藏  举报