Issue with writing YUV image frame in C/C++

后端 未结 2 1380
醉话见心
醉话见心 2021-02-06 17:31

I am trying to convert an RGB frame, which is taken from OpenGL glReadPixels(), to a YUV frame, and write the YUV frame to a file (.yuv). Later on I would like to write it to a

相关标签:
2条回答
  • 2021-02-06 18:09

    I compiled your code and surely there is a problem when computing upos and vpos values. For me this worked (RGB to YUV NV12):

    vpos = length + (windowWidth * (j/2)) + (i/2)*2;
    upos = vpos + 1;
    
    0 讨论(0)
  • 2021-02-06 18:14

    It looks to me like you have too many bytes per frame for 4:2:0 data. ACcording to the spec you linked to, the number of bytes for a 200x200 pixel 4:2:0 frame should be 200 * 200 * 3 / 2 = 60,000. But you have ~90,000 bytes. Looking at your code, I don't see where you are convert from 4:4:4 to 4:2:0. So you have 2 choices - either set the header to 4:4:4, or convert the YCbCr data to 4:2:0 before writing it out.

    0 讨论(0)
提交回复
热议问题