Project

General

Profile

Actions

The Metadata in RIFF files » History » Revision 1

Revision 1/6 | Next »
Mahesh Hegde, 10 Sep 2013 12:19


The Metadata in RIFF (.avi) files (Under construction)

Please note: Four bytes words in caps have special significance in this document, which are called Chunk headers, and appear exactly same in the original RIFF file.

This page brief about the Riff(Resource Interchange File Format) type video file container, popular video files using Riff container being AVI files.

Why RIFF?

Since video files most likely to have multiple data chunks like video,audio,subtitle,metadata which essentially describe about the video,it's been convenient to have structured data rather than in a random order.

What is RIFF?

RIFF is a structured video container format Issued as a joint design by IBM Corporation and Microsoft Corporation in 1991.

How it is structured?

Everything in RIFF is structured in Chunk, sub-chunk hierarchy. Every chunk contains ChunkID, ChunkSize, and ChunkData. First four bytes of a RIFF file type must be ASCII values corresponding to letters RIFF. This is the ChunkId parent of every other sub-chunk. Rules dominating RIFF structure which describe how a typical RIFF file are:

  • Every chunk should have ChunkId(four bytes), ChunkSize(four bytes). Do not include size of ChunkId and ChunkSize in ChunkSize.
  • ChunkData having odd number of bytes should be padded with one more dummy byte,and ChunkSize is always even.
  • ChunkData can be simple data like video frames (encoded or plane), audio samples or another Chunk having similar structure as parent Chunk. Hence ChunkData can have sub-chunks and it is recursive, which means LIST chunk can contain another LIST chunk.
  • Every chunk will have data which has to be decoded according to either predefined schema(Fixed size structured metadata like AVIH,*STRH* primitive chunks) or variable size metadata chunks like INFO main Chunk.

Following picture is a typical RIFF file.

Here Tags RIFF,AVI (notice single space after AVI),LIST,hdrl,movi are four byte character codes,and are present right in the beginning of the chunks and appear exactly same(corresponding ASCII) in the file.Following are the some of the predefined Primitive chunk Structure.

AVIH primitive Chunk

Byte Number Metadata Description
0 to 3 avih Primitive Header tag
Signifying start of avih chunk
4 to 7 size 44(fixed)
8 to 11 Microseconds Per Frame Video related Data
12 to 15 Maximum Bytes Per Second Video related Data
16 to 19 Padding Granularity Video related Data
20 to 23 Flags Video related Data
24 to 27 Total Frames Video related Data
28 to 31 Initial Frames Video related Data
32 to 35 Streams Video related Data
36 to 39 Suggested Buffer Size Video related Data
40 to 43 Width Video Dimention
44 to 47 Height Video Dimention
48 to 51 Reserved Reserved

For More Detail refer http://msdn.microsoft.com/en-us/library/windows/desktop/dd318183(v=vs.85).aspx

STRH Primitive Chunk

Byte Number Metadata Description
0 to 3 strh Stream Header Chunk
4 to 7 size 52
8 to 11 Type,'auds'
'mids','txts'
'vids'
Define Data about
either of Audio,Midi
text or Video
12 to 15 Handler For Audio and Video,
This will be codec name which
will be used by Audio/Video Players
16 to 19 Flags Defines whether Stream should be
enabled/disabled
20 to 23 Priority Stream priority
24 to 27 Language Stream Language
28 to 31 Initial Frames Significant data for
interleaved Files,specifies Audio
position relative to Video
32 to 35 Scale Used internally
for calculations
36 to 39 Rate Stream Rate
40 to 43 Start Specifies Starting Time of
the Stream
44 to 47 Length Stream Length
48 to 51 Suggested Buffer
Size
Used by Video Players
52 to 55 Quality Stream Quality
56 to 59 Sample Size Size of Single sample
60 to 63 Frame Rectangle position
,upper Left corner

For More Detail refer http://msdn.microsoft.com/en-us/library/windows/desktop/dd318183(v=vs.85).aspx

Similar Chunk structure is found in strd and strf.

INFO Main Header Chunk

Byte Number Metadata Description
0 to 3 INFO Info Header Tag
4 to 7 Info Primitive Tag Predefined Tag Header
8 to 11 size Size of Info Primitive Chunk
12 to 12+size Info Primitive
Data
String Array of Metadata
12+size+1 to 12+size+4 Info Primitive Chunk Optional Second Info Primitive Chunk
... size Size of Second Info Primitive Chunk

Info is slightly special Metadata Chunk,because we can store variable sized metadata in here.These are basically user related data and video subjects related information.Here we have flexibility to add tags,having standard tag Ids like Comment,Copyright,Location Description,Genre,Country and more.

In Exiv2, all video files are treated as Image Files and the RIFF read flow is as follows:

Write-Flow

Updated by Mahesh Hegde about 8 years ago · 1 revisions