The Metadata in RIFF files » History » Version 5
Mahesh Hegde, 10 Sep 2013 12:24
1 | 1 | Mahesh Hegde | h1. The Metadata in RIFF (.avi) files (Under construction) |
---|---|---|---|
2 | |||
3 | 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. |
||
4 | |||
5 | This page brief about the Riff(Resource Interchange File Format) type video file container, popular video files using Riff container being AVI files. |
||
6 | |||
7 | h2. Why RIFF? |
||
8 | |||
9 | 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. |
||
10 | |||
11 | h2. What is RIFF? |
||
12 | |||
13 | RIFF is a structured video container format Issued as a joint design by IBM Corporation and Microsoft Corporation in 1991. |
||
14 | |||
15 | h2. How it is structured? |
||
16 | |||
17 | 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: |
||
18 | |||
19 | * Every chunk should have ChunkId(four bytes), ChunkSize(four bytes). Do not include size of ChunkId and ChunkSize in ChunkSize. |
||
20 | * ChunkData having odd number of bytes should be padded with one more dummy byte,and ChunkSize is always even. |
||
21 | * 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. |
||
22 | * 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. |
||
23 | |||
24 | Following picture is a typical RIFF file. |
||
25 | 4 | Mahesh Hegde | !/attachments/540/riff_file_structure.jpg! |
26 | 1 | Mahesh Hegde | |
27 | 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. |
||
28 | |||
29 | |||
30 | h3. AVIH primitive Chunk |
||
31 | |||
32 | |_.Byte Number |_.Metadata |_.Description | |
||
33 | |0 to 3 | *avih* | Primitive Header tag |
||
34 | Signifying start of avih chunk | |
||
35 | |4 to 7 |size| 44(fixed) | |
||
36 | |8 to 11|Microseconds Per Frame| Video related Data | |
||
37 | |12 to 15| Maximum Bytes Per Second| Video related Data| |
||
38 | |16 to 19|Padding Granularity|Video related Data| |
||
39 | |20 to 23|Flags|Video related Data| |
||
40 | |24 to 27|Total Frames|Video related Data| |
||
41 | |28 to 31|Initial Frames|Video related Data| |
||
42 | |32 to 35|Streams|Video related Data| |
||
43 | |36 to 39|Suggested Buffer Size|Video related Data| |
||
44 | |40 to 43|Width|Video Dimention| |
||
45 | |44 to 47|Height|Video Dimention| |
||
46 | |48 to 51|Reserved|Reserved| |
||
47 | |||
48 | For More Detail refer http://msdn.microsoft.com/en-us/library/windows/desktop/dd318183(v=vs.85).aspx |
||
49 | |||
50 | h3. STRH Primitive Chunk |
||
51 | |||
52 | |_.Byte Number |_.Metadata |_.Description | |
||
53 | |0 to 3|*strh*|Stream Header Chunk| |
||
54 | |4 to 7|size|52| |
||
55 | |8 to 11|Type,'auds' |
||
56 | 'mids','txts' |
||
57 | 'vids'|Define Data about |
||
58 | either of Audio,Midi |
||
59 | text or Video| |
||
60 | |12 to 15|Handler|For Audio and Video, |
||
61 | This will be codec name which |
||
62 | will be used by Audio/Video Players| |
||
63 | |16 to 19|Flags|Defines whether Stream should be |
||
64 | enabled/disabled| |
||
65 | |20 to 23|Priority|Stream priority| |
||
66 | |24 to 27|Language|Stream Language| |
||
67 | |28 to 31|Initial Frames|Significant data for |
||
68 | interleaved Files,specifies Audio |
||
69 | position relative to Video| |
||
70 | |32 to 35|Scale|Used internally |
||
71 | for calculations| |
||
72 | |36 to 39|Rate|Stream Rate| |
||
73 | |40 to 43|Start|Specifies Starting Time of |
||
74 | the Stream| |
||
75 | |44 to 47|Length|Stream Length| |
||
76 | |48 to 51|Suggested Buffer |
||
77 | Size|Used by Video Players| |
||
78 | |52 to 55|Quality|Stream Quality| |
||
79 | |56 to 59|Sample Size|Size of Single sample| |
||
80 | |60 to 63|Frame|Rectangle position |
||
81 | ,upper Left corner| |
||
82 | |||
83 | |||
84 | For More Detail refer http://msdn.microsoft.com/en-us/library/windows/desktop/dd318183(v=vs.85).aspx |
||
85 | |||
86 | Similar Chunk structure is found in *strd* and *strf*. |
||
87 | |||
88 | h3. INFO Main Header Chunk |
||
89 | |||
90 | |_.Byte Number |_.Metadata |_.Description | |
||
91 | |0 to 3|INFO|Info Header Tag| |
||
92 | |4 to 7|Info Primitive Tag|Predefined Tag Header| |
||
93 | |8 to 11|size|Size of Info Primitive Chunk| |
||
94 | |12 to 12+size|Info Primitive |
||
95 | Data|String Array of Metadata| |
||
96 | |12+size+1 to 12+size+4|Info Primitive Chunk|Optional Second Info Primitive Chunk| |
||
97 | |....|size|Size of Second Info Primitive Chunk| |
||
98 | |||
99 | 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. |
||
100 | |||
101 | |||
102 | h3. In Exiv2, all video files are treated as Image Files and the RIFF read flow is as follows: |
||
103 | |||
104 | 2 | Mahesh Hegde | !/attachments/538/riff_read_in_exiv2_flow.jpeg! |
105 | 1 | Mahesh Hegde | |
106 | h3. Write-Flow |
||
107 | |||
108 | 5 | Mahesh Hegde | !/attachments/539/riff_write_flow.jpeg! |