Many digital media formats have FOURCC codes assigned to them. A FOURCC code is a 32-bit unsigned integer that is created by concatenating four ASCII characters. For example, the FOURCC code for YUY2 video is 'YUY2'. For compressed video formats and non-RGB video formats (such as YUV), the biCompression member of the BITMAPINFOHEADER structure should be set to the FOURCC code.
There are various C/C++ macros that make it easier to declare FOURCC values in source code. For example, the MAKEFOURCC macro is declared in Mmsystem.h, and the FCC macro is declared in Aviriff.h. Use them as follows:
You can also declare a FOURCC code directly as a string literal simply by reversing the order of the characters. For example:
Reversing the order is necessary because the Microsoft Windows operating system uses a little-endian architecture. 'Y' = 0x59, 'U' = 0x55, and '2' = 0x32, so '2YUY' is 0x32595559.
A range of 2*32 GUIDs is reserved for representing FOURCCs. These GUIDs are all of the form
XXXXXXXX is the FOURCC code. Thus, the subtype GUID for YUY2 is
Many of these GUIDs are defined already in the header file Uuids.h. For example, the YUY2 subtype is defined as MEDIASUBTYPE_YUY2. The DirectShow base class library also provides a helper class, FOURCCMap, which can be used to convert FOURCC codes into GUID values. The FOURCCMap constructor takes a FOURCC code as an input parameter. You can then cast the FOURCCMap object to the corresponding GUID:
FOURCCMap fccMap(FCC('YUY2')); GUID g1 = (GUID)fccMap; // Equivalent: GUID g2 = (GUID)FOURCCMap(FCC('YUY2'));