《2022年avi格式文档 .pdf》由会员分享,可在线阅读,更多相关《2022年avi格式文档 .pdf(13页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、AVI Files The Microsoft Audio/Video Interleaved (AVI) file format is a RIFF file specification used with applications that capture, edit, and playback audio/video sequences. In general, AVI files contain multiple streams of different types of data. Most AVI sequences will use both audio and video st
2、reams. A simple variation for an AVI sequence uses video data and does not require an audio stream. Specialized AVI sequences might include a control track or MIDI track as an additional data stream. The control track could control external devices such as an MCI videodisc player. The MIDI track cou
3、ld play background music for the sequence. While a specialized sequence requires a specialized control program to take advantage of all its capabilities, applications that can read and play AVI sequences can still read and play an AVI sequence in a specialized file. (These applications ignore the no
4、n-AVI data in the specialized file.) This chapter primarily describes AVI files containing only audio and video data. This chapter covers the following topics: ?The required chunks of an AVI file ?The optional chunks of an AVI file ?Developing routines to write AVI files For additional information a
5、bout RIFF files, see the Microsoft Windows Multimedia Programmers Guide and Microsoft Windows Multimedia Programmers Reference. For additional information about installable compressors and decompressors, see chapter 10, Video Compression and Decompression Drivers. AVI RIFF Form AVI files use the AVI
6、 RIFF form. The AVI RIFF form is identified by the four-character code AVI . All AVI files include two mandatory LIST chunks. These chunks define the format of the streams and stream data. AVI files might also include an index chunk. This optional chunk specifies the location of data chunks within t
7、he file. An AVI file with these components has the following form: RIFF (AVI LIST (hdrl . . . ) LIST (movi . . . ) idx1 ) The LIST chunks and the index chunk are subchunks of the RIFF AVI chunk. The AVI chunk identifies the file as an AVI RIFF file. The LIST hdrl chunk defines the format of the data
8、 and is the first required list chunk. The LIST movi chunk contains the data for the AVI sequence and is the second required list chunk. The idx1 chunk is the optional index chunk. AVI files must keep these three components in the proper sequence. The LIST hdrl and LIST movi chunks use subchunks for
9、 their data. The following example shows the AVI RIFF form expanded with the chunks needed to complete the LIST hdrl and LIST movi chunks: RIFF (AVI LIST (hdrl avih() LIST (strl strh() 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 13 页 - - - - - - - - - strf()
10、 strd(additional header data) . . . ) . . . ) LIST (movi SubChunk | LIST(rec SubChunk1 SubChunk2 . . . ) . . . . . . ) idx1 ) The following sections describe the chunks contained in the LIST hdrl and LIST movi chunks as well as the idx1 chunk. Data Structures for AVI Files Data structures used in th
11、e RIFF chunks are defined in the AVIFMT.H header file. The reference section at the end of this chapter describes the data structures that can be used for the main AVI header, stream header, AVIIndex, and palette change chunks. The Main AVI Header LIST The file begins with the main header. In the AV
12、I file, this header is identified with avih four-character code. The header contains general information about the file, such as the number of streams within the file and the width and height of the AVI sequence. The main header has the following data structure defined for it: typedef struct DWORD d
13、wMicroSecPerFrame; DWORD dwMaxBytesPerSec; DWORD dwReserved1; DWORD dwFlags; DWORD dwTotalFrames; DWORD dwInitialFrames; DWORD dwStreams; DWORD dwSuggestedBufferSize; DWORD dwWidth; DWORD dwHeight; DWORD dwScale; DWORD dwRate; DWORD dwStart; DWORD dwLength; MainAVIHeader; 名师资料总结 - - -精品资料欢迎下载 - - -
14、- - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 13 页 - - - - - - - - - The dwMicroSecPerFrame field specifies the period between video frames. This value indicates the overall timing for the file. The dwMaxBytesPerSec field specifies the approximate maximum data rate of the file. This val
15、ue indicates the number of bytes per second the system must handle to present an AVI sequence as specified by the other parameters contained in the main header and stream header chunks. The dwFlags field contains any flags for the file. The following flags are defined: AVIF_HASINDEX Indicates the AV
16、I file has an idx1 chunk. AVIF_MUSTUSEINDEX Indicates the index should be used to determine the order of presentation of the data. AVIF_ISINTERLEAVED Indicates the AVI file is interleaved. AVIF_WASCAPTUREFILE Indicates the AVI file is a specially allocated file used for capturing real-time video. AV
17、IF_COPYRIGHTED Indicates the AVI file contains copyrighted data. The AVIF_HASINDEX and AVIF_MUSTUSEINDEX flags applies to files with an index chunk. The AVI_HASINDEX flag indicates an index is present. The AVIF_MUSTUSEINDEX flag indicates the index should be used to determine the order of the presen
18、tation of the data. When this flag is set, it implies the physical ordering of the chunks in the file does not correspond to the presentation order. The AVIF_ISINTERLEAVED flag indicates the AVI file has been interleaved. The system can stream interleaved data from a CD-ROM more efficiently than non
19、-interleaved data. For more information on interleaved files, see Special Information for Interleaved Files. The AVIF_WASCAPTUREFILE flag indicates the AVI file is a specially allocated file used for capturing real-time video. Typically, capture files have been defragmented by user so video capture
20、data can be efficiently streamed into the file. If this flag is set, an application should warn the user before writing over the file with this flag. The AVIF_COPYRIGHTED flag indicates the AVI file contains copyrighted data. When this flag is set, applications should not let users duplicate the fil
21、e or the data in the file. The dwTotalFrames field of the main header specifies the total number of frames of data in file. The dwInitialFrames is used for interleaved files. If you are creating interleaved files, specify the number of frames in the file prior to the initial frame of the AVI sequenc
22、e in this field. The dwStreams field specifies the number of streams in the file. For example, a file with audio and video has 2 streams. The dwSuggestedBufferSize field specifies the suggested buffer size for reading the file. Generally, this size should be large enough to contain the largest chunk
23、 in the file. If set to zero, or if it is too small, the playback software will have to reallocate memory during playback which will reduce performance. For an interleaved file, the buffer size should be large enough to read an entire record and not just a chunk. The dwWidth and dwHeight fields spec
24、ify the width and height of the AVI file in pixels. The dwScale and dwRate fields are used to specify the general time scale that the file will use. In addition to this time scale, each stream can have its own time scale. The time scale in samples per second is determined by dividing dwRate by dwSca
25、le. The dwStart and dwLength fields specify the starting time of the AVI file and the length of the file. The units are defined by dwRate and dwScale. The dwStart field is usually set to zero. The Stream Header (strl) Chunks 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - -
26、 - 第 3 页,共 13 页 - - - - - - - - - The main header is followed by one or more strl chunks. (A strl chunk is required for each data stream.) These chunks contain information about the streams in the file. Each strl chunk must contain a stream header and stream format chunk. Stream header chunks are id
27、entified by the four-character code strh and stream format chunks are identified with the four-character code strf. In addition to the stream header and stream format chunks, the strl chunk might also contain a stream data chunk. Stream data chunks are identified with the four-character code strd. T
28、he stream header has the following data structure defined for it: typedef struct FOURCC fccType; FOURCC fccHandler; DWORD dwFlags; DWORD dwReserved1; DWORD dwInitialFrames; DWORD dwScale; DWORD dwRate; DWORD dwStart; DWORD dwLength; DWORD dwSuggestedBufferSize; DWORD dwQuality; DWORD dwSampleSize; A
29、VIStreamHeader; The stream header specifies the type of data the stream contains, such as audio or video, by means of a four-character code. The fccType field is set to vids if the stream it specifies contains video data. It is set to auds if it contains audio data. The fccHandler field contains a f
30、our-character code describing the installable compressor or decompressor used with the data. The dwFlags field contains any flags for the data stream. The AVISF_DISABLED flag indicates that the stream data should be rendered only when explicitly enabled by the user. The AVISF_VIDEO_PALCHANGES flag i
31、ndicates palette changes are embedded in the file. The dwInitialFrames is used for interleaved files. If you are creating interleaved files, specify the number of frames in the file prior to the initial frame of the AVI sequence in this field. The remaining fields describe the playback characteristi
32、cs of the stream. These factors include the playback rate (dwScale and dwRate ), the starting time of the sequence (dwStart ), the length of the sequence (dwLength ), the size of the playback buffer (dwSuggestedBuffer ), an indicator of the data quality (dwQuality ), and sample size (dwSampleSize ).
33、 See the reference section for more information on these fields. Some of the fields in the stream header structure are also present in the main header structure. The data in the main header structure applies to the whole file while the data in the stream header structure applies only to a stream. A
34、stream format (strf) chunk must follow a stream header (strh) chunk. The stream format chunk describes the format of the data in the stream. For video streams, the information in this chunk is a BITMAPINFO structure (including palette information if appropriate). For audio streams, the information i
35、n this chunk is a WAVEFORMATEX or PCMWAVEFORMAT structure. (The WAVEFORMATEX structure is an extended version of the WAVEFORMAT structure.) For more information on this structure, see the New Multimedia Data Types and Data Techniques Standards Update. The strl chunk might also contain a stream data
36、(strd) chunk. If used, this chunk follows the stream format chunk. The format and content of this chunk is defined by installable compression or decompression drivers. Typically, drivers use this information for configuration. Applications that read and write RIFF files do not need to decode this in
37、formation. They transfer this data to and from a driver as a memory block. An AVI player associates the stream headers in the LIST hdrl chunk with the stream data in the LIST movi chunk by using the order of the strl chunks. The first strl chunk appli名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - -
38、- - - - 名师精心整理 - - - - - - - 第 4 页,共 13 页 - - - - - - - - - es to stream 0, the second applies to stream 1, and so forth. For example, if the first strl chunk describes the wave audio data, the wave audio data is contained in stream 0. Similarly, if the second strl chunk describes video data, then t
39、he video data is contained in stream 1. The LIST movi Chunk Following the header information is a LIST movi chunk that contains chunks of the actual data in the streams; that is, the pictures and sounds themselves. The data chunks can reside directly in the LIST movi chunk or they might be grouped i
40、nto rec chunks. The rec grouping implies that the grouped chunks should be read from disk all at once. This is used only for files specifically interleaved to play from CD-ROM. Like any RIFF chunk, the data chunks contain a four-character code to identify the chunk type. The four-character code that
41、 identifies each chunk consists of the stream number and a two-character code that defines the type of information encapsulated in the chunk. For example, a waveform chunk is identified by a two-character code of wb. If a waveform chunk corresponded to the second LIST hdrl stream description, it wou
42、ld have a four-character code of 01wb. Since all the format information is in the header, the audio data contained in these data chunks does not contain any information about its format. An audio data chunk has the following format (the # in the format represents the stream identifier): WAVE Bytes #
43、wb BYTE abBytes; Video data can be compressed or uncompressed DIBs. An uncompressed DIB has BI_RGB specified for the biCompression field in its associated BITMAPINFO structure. A compressed DIB has a value other than BI_RGB specified in the biCompression field. For more information about compression
44、 formats, see the description of the BITMAPINFOHEADER data structure in the Microsoft Windows Programmers Reference and Chapter 5, DIB Format Extensions for Microsoft Windows. A data chunk for an uncompressed DIB contains RGB video data. These chunks are identified with a two-character code of db (d
45、b is an abbreviation for DIB bits). Data chunks for a compressed DIB are identified with a two-character code of dc (dc is an abbreviation for DIB compressed). Neither data chunk will contain any header information about the DIBs. The data chunk for an uncompressed DIB has the following form: DIB Bi
46、ts #db BYTE abBits; The data chunk for a compressed DIB has the following form: Compressed DIB #dc BYTE abBits; Video data chunks can also define new palette entries used to update the palette during an AVI sequence. These chunks are identified with a two-character code of pc (pc is an abbreviation
47、for palette change). The following data structure is defined palette information: typedef struct BYTE bFirstEntry; BYTE bNumEntries; WORD wFlags; PALETTEENTRY peNew; AVIPALCHANGE; The bFirstEntry field defines the first entry to change and the bNumEntries field specifies the number of entries to cha
48、nge. The peNew field contains the new color entries. If you include palette changes in a video stream, set the AVITF_VIDEO_PALCHANGES flag in the dwFlags field of the stream header. This flag indicates that this video stream contains palette changes and warns the playback software that it will need
49、to animate the palette. The idx1 Chunk AVI files can have an index chunk after the LIST movi chunk. The index chunk essentially名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 13 页 - - - - - - - - - contains a list of the data chunks and their location in the fil
50、e. This provides efficient random access to the data within the file, because an application can locate a particular sound sequence or video image in a large AVI file without having to scan it. Index chunks use the four-character code idx1. The following data structure is defined for index entries: