AVI file format

zhaozj2021-02-16  67

AVI file format

Tips: AVI file format ---- excerpt from "DirectShow Practice Featured in" Author: Lu Qiming

AVI (Audio Video Interleaved Abbreviation) is an exact file format for Riff (Resource Interchange File Format) file format, mostly used in audio and video capture, editing, playback. Typically, an AVI file can contain multiple different types of media streams (typically have an audio stream and a video stream), but the AVI file containing a single audio stream or a single video stream is also legal. AVI can be the most basic and most common media file format on the Windows operating system.

First introduce the Riff file format. Riff files use four character code Fourcc (Four-Character Code) to characterize data type, such as 'Riff', 'Avi', 'List', etc. Note that the byte order used by the Windows operating system is Little-Endian, so a four-character code 'abcd' actually DWORD value should be 0x64636261. In addition, it is also legal in four-character code like 'avi'. The RIFF file first contains a file header structure as shown in Figure 3.31. Figure 3.31 The first four bytes of the RIFF file structure is a four-character code 'riff', indicating that this is a Riff file; followed by 4 bytes of this RIFF file; then a four-character The specific type of code description file (such as AVI, Wave, etc.); the end is actual data. Note that the calculation method of the file size value is: the actual data length 4 (the size of the file type field); that is, the value of the file size does not include the size of the 'Riff' domain and the "file size" domain itself. Among the actual data of the RIFF file, the form of list (LIST) and blocks is also used to organize. The list can be nested with sub-lists and blocks. Among them, the structure of the list is: 'list' is a four-character code, indicating that this is a list; ListSize takes up 4 bytes, records the size of the entire list; ListType is also a four-character code, Represents the specific type of this list; ListData is the actual list data. Note that the ListSize value is calculated: the actual list data length 4 (the size of the ListType field); that is, the ListSize value does not include the size of the 'List' domain and the ListSize domain itself. Take another structure: ckid cksize ckdata --ckid is a four-character code representing the block type; CKSIZE occupies 4 bytes, records the size of the entire block; CKDATA is the actual block data. Note that the CKSIZE value refers to the actual block data length without including the size of the CKID domain and the Cksize domain itself. (Note: In the following, a list will be represented in the form of List (ListType (ListData), indicating a block in the form of CKID (CKDATA), such as [optional element] in the brackets in brackets Options.) Next, introduce the AVI file format. The AVI file type is represented by a four-character code 'avi'. The structure of the entire AVI file is: a Riff header two lists (a media stream format, one for saving media stream data) an optional index block.

The expansion structure of the AVI file is approximately as follows: Riff ('avi' list ('HDRL' 'AviH' (main AVI Information Head Data) List ('Strl' 'Strh' (Flow Summer Information Data) 'Strf' (Flow Format Information data) ['strd' (optional additional header information)] ['strn' (name)] ...) List ('Movi' {Subchunk | List REC 'Subchunk1 Subchunk2 ...) ...} ...) [' IDX1 '(optional AVI Index Block Data)] First, Riff (' Avi '...) is characterized by the AVI file type. Then the first list of the AVI files - 'hdrl' list, used to describe the format information of each stream in the AVI file (each of the media data in the AVI file is called a stream). The 'HDRL' list nested a series of blocks and sub-lists - first is a 'avih' block for recording global information of the AVI file, such as the number of streams, the wide and higher video images, can use an AvimainHeader data structure Operation: typedef struct _avimainheader {fourcc fcc; // must be 'avih' DWORD CB; // This data structure size, does not include the initial 8 bytes (FCC and CB two domains) DWORD dwMICROSECPERFRAME; // video frame Interval (in milliseconds) DWORD dwMaxBytespersec; // This avi file maximum data rate DWord dwpaddinggranularity; // Data filled granular DWORD DWFLAGS; // Avi file global tag, such as whether it contains DWord dwtotAlframes, etc. of the index block; / / Total frame number DWORD dword dwireframes; // Specify the number of initial frames (Non-interaction format should be specified as 0) DWORD DWSTREAMS; / / This file is recommended to read the cache of this file. Size (can accommodate the largest block) DWORD DWWIDTH; // Video image width (in pixel) DWORD dwheight; // Video image high (in pixels) DWORD dwreserved [4]; // Reserved} avimainheader Then, it is one or more 'Strl' sub-lists. (How many flows are in the file, where there is a "Strl 'sub-list.

Each 'Strl' sub-list contains at least one 'strH' block and a 'STRF' block, and 'strd' block (some of the configuration information required to save the codec) and the 'strn' block (the name of the save stream) is Optional. The first is the 'strH' block for explaining the header information of this stream, you can use an AvistreamHeader data structure to operate: typedef struct _avistreamheader {fourcc fcc; // must be 'strH' dword CB; // This data structure size, Does not include the initial 8 bytes (FCC and CB two domains) Fourcc fcctype; // stream type: 'Auds' (audio stream), 'VIDS' (video stream), // 'mids' (MIDI stream) , 'Txts' (text flow) Fourcc fcchandler; // Specify the process of the stream, for the audio and video is the decoder DWORD DWFLAGS; // Tag: Is this stream output? Is the palette change? Word WPRIORITY; / / The priority (when there are multiple types of flows, the highest priority is the default flow) Word WLANGUAGE; DWORD dwinitialframes; / / Specify the initial frame number DWORD DWSCALE for the interactive format; // This stream use Time Scale DWORD DWRATE; DWORD DWSTART; / / Start Time DWORD DWLENGTH; / / The length of the stream (the definition of DWSCALE and DWRATE) DWORD dwsuggestedBuffersize; // Read this streaming data Recommended Cache size DWQQuality ; // stream data quality indicator (0 ~ 10,000) DWORD DWSAMPLESIZE; // Sample Size Struct {Short Int Left; Short Int Top; Short Int Int Right; Short Int Bottom;} rcframe; // Specify this stream (video stream) Or text flow) The display location // video main window in the video main window determines the DWWIDTH and DWHEIGHT in the AvimainHeader structure} AvistreamHeader; then the 'STRF' block, which is used to explain the specific format of the stream. If it is a video stream, use a BitmapInfo data structure; if it is a audio stream, use a WAVEFormatex data structure to describe it. When all streams in the AVI file use a 'strl' sub-list description (Note: The order of the 'Strl' sub-list is corresponding to the number of media streams, such as the first 'Strl' sub-list description The first stream (stream 0), the second 'Strl' sub-list description is the second stream (stream 1), in this type), the task of the 'HDRL' list is completed, followed by AVI The second list of files must be used - 'Movi' list, used to save real media stream data (video image frame data or audio sampling data, etc.).

转载请注明原文地址:https://www.9cbs.com/read-16671.html

New Post(0)