我使用libyuv将NV21图像格式转换为I420:
void convert(uint8* input, int width, int height) {
int size = width * height * 3/2;
uint8* output = new uint8[size];
uint8* src_y = input;
int src_stride_y = width;
uint8* src_vu = input + (width * height);
int src_stride_vu = width / 2;
uint8* dst_y = output;
int dst_stride_y = width;
uint8* dst_u = dst_y + (width * height);
int dst_stride_u = width / 2;
uint8* dst_v = dst_u + (width * height) / 4;
int dst_stride_v = width / 2;
libyuv::NV21ToI420(src_y, src_stride_y,
src_vu, src_stride_vu,
dst_y, dst_stride_y,
dst_u, dst_stride_u,
dst_v, dst_stride_v,
width, height);
dumpToFile(dst_y, size);
...
}我的输入大小是640x480。
我使用ImageMagick的显示器显示转储的文件:
$ display -size 640x480 -depth 8 -sampling-factor 4:2:0 -colorspace srgb MyI420_1.yuv但是,显示的图像中的颜色会变得混乱。图像的其他方面看起来都没问题。
我想知道我是否在代码中犯了一个错误。也许我的步幅计算是不正确的。
注意,如果我使用我的自定义函数来重新排列V1U1V2U2...作为U1U2...V1V2..。并转储输出,则显示正常。然而,我更喜欢使用libyuv,因为它对霓虹灯、SSE2等有一些优化。
发布于 2021-03-05 16:22:46
你的src_stride_vu需要和width一样,因为它是组合步幅到UV像素的交错。
https://stackoverflow.com/questions/29529320
复制相似问题