Sunday, March 1, 2009

AVI File format - AVI Indexes

The Stream header list - general

There is one strl - List for each stream. If the number of strl - Lists inside the hdrl - Listis different from MainAVIHeader::dwStreams, a fatal error should be reported.

The stream header list element: strh

typedef struct
{
FOURCC fccType;
FOURCC fccHandler;
DWORD dwFlags;
WORD wPriority;
WORD wLanguage;
DWORD dwInitialFrames;
DWORD dwScale;
DWORD dwRate; /* dwRate / dwScale == samples/second */
DWORD dwStart;
DWORD dwLength; /* In units above... */
DWORD dwSuggestedBufferSize;
DWORD dwQuality;
DWORD dwSampleSize;
RECT rcFrame;
} AVIStreamHeader;

Again, the meaning is not always obvious.

• fccType
Can be
- 'vids' - video
- 'auds' - audio
- 'txts' - subtitle

• fccHandler
FourCC of codec to be used.

• dwFlags
The following flags are defined
-AVISF_DISABLED - Stream should not be activated by default
-AVISF_VIDEO_PALCHANGES - Stream is a video stream using palettes where the palette is changing during playback.

• dwInitialFrames
Number of the first block of the stream that is present in the file.

• dwRate / dwScale =
samples / second (audio) or
frames / second (video).
dwScale and dwRate should be mutually prime. Tests have shown that for example 10,000,000 /400,000 instead of 25/1 results in files that don't work on some hardware MPEG4 players.

• dwStart
Start time of stream. In the case of VBR audio, this value indicates the number of silent frames to be played before the stream starts.

• dwLength
size of stream in units as defined in dwRate and dwScale

• dwSuggestedBufferSize
Size of buffer necessary to store blocks of that stream. Can be 0 (in that case the application has to guess), but should not be 0, as Microsoft's AVI splitter does not handle this case properly in some cases (e.g. MP3-CBR in Open-DML files)

• dwQuality
should indicate the quality of the stream. Not important

• dwSample
Size number of bytes of one stream atom (that should not be split any further).

The stream header list element: strf

The structure of the strf chunk depends on the media type. Video streams use the BITMAPINFOHEADER structure, whereas audio streams use the WAVEFORMATEX structure.

The stream header list element: indx

This chunk contains the upper level index for the stream.

The stream header list element: strn

This element contains a name for the stream. That stream name should only use plain ASCII, especially not UTF-8.

AVI Indexes

old style index

The index as described is the index you will find in AVI 1.0 files. It is placed after the movi List in the RIFF AVI List. The data section of the idx1 chunk has the following layout:

AVIINDEXENTRY index_entry[n]

typedef struct
{
DWORD ckid;
DWORD dwFlags;
DWORD dwChunkOffset;
DWORD dwChunkLength;
} AVIINDEXENTRY;

Those values have the following meaning:

• ckid
Specifies a four-character code corresponding to the chunk ID of a data chunk in the file.

• dwFlags
The following flags are defined:

- AVIIF_KEYFRAME: The chunk the entry refers to is a keyframe.
- AVIIF_LIST: The entry points to a list, not to a chunk.
- AVIIF_FIRSTPART: Indicates this chunk needs the frames following it to be used; it cannot stand alone.
- AVIIF_LASTPART: Indicates this chunk needs the frames preceding it to be used; it cannot stand alone.
- AVIIF_NOTIME: The duration which is applied to the corresponding chunk is 0.

If neither AVIIF_FIRSTPART nor AVIIF_LASTPART is set, the chunk can be used alone, in other words, it is at least one packet of the corresponding stream. This is important for storing VBR audio streams in AVI files.

• dwChunk
Offset Contains the position of the header of the corresponding Chunk.
Warning: This can be either the absolute position in the file, or the position relatively to the first byte of the 'movi' identificator. An AVI File parser must be able to handleboth versions.

• dwChunkLength
Contains the size of the corresponding chunk in bytes.

No comments:

Post a Comment