使用libyuv解码YUYV(YUV2)遇到的坑

最近在做摄像头相关项目,在使用libyuv提供的函数YUY2ToARGB对接收到的YUV帧转换成ARGB,然后通过Native Surface渲染显示。结果渲染完成之后画面重叠,折腾了大半天。函数调用如下:

YUY2ToARGB(videobuffers[bufffer.index].start,captureData->CaptureWidth,argb,captureData->CaptureWidth * 4,
        captureData->CaptureWidth,captureData->CaptrueHeight);

转换完成完成之后,渲染到Native Surface:

uint32_t *line = (uint32_t *) windowBuffer.bits;
for (int y = 0; y < windowBuffer.height; y++) {
    for (int x = 0; x < windowBuffer.width; x++) {
        int index = y * windowBuffer.width + x;
        line[x] = argb[index * 4] << 16 /*B*/
                  | argb[index * 4 + 1] <<8/*G*/
                  | argb[index * 4 + 2]  /*R*/
                  | argb[index * 4 + 3] << 24/*A*/;
    }
    line = line + windowBuffer.stride;
}

结果画面成下面这个鬼样子:

折腾了大半天还是有点懵,后面看了函数调用参数搞明白了。

int YUY2ToARGB(const uint8_t* src_yuy2,
               int src_stride_yuy2,
               uint8_t* dst_argb,
               int dst_stride_argb,
               int width,
               int height);

src_stride_yuy2这个参数是帧width的两倍,表示的是yuv的跨距。

然后重新修改调用:

YUY2ToARGB(videobuffers[bufffer.index].start,captureData->CaptureWidth * 2,argb,captureData->CaptureWidth * 4, captureData->CaptureWidth,captureData->CaptrueHeight);

显示正常:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老吕丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值