Search code examples
cffmpeg

AV_PIX_FMT_NV12 says it has a 12bpp bit pixel color but data is uint8_t how can I modify the pixels from a frame?


The documentaions says AV_PIX_FMT_NV12 planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (first byte U and the following byte V)

also linesize[1] and linesize[0] are 1920, but if I strlen(data[1]) ( UV components ) I get 1044587 this divided by the frame->heigth gives me 967,21... so the linesize is wrong?


Solution

  • It's 8 bits per channel, so uint8_t is correct, but it's 4:2:0 subsampled (U and V planes have both horizontal and vertical resolution halved).

    The "12 bits per pixel" comes from 8 bits Y + 2 bits U (8 bits for every 4 pixels) + 2 bits V (8 bits for every 4 pixels) = 12 bits per pixel on average. This is also why the UV plane is half as many bits as the Y plane; it's U+V data, but only for 1/4 of the pixels.