Skip to content
Search

FourCC

lastmod 2023-01-26created 2015-08-113 edits

FourCC (Four Character Code) literally means "four-character code": a 4-byte string serves as a unique tag that identifies a data format. The FourCC concept was taken from OSType in the Macintosh system software. The concept was later also used to identify data formats in QuickTime and DirectShow.

Because data is identified by four English letters, it is easy for people to read and remember. Being made of 4 bytes, it still suits 32-bit systems. However, endianness can sometimes make it hard to read. For example, if the FourCC is 'abcd', a little-endian system represents it as "0x64636261".

FourCC is mainly used to identify the video codec of AVI files. Codecs usable in files with the AVI extension include Divx, Xvid, and H.264. Audio codecs in AVI or WAV files are identified with 2 bytes, usually written in hexadecimal (e.g. MP3 is 0x0055). Of course, it is also used to identify file formats other than video and audio codecs.

OpenCV FOURCC Examples

# -*- coding: utf-8 -*-

from typing import Final

import cv2

FOURCC_MP4V: Final[int] = cv2.VideoWriter_fourcc(*"mp4v")
FOURCC_DIVX: Final[int] = cv2.VideoWriter_fourcc(*"divx")  # DivX MPEG-4
FOURCC_XVID: Final[int] = cv2.VideoWriter_fourcc(*"xvid")  # XVID MPEG-4
FOURCC_FMP4: Final[int] = cv2.VideoWriter_fourcc(*"fmp4")  # FFMPEG MPEG4
FOURCC_WMV2: Final[int] = cv2.VideoWriter_fourcc(*"wmv2")  # Windows Media Video 8
FOURCC_MJPG: Final[int] = cv2.VideoWriter_fourcc(*"mjpg")  # Motion JPEG
FOURCC_YV12: Final[int] = cv2.VideoWriter_fourcc(*"yv12")  # YUV 4:2:0 Planar
FOURCC_X264: Final[int] = cv2.VideoWriter_fourcc(*"x264")  # H.264 / AVC
FOURCC_AVC1: Final[int] = cv2.VideoWriter_fourcc(*"avc1")  # Advanced Video

DEFAULT_VIDEO_WRITER_FOURCC: Final[int] = FOURCC_MP4V


if __name__ == "__main__":
    print(DEFAULT_VIDEO_WRITER_FOURCC)

See also

Favorite site

author Zer0 sitemap