ArticleslgStudy

computer science

FourCC

FourCC is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand FourCC rather than just read about it. In short: A FourCC ("four-character code") is a sequence of four bytes (typically ASCII) used to uniquely identify data formats. It originated from the OSType or ResType metadata system used in classic Mac OS and was adopted for the Amiga/Electronic Arts Interchange File Format and derivatives.

Key takeaways

  • FourCC belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect FourCC to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of FourCC from memory before moving on to harder problems.

Reference excerpt

A FourCC ("four-character code") is a sequence of four bytes (typically ASCII) used to uniquely identify data formats. It originated from the OSType or ResType metadata system used in classic Mac OS and was adopted for the Amiga/Electronic Arts Interchange File Format and derivatives. The idea was later reused to identify compressed data types in QuickTime and DirectShow.

History In 1984, the earliest version of a Macintosh OS, System 1, was released. It used the single-level Macintosh File System with metadata fields including file types, creator (application) information, and forks to store additional 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. In 1985, Electronic Arts introduced the Interchange File Format (IFF) meta-format (family of file formats), originally devised for use on the Amiga. 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. This IFF was adopted by a number of developers including Apple for AIFF files and Microsoft for RIFF files (which were used as the basis for the AVI and WAV file formats). Apple referred to many of these codes as OSTypes. Microsoft and Windows developers refer to their four-byte identifiers as FourCCs or Four-Character Codes. FourCC codes were also adopted by Microsoft to identify data formats used in DirectX, specifically within DirectShow and DirectX Graphics.

In Apple systems Since Mac OS X Panther, OSType signatures are one of several sources that may be examined to determine a Uniform 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 misplaces metadata 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 tools GetFileInfo and SetFile which are installed as part of the developer tools into /Developer/Tools, or the ResEdit utility available for older Macs.

Technical details The byte sequence is usually restricted to ASCII printable characters, with space characters reserved for padding shorter sequences. Case sensitivity is preserved, unlike in file extensions. FourCCs are sometimes encoded in hexadecimal (e.g., "0x31637661" for 'avc1') 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, 10bit Y'CbCr 4:2:2 video can have a FourCC of ('Y', '3', 10, 10) which ffmpeg displays as rawvideo (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 in 32-bit systems (although endian 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.

Compiler support 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 a multi-character literal behavior of right-aligning to the least significant byte, so that '1234' becomes 0x31323334 in ASCII. 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 value 0x61766331, a little-endian machine would have reversed the byte order and stored the value as 31 63 76 61. To yield the correct byte sequence 61 76 63 31, the pre-swapped value 0x31637661 is used.

Common uses

One of the most well-known uses of FourCCs is to identify the video codec or video coding format in AVI files. Common identifiers include DIVX, XVID, and H264. For audio coding formats, AVI and WAV files use a two-byte identifier, usually written in hexadecimal (such as 0055 for MP3). 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 the Standard MIDI File (SMF) format, the PNG image file format, the 3DS (3D Studio Max) mesh file format and the ICC profile format. Four-character codes are also used in applications other than file formats, for example:

UEFI Forum for vendor in the ACPI ID Registry ACPI specification defines four-character identifiers in ACPI Source Language (ASL) Synopsys to tell component ID via registers of an IP (DesignWare collection) Other uses for OSTypes include:

as record field IDs and event type and class IDs in AppleEvents for identifying components in the Component Manager as “atom” IDs in the QuickTime movie and image file formats as a localization-independent way of identifying standard folders in the Folder Manager in QuickDraw GX, they were used as gxTag types and also as types of collection items in the Collection Manager. Enumeration constants in Apple APIs (as an integer; host endianess) "OSStatus" error codes in certain libraries, such as QuickTime (as an integer; host endianess) For creator and resource type in PalmOS, under the data manager.

See also Filename extension (also known as "file extension") Interchange File Format Magic number OSType (now merged into this page, though the subpages remain independent) creator code type code

References

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with FourCC

Start with the simplest possible case. Write down what FourCC claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to FourCC before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about FourCC ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of FourCC

In research
FourCC appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses FourCC in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
FourCC is common in secondary-school and first-year university syllabi. It links to neighbouring topics Apple Inc. file systems, Apple Inc. software, Computer file formats, so understanding it makes those chapters shorter.
In everyday life
Look for FourCC outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “FourCC” →

How to study FourCC in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what FourCC means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain FourCC out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is FourCC in simple terms?

A FourCC ("four-character code") is a sequence of four bytes (typically ASCII) used to uniquely identify data formats. It originated from the OSType or ResType metadata system used in classic Mac OS and was adopted for the Amiga/Electronic Arts Interchange File Format and derivatives.

Why does FourCC matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study FourCC?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on FourCC.

Tags

  • Apple Inc. file systems
  • Apple Inc. software
  • Computer file formats
  • Macintosh operating systems
  • Metadata

Keep exploring