最近一直在想办法解决直接显示YUV的问题,比如说Vc中显示YUV,看了DirectX9.0 10.0等文档,发现它不支持显示YUV,但是通过cpu将YUV转换成RGB32,速度很慢,而且cpu占用率高,但是有一种好的办法,就是采用intel的ipp或者FFMPEG库的swscale(swscale from the
FFMPEG library.),这种方法降低cpu占用率,提高性能。
Color space conversion
Most video decoders output video frames in one of the YUV420 pixel formats. It is a planar format with sub sampled chrominance values. For more on that subject, visit the
FOURCC web site. The filter in this code sample supports most common DirectShow pixel formats, both planar and packed:
- YV12 – 12 bits per pixel planar format with Y plane followed by V and U planes
- I420(IYUV) – same as YV12 but V and U are swapped
- NV12 – 12 bits per pixel planar format with Y plane and interleaved UV plane
- YUY2 – 16 bits per pixel packed YUYV array
- RGB555 – 16 bits per pixel with 1 bit unused and 5 bits for each RGB channel
- RGB565 – 16 bits per pixel with 5 bits Red, 6 bits Green, and 5 bits Blue
- RGB24 – 24 bits per pixel with 8 bits for each RGB channel
- RGB32 – 32 bits per pixel with 8 bits for Alpha and 8 bits for each RGB channel
All these formats, except the last one, needs conversion to be rendered by Direct2D since for now it does not support YUV images. Since this is an introduction level article, I am using simple C methods for this purpose – unfortunately, they are
slow and CPU intensive, so in real world applications, you should consider more appropriate APIs and tools like
IPP or swscale from the
FFMPEG library.