yuv420p转nv21
时间: 2023-07-29 08:14:59 浏览: 94
java视频格式NV21/NV12/YV12/YUV420P的转换
您可以使用以下代码将YUV420P格式的图像转换为NV21格式的图像:
```cpp
void convertYUV420PToNV21(unsigned char* yuv420p, int width, int height, unsigned char* nv21) {
int imageSize = width * height;
unsigned char* yPlane = yuv420p;
unsigned char* uPlane = yuv420p + imageSize;
unsigned char* vPlane = yuv420p + imageSize * 5 / 4;
int yIndex = 0, uvIndex = 0;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
nv21[yIndex++] = yPlane[i * width + j];
if (i % 2 == 0 && j % 2 == 0) {
nv21[imageSize + uvIndex] = vPlane[uvIndex];
nv21[imageSize + uvIndex + 1] = uPlane[uvIndex];
uvIndex++;
}
}
}
}
```
其中,yuv420p是YUV420P格式的图像数据,width和height分别是图像的宽度和高度,nv21是转换后的NV21格式的图像数据。
阅读全文