AFourCC ("four-character code") is a sequence of fourbytes (typicallyASCII) used to uniquely identifydata formats. It originated from theOSType orResType metadata system used inclassic Mac OS and was adopted for theAmiga/Electronic ArtsInterchange File Format and derivatives. The idea was later reused to identify compressed data types inQuickTime andDirectShow.
In 1984, the earliest version of a Macintosh OS,System 1, was released. It used the single-levelMacintosh File System with metadata fields includingfile types,creator (application) information, and forks to storeadditional resources. It was possible to change this information without changing the data itself, so that they could be interpreted differently. Identical codes were used throughout the system, as type tags for all kinds of data.[1][2]
In 1985,Electronic Arts introduced theInterchange File Format (IFF) meta-format (family of file formats), originally devised for use on theAmiga. These files consisted of a sequence of "chunks", which could contain arbitrary data, each chunk prefixed by a four-byte ID. The IFF specification explicitly mentions that the origins of the FourCC idea lie with Apple.[3]
This IFF was adopted by a number of developers includingApple forAIFF files andMicrosoft forRIFF files (which were used as the basis for theAVI andWAV file formats). Apple referred to many of these codes asOSTypes. Microsoft andWindows developers refer to their four-byte identifiers asFourCCs orFour-Character Codes. FourCC codes were also adopted by Microsoft to identify data formats used inDirectX, specifically within DirectShow and DirectX Graphics.
SinceMac OS X Panther, OSType signatures are one of several sources that may be examined to determine aUniform Type Identifier and are no longer used as the primary data type signature. Mac OS X (macOS) prefers the more colloquial convention of labelling file types using file name extensions. At the time of the change, the change was a source of great contention among older users, who believed that Apple was reverting to a more primitive way that misplacesmetadata in the filename.
Filesystem-associated type codes are not readily accessible for users to manipulate, although they can be viewed and changed with certain software, most notably the macOS command line toolsGetFileInfo andSetFile which are installed as part of the developer tools into/Developer/Tools, or theResEdit utility available for older Macs.[4][5]
The byte sequence is usually restricted toASCII printable characters, with space characters reserved for padding shorter sequences. Case sensitivity is preserved, unlike infile extensions. FourCCs are sometimes encoded in hexadecimal (e.g., "0x31637661" for 'avc1')[6][7][8] and sometimes encoded in a human-readable way (e.g., "mp4a"). Some FourCCs however,do contain non-printable characters, and are not human-readable without special formatting for display; for example, 10bitY'CbCr4:2:2 video can have a FourCC of ('Y', '3', 10, 10)[9] whichffmpeg displays asrawvideo (Y3[10] [10] / 0x0A0A3359), yuv422p10le.
Four-byte identifiers are useful because they can be made up of four human-readable characters with mnemonic qualities, while still fitting in the four-byte memory space typically allocated for integers in32-bit systems (althoughendian issues may make them less readable). Thus, the codes can be used efficiently in program code as integers, as well as giving cues in binary data streams when inspected.
FourCC is written in big endian relative to the underlying ASCII character sequence, so that it appears in the correct byte order when read as a string. Many C compilers, including GCC, define amulti-character literal behavior of right-aligning to the least significant byte, so that'1234' becomes0x31323334 in ASCII.[10] This is the conventional way of writing FourCC codes used by Mac OS programmers for OSType. (Classic Mac OS was exclusively big-endian.)
On little-endian machines, a byte-swap on the value is required to make the result correct. Taking the avc1 example from above: although the literal'avc1' already converts to the integer value0x61766331, a little-endian machine would have reversed the byte order and stored the value as31 63 76 61. To yield the correct byte sequence61 76 63 31, the pre-swapped value0x31637661 is used.
This sectionneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources in this section. Unsourced material may be challenged and removed. Find sources: "FourCC" – news ·newspapers ·books ·scholar ·JSTOR(February 2024) (Learn how and when to remove this message) |
One of the most well-known uses of FourCCs is to identify thevideo codec orvideo coding format in AVI files. Common identifiers includeDIVX,XVID, andH264. Foraudio coding formats, AVI and WAV files use a two-byte identifier, usually written inhexadecimal (such as0055 forMP3). In QuickTime files, these two-byte identifiers are prefixed with the letters "ms" to form a four-character code.RealMedia files also use four-character codes, however, the actual codes used differ from those found in AVI or QuickTime files.
Other file formats that make important use of the four-byte ID concept are theStandard MIDI File (SMF) format, thePNG image file format, the3DS (3D Studio Max) mesh file format and theICC profile format.
Four-character codes are also used in applications other than file formats, for example:
Other uses for OSTypes include:
This function GETFOURCC gives a list of available Video encoder-codecs in the current Windows installation