Thursday, August 02, 2012


Why YUV format is used in MPEG2/MPEG4/H264encoders for compression ?

  MPEG2/MPEG4/H264 is lossy compression.
RGGB will have image details/color information in all the RGB represented bytes.
if we are applying for lossy compression, there is a chance for losing bits information.
if LSB bits are affected there wont be a big change in image. If MSB bits of RGB is lost,
this will be bigger change in image and user can perceive/can observe the changes in image.

  In YUV format, image details will be available in Y data[ this will have monochrome/ black and white image]. U and V component is used to store color information.

  Eyes can't perceive color information changes than image information. But it can easily observe the changes in image information[Y data which will have black/white image]. So In lossy compression, encoders wont disturb the image information & will
disturb or compress more in color information [UV components]

     If we are using RGB, we cannot separate image information & color information.Because all the pixels will have the image information and color information.

This is the reason why we are using YUV format in lossy compression or MPEG2/MPEG4/H264 encoders.


   

Labels: , , , ,

Wednesday, February 06, 2008

YUV420P to YV12 format conversion

I converted the YUV420P to YV12 format using the following :


The YV12 format is essentially the same as YUV420p, but it has the U and V data reversed: the Y values are followed by the V values, with the U values last.Our output is YUV420P.

Our MPEG4 Decoder's output is YUV420P. So we need to convert it as
YV12. I used the following code to convert from YUV420P to YV12.

long ulNumberOfPixels = m_iWidth * m_iHeight;
long ulUVBufferSize = (m_iWidth * m_iHeight) /4;
unsigned char ch; for(long i = 0; i < ulUVBufferSize; i++)
{
ch = pbYUVData[ulNumberOfPixels + i] ;
pbYUVData[ulNumberOfPixels + i] = pbYUVData[ ulNumberOfPixels + ulUVBufferSize + i];
pbYUVData[ ulNumberOfPixels + ulUVBufferSize + i] = ch;
}

Labels: ,