Mercurial > mplayer.hg
annotate DOCS/tech/mpcf.txt @ 12228:7e22b762e1a8
typo fix: Mplayer --> MPlayer
author | diego |
---|---|
date | Sat, 17 Apr 2004 23:19:22 +0000 |
parents | 3baef37d3b7c |
children | a0ddf85bdee0 |
rev | line source |
---|---|
12161
8e4700721c38
removing checksum_threshold & keyframe prediction
michael
parents:
12150
diff
changeset
|
1 NUT Open Container Format DRAFT 20040409 |
10817 | 2 ---------------------------------------- |
9294 | 3 |
4 | |
5 | |
6 Intro: | |
7 | |
8 Features / goals: | |
9 (supported by the format, not necessary by a specific implementation) | |
10 | |
11 Simple | |
12 use the same encoding for nearly all fields | |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
13 simple decoding, so slow cpus (and embedded systems) can handle it |
9294 | 14 Extendible |
15 no limit for the possible values for all fields (using universal vlc) | |
16 allow adding of new headers in the future | |
17 allow adding more fields at the end of headers | |
18 Compact | |
19 ~0.2% overhead, for normal bitrates | |
20 index is <10kb per hour (1 keyframe every 3sec) | |
10831 | 21 a usual header for a file is about 100bytes (audio + video headers together) |
12082 | 22 a packet header is about ~1-8 bytes |
9294 | 23 Error resistant |
24 seeking / playback without an index | |
25 headers & index can be repeated | |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
26 damaged files can be played back with minimal data lost and fast |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
27 resyncing times |
9294 | 28 |
29 | |
30 | |
31 Definitions: | |
32 | |
33 MUST the specific part must be done to conform to this standard | |
34 SHOULD its recommanded to be done that way but its not strictly required | |
35 | |
36 | |
37 | |
38 Syntax: | |
39 | |
9295 | 40 Type definitions: |
12209 | 41 |
42 f(x) n fixed bits in big endian order | |
43 u(x) unsigned number encoded in x bits in MSB first order | |
44 | |
9295 | 45 v |
46 value=0 | |
47 do{ | |
48 more_data u(1) | |
49 data u(7) | |
50 value= 128*value + data | |
51 }while(more_data) | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
52 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
53 s |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
54 temp v |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
55 temp++ |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
56 if(temp&1) value= -(temp>>1) |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
57 else value= (temp>>1) |
9323 | 58 |
59 b (binary data or string) | |
60 for(i=0; i<length; i++){ | |
61 data[i] u(8) | |
9295 | 62 } |
9335
de287fe94511
lang & country codes from ISO & utf8 requirement (ideas from Tobias Diedrich <td at sim dot uni-hannover dot de>
michael
parents:
9325
diff
changeset
|
63 Note: strings MUST be encoded in utf8 |
9295 | 64 |
12117 | 65 vb |
66 length v | |
67 value b | |
68 | |
9295 | 69 |
70 Bitstream syntax: | |
9294 | 71 packet header |
12084
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
72 forward ptr v |
12082 | 73 backward ptr v |
9294 | 74 |
75 align_byte | |
76 while(not byte aligned) | |
77 one f(1) | |
78 | |
79 reserved_bytes | |
80 for(i=0; i<forward_ptr - length_of_non_reserved; i++) | |
81 reserved u(8) | |
12184 | 82 a demuxer MUST ignore any reserved bytes |
83 a muxer MUST NOT write any reserved bytes, as this would make it | |
10824 | 84 inpossible to add new fields at the end of packets in the future in |
85 a compatible way | |
86 | |
9294 | 87 main header: |
10831 | 88 main_startcode f(64) |
9294 | 89 packet header |
90 version v | |
91 stream_count v | |
12084
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
92 for(i=0; i<256; ){ |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
93 tmp_flag v |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
94 tmp_stream v |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
95 tmp_mul v |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
96 tmp_size v |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
97 count v |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
98 for(j=0; j<count; j++, i++){ |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
99 flags[i]= tmp_flag; |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
100 stream_id_plus1[i]= tmp_stream; |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
101 data_size_mul[i]= tmp_mul; |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
102 data_size_lsb[i]= tmp_size; |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
103 if(++tmp_size >= tmp_mul){ |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
104 tmp_size=0; |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
105 tmp_stream++; |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
106 } |
12082 | 107 } |
108 } | |
9294 | 109 reserved_bytes |
110 checksum u(32) | |
111 | |
112 stream_header: | |
10831 | 113 stream_startcode f(64) |
9294 | 114 packet_header |
115 stream_id v | |
116 stream_class v | |
12150 | 117 fourcc vb |
9294 | 118 average_bitrate v |
12150 | 119 language_code vb |
9297 | 120 time_base_nom v |
121 time_base_denom v | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
122 msb_timestamp_shift v |
12084
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
123 initial_timestamp_predictor v(3) |
12082 | 124 initial_data_size_predictor v(2) |
9294 | 125 fixed_fps u(1) |
9347
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
126 index_flag u(1) |
9356 | 127 reserved u(6) |
9357
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
128 for(;;){ |
9361 | 129 codec_specific_data_type v |
130 if(codec_specific_data_type==0) break; | |
12117 | 131 codec_specific_data vb |
9357
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
132 } |
9294 | 133 |
134 video_stream_header: | |
135 stream_header | |
136 width v | |
137 height v | |
138 sample_width v | |
139 sample_height v | |
140 colorspace_type v | |
141 reserved_bytes | |
142 checksum u(32) | |
143 | |
144 audio_stream_header: | |
145 stream_header | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
146 samplerate_mul v |
9294 | 147 channel_count v |
148 reserved_bytes | |
149 checksum u(32) | |
9420 | 150 |
12082 | 151 |
9294 | 152 frame |
12082 | 153 if(frame_type == 2){ |
154 frame_type2_startcode f(64) | |
9294 | 155 } |
12082 | 156 frame_code f(8) |
157 if(flags[frame_code]&1){ | |
158 packet header | |
159 } | |
12084
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
160 if(stream_id_plus1[frame_code]==0){ |
12082 | 161 stream_id v |
162 } | |
12084
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
163 if(flags[frame_code]&16){ |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
164 if(flags[frame_code]&4){ |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
165 timestamp v |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
166 }else{ |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
167 lsb_timestamp v |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
168 } |
9420 | 169 } |
12082 | 170 if(flags[frame_code]&2){ |
171 data_size_msb v | |
172 } | |
173 data | |
174 | |
9294 | 175 Index: |
10831 | 176 index_startcode f(64) |
9294 | 177 packet header |
178 stream_id v | |
179 index_length v | |
180 for(i=0; i<index_length; i++){ | |
181 index_timestamp v | |
182 index_position v | |
183 } | |
9310 | 184 reserved_bytes |
9294 | 185 checksum u(32) |
186 | |
9310 | 187 info_packet: (optional) |
10831 | 188 info_startcode f(64) |
9294 | 189 packet header |
9323 | 190 for(;;){ |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
191 id v |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
192 if(id==0) break |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
193 name= info_table[id][0] |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
194 type= info_table[id][1] |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
195 if(type==NULL) |
12117 | 196 type vb |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
197 if(name==NULL) |
12117 | 198 name vb |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
199 if(type=="v") |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
200 value v |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
201 else |
12117 | 202 value vb |
9323 | 203 } |
9310 | 204 reserved_bytes |
9294 | 205 checksum u(32) |
9323 | 206 |
207 | |
9294 | 208 forward_ptr |
209 backward_ptr | |
210 pointer to the next / previous packet | |
9323 | 211 pointers are relative and backward pointer is implicitelly negative |
9294 | 212 Note: a frame with 0 bytes means that its skiped |
9323 | 213 Note: the forward pointer is equal to the size of this packet including |
214 the header | |
215 the backward pointer is equal to the size of the previous packet | |
216 Example: | |
217 0 | |
218 size1 (size of frame1 including header) | |
219 frame1 | |
220 | |
221 size1 | |
222 size2 | |
223 frame2 | |
224 | |
225 size2 | |
226 size3 | |
227 frame3 | |
228 | |
229 | |
230 *_startcode | |
12162 | 231 all startcodes start with 'N' |
232 | |
233 main_startcode | |
234 0x7A561F5F04ADULL + (((uint64_t)('N'<<8) + 'M')<<48) | |
235 stream_starcode | |
236 0x11405BF2F9DBULL + (((uint64_t)('N'<<8) + 'S')<<48) | |
237 frame_type2_startcode | |
238 0xE4ADEECA4569ULL + (((uint64_t)('N'<<8) + 'K')<<48) | |
239 index_startcode | |
240 0xDD672F23E64EULL + (((uint64_t)('N'<<8) + 'X')<<48) | |
241 info_startcode | |
242 0xAB68B596BA78ULL + (((uint64_t)('N'<<8) + 'I')<<48) | |
9294 | 243 |
244 version | |
12150 | 245 1 for now |
12082 | 246 |
9294 | 247 stream_id |
248 Note: streams with a lower relative class MUST have a lower relative id | |
249 so a stream with class 0 MUST allways have a id which is lower then any | |
250 stream with class > 0 | |
12150 | 251 stream_id MUST be < stream_count |
9294 | 252 |
253 stream_class | |
254 0 video | |
255 32 audio | |
256 64 subtiles | |
257 Note the remaining values are reserved and MUST NOT be used | |
12184 | 258 a demuxer MUST ignore streams with reserved classes |
9294 | 259 |
260 fourcc | |
261 identification for the codec | |
9323 | 262 example: "H264" |
10817 | 263 MUST contain 2 or 4 bytes, note, this might be increased in the future |
264 if needed | |
265 | |
9294 | 266 language_code |
9335
de287fe94511
lang & country codes from ISO & utf8 requirement (ideas from Tobias Diedrich <td at sim dot uni-hannover dot de>
michael
parents:
9325
diff
changeset
|
267 ISO 639 and ISO 3166 for language/country code |
9325 | 268 something like "usen" (US english), can be 0 |
9294 | 269 if unknown |
9335
de287fe94511
lang & country codes from ISO & utf8 requirement (ideas from Tobias Diedrich <td at sim dot uni-hannover dot de>
michael
parents:
9325
diff
changeset
|
270 see http://www.loc.gov/standards/iso639-2/englangn.html |
de287fe94511
lang & country codes from ISO & utf8 requirement (ideas from Tobias Diedrich <td at sim dot uni-hannover dot de>
michael
parents:
9325
diff
changeset
|
271 and http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1/en_listp1.html |
9294 | 272 |
9297 | 273 time_base_nom / time_base_denom = time_base |
9294 | 274 the number of timer ticks per second, this MUST be equal to the fps |
275 if the fixed_fps is 1 | |
9297 | 276 time_base_denom MUST not be 0 |
277 time_base_nom and time_base_denom MUST be relative prime | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
278 time_base_nom MUST be < 2^16 |
9297 | 279 examples: |
280 fps time_base_nom time_base_denom | |
281 30 30 1 | |
282 29.97 30000 1001 | |
283 23.976 24000 1001 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
284 sample_rate sample_rate_mul time_base_nom time_base_denom |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
285 44100 1 44100 1 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
286 44100 64 11025 16 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
287 48000 1024 375 8 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
288 Note: the advantage to using a large sample_rate_mul is that the |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
289 timestamps need fewer bits |
9294 | 290 |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
291 msb_timestamp_shift |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
292 amount of bits msb_timestamp is shifted left before adding lsb_timestamp |
9294 | 293 MUST be <16 |
294 | |
295 fixed_fps | |
296 1 indicates that the fps is fixed | |
297 | |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
298 index_flag |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
299 1 indicates that this file has an index |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
300 Note, all files SHOULD have an index at the end except, (realtime) streams |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
301 Note, all streams SHOULD have an index |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
302 |
9357
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
303 codec_specific_data_type |
10817 | 304 0 none/end |
9361 | 305 1 native |
306 2 bitmapinfoheader | |
307 3 waveformatex | |
308 4 imagedesc | |
309 5 sounddesc | |
9357
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
310 "native", means a simple api & container independanet storage form, |
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
311 for example some mpeg4-es headers |
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
312 |
9356 | 313 codec_specific_data |
314 private global data for a codec (could be huffman tables or ...) | |
12082 | 315 |
316 frame_code | |
317 the meaning of this byte is stored in the main header | |
318 the value 78 ('N') is forbidden to ensure that the byte is always | |
319 different from the first byte of any startcode | |
9420 | 320 |
12082 | 321 flags[frame_code] |
12084
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
322 the bits of the flags from MSB to LSB are KKTTTDP |
12082 | 323 P is 1 for type 1 and 2 packets, 0 for type 0 packets |
12084
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
324 TTT is the timestamp_code, 000,001,010 use the last timestamp + the |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
325 first, second and third last unique timestamp difference, so if |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
326 the timestamp differences, are +3,+1,+2,+2,+1 then last diff is |
12082 | 327 +1, second is +2 and third is +3 |
12084
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
328 100,101 mean that the lsb or full timestamp is coded |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
329 if TTT is 100, then the timestamp is calculated by |
12082 | 330 mask = (1<<msb_timestamp_shift)-1; |
331 delta= last_timestamp - mask/2 | |
332 timestamp= ((timestamp_lsb-delta)&mask) + delta | |
12208
31811f35f845
type 1/2 packets must have MSB timestamps (this is already mentioned at some other places but i forgot this one)
michael
parents:
12184
diff
changeset
|
333 TTT must be 101 if the packet_type is not 0 |
12184 | 334 the last timestamp differences are reset to the |
335 initial_timestamp_predictor values from the stream header if a | |
336 packet of type not 0 in encountered | |
12084
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
337 if D is 1 then data_size_msb is coded, otherwise its 0 |
12082 | 338 KK is the keyframe_type |
339 00-> no keyframe, | |
340 01-> keyframe, | |
12084
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
341 flags=1 can be used to mark illegal frame_code bytes |
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
342 frame_code=78 must have flags=1 |
9420 | 343 |
12082 | 344 frame_type |
345 0 is indicated by (flags[frame_code]&1)==0 | |
346 1 is indicated by (flags[frame_code]&1)==1 && !startcode | |
347 2 is indicated by (flags[frame_code]&1)==1 && startcode | |
348 there SHOULD not be more then 0.5 seconds or 16kbyte of type 0 frames | |
349 wihout a intervening frame of different frame_type | |
12110
a34dc5a369ca
restrictions to ensure that O(log n) seeking and error recovery is possible
michael
parents:
12084
diff
changeset
|
350 * type 2 frames MUST be decodeable independantly of any other frames |
a34dc5a369ca
restrictions to ensure that O(log n) seeking and error recovery is possible
michael
parents:
12084
diff
changeset
|
351 this means they MUST be keyframes and they MUST use a full timestamp |
a34dc5a369ca
restrictions to ensure that O(log n) seeking and error recovery is possible
michael
parents:
12084
diff
changeset
|
352 * type 1 frames MUST not depend(1) upon any other frames, this means, |
a34dc5a369ca
restrictions to ensure that O(log n) seeking and error recovery is possible
michael
parents:
12084
diff
changeset
|
353 they MUST use a full timestamp |
a34dc5a369ca
restrictions to ensure that O(log n) seeking and error recovery is possible
michael
parents:
12084
diff
changeset
|
354 * type 0 frames MUST not depend(1) upon frames prior to the last type |
a34dc5a369ca
restrictions to ensure that O(log n) seeking and error recovery is possible
michael
parents:
12084
diff
changeset
|
355 1/2 frames |
a34dc5a369ca
restrictions to ensure that O(log n) seeking and error recovery is possible
michael
parents:
12084
diff
changeset
|
356 depend(1) means dependancy on the container level (NUT) not dependancy |
a34dc5a369ca
restrictions to ensure that O(log n) seeking and error recovery is possible
michael
parents:
12084
diff
changeset
|
357 on the codec level |
a34dc5a369ca
restrictions to ensure that O(log n) seeking and error recovery is possible
michael
parents:
12084
diff
changeset
|
358 |
12084
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
359 stream_id_plus1[frame_code] |
12082 | 360 must be <250 |
12084
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
361 if its 0 then the stream_id is coded in the frame |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
362 |
12082 | 363 data_size_mul[frame_code] |
364 must be <250 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
365 |
12082 | 366 data_size_lsb[frame_code] |
367 must be <250 | |
368 | |
12084
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
369 data_size |
12082 | 370 if(data_size_lsb == data_size_mul) |
371 data_size= last; | |
372 else if(data_size_lsb == data_size_mul+1) | |
12184 | 373 data_size= next_last; |
12082 | 374 else if(data_size_lsb < data_size_mul) |
375 data_size= data_size_lsb + data_size_msb*data_size_mul; | |
376 else reserved | |
12184 | 377 next_last is the second last unique data_size, for example: |
378 previous data_size: 123,500,312,500,500 last=500, next_last=312 | |
379 last and next_last are reset to the initial_data_size_predictor values | |
380 stored in the stream header if an frame with type > 0 is encountered | |
12082 | 381 |
9294 | 382 lsb_timestamp |
12082 | 383 least significant bits of the timestamp in time_base precission |
9294 | 384 Example: IBBP display order |
12084
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
385 keyframe timestamp=0 -> timestamp=0 |
9294 | 386 frame lsb_timestamp=3 -> timestamp=3 |
387 frame lsb_timestamp=1 -> timestamp=1 | |
388 frame lsb_timestamp=2 -> timestamp=2 | |
389 ... | |
12084
68baf8877c07
reversing the change to the forw/backw pointers, its somewhat simpler to update it if the forward pointer is first
michael
parents:
12082
diff
changeset
|
390 keyframe msb_timestamp=257 -> timestamp=257 |
12082 | 391 frame lsb_timestamp=255->timestamp=255 |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
392 frame lsb_timestamp=0 -> timestamp=256 |
9294 | 393 frame lsb_timestamp=4 -> timestamp=260 |
394 frame lsb_timestamp=2 -> timestamp=258 | |
395 frame lsb_timestamp=3 -> timestamp=259 | |
12110
a34dc5a369ca
restrictions to ensure that O(log n) seeking and error recovery is possible
michael
parents:
12084
diff
changeset
|
396 all timestamps of keyframes of a single stream MUST be monotone |
9294 | 397 |
398 width/height | |
399 MUST be set to the coded width/height | |
400 | |
401 sample_width/sample_height (aspect ratio) | |
402 sample_width is the horizontal distance between samples | |
403 sample_width and sample_height MUST be relative prime if not zero | |
404 MUST be 0 if unknown | |
405 | |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
406 colorspace_type |
10166 | 407 0 unknown |
408 1 ITU Rec 624 / ITU Rec 601 Y range: 16..235 Cb/Cr range: 16..240 | |
409 2 ITU Rec 709 Y range: 16..235 Cb/Cr range: 16..240 | |
410 17 ITU Rec 624 / ITU Rec 601 Y range: 0..255 Cb/Cr range: 0..255 | |
411 18 ITU Rec 709 Y range: 0..255 Cb/Cr range: 0..255 | |
412 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
413 samplerate_mul |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
414 the number of samples per second in one time_base unit |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
415 samplerate = time_base*samplerate_mul |
9294 | 416 |
9311
4b04416ada91
zero_bit for normal frames, so we can distinguish them from other packets
michael
parents:
9310
diff
changeset
|
417 zero_bit |
4b04416ada91
zero_bit for normal frames, so we can distinguish them from other packets
michael
parents:
9310
diff
changeset
|
418 MUST be 0, its there to distinguish non keyframes from other packets, |
4b04416ada91
zero_bit for normal frames, so we can distinguish them from other packets
michael
parents:
9310
diff
changeset
|
419 Note: all packets have a 64-bit startcode except non-keyframes to reduce |
4b04416ada91
zero_bit for normal frames, so we can distinguish them from other packets
michael
parents:
9310
diff
changeset
|
420 their size, and all startcodes start with a 1 bit |
9294 | 421 |
422 checksum | |
12118
b8fea9441d02
switching from crc32 to adler32 checksums, cuz they are faster and simpler
michael
parents:
12117
diff
changeset
|
423 adler32 checksum |
9294 | 424 |
425 index_timestamp | |
426 value in time_base precission, relative to the last index_timestamp | |
427 | |
428 index_position | |
429 position in bytes of the first byte of the keyframe header, relative | |
430 to the last index_position | |
431 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
432 id |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
433 the id of the type/name pair, so its more compact |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
434 0 means end |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
435 |
9323 | 436 type |
9347
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
437 for example: "UTF8" -> String or "JPEG" -> jpeg image |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
438 Note: nonstandard fields should be prefixed by "X-" |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
439 Note: MUST be less than 6 byte long (might be increased to 64 later) |
9323 | 440 |
9295 | 441 name |
442 the name of the info entry, valid names are | |
10873 | 443 "TotalTime" total length of the stream in msecs |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
444 "StreamId" the stream(s) to which the info packet applies |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
445 "StartTimestamp" |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
446 "EndTimestamp" the time range in msecs to which the info applies |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
447 "SegmentId" a unique id for the streams + time specified |
9347
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
448 "Author" |
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
449 "Description" |
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
450 "Copyright" |
9369 | 451 "Encoder" the name & version of the software used for encoding |
9347
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
452 "Title" |
9373 | 453 "Cover" an image of the (cd,dvd,vhs,..) cover (preferable PNG or JPEG) |
9350 | 454 "Source" "DVD", "VCD", "CD", "MD", "FM radio", "VHS", "TV", |
455 "LD" | |
9373 | 456 Optional: appended PAL,NTSC,SECAM, ... in parentheses |
9350 | 457 "CaptureDevice" "BT878", "BT848", "webcam", ... (more exact names are fine too) |
458 "CreationTime" "2003-01-20 20:13:15Z", ... | |
459 (ISO 8601 format, see http://www.cl.cam.ac.uk/~mgk25/iso-time.html) | |
460 Note: dont forget the timezone | |
11975 | 461 "ReplayGain" |
9360
add934b25d6d
"X-" prefix for nonstd fields & "keywords" idea by (Andreas Hess <jaska at gmx dot net>)
michael
parents:
9357
diff
changeset
|
462 "Keywords" |
9295 | 463 Note: if someone needs some others, please tell us about them, so we can |
464 add them to the official standard (if they are sane) | |
9360
add934b25d6d
"X-" prefix for nonstd fields & "keywords" idea by (Andreas Hess <jaska at gmx dot net>)
michael
parents:
9357
diff
changeset
|
465 Note: nonstandard fields should be prefixed by "X-" |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
466 Note: MUST be less than 64 bytes long |
9295 | 467 |
468 value | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
469 value of this name/type pair |
9295 | 470 |
9310 | 471 stuffing |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
472 0x80 can be placed infront of any type v entry for stuffing |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
473 purposes |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
474 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
475 info_table[][2]={ |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
476 {NULL , NULL }, // end |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
477 {NULL , NULL }, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
478 {NULL , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
479 {NULL , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
480 {NULL , "s"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
481 {"StreamId" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
482 {"SegmentId" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
483 {"StartTimestamp" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
484 {"EndTimestamp" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
485 {"Author" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
486 {"Titel" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
487 {"Description" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
488 {"Copyright" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
489 {"Encoder" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
490 {"Keyword" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
491 {"Cover" , "JPEG"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
492 {"Cover" , "PNG"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
493 }; |
9294 | 494 |
495 Structure: | |
496 | |
497 the headers MUST be in exactly the following order (to simplify demuxer design) | |
498 main header | |
499 stream_header (id=0) | |
500 stream_header (id=1) | |
501 ... | |
502 stream_header (id=n) | |
503 | |
504 headers may be repated, but if they are then they MUST all be repeated together | |
505 and repeated headers MUST be identical | |
506 | |
507 headers MUST be repeated every 10sec at least ? FIXME | |
10817 | 508 headers MUST be repeated BEFORE keyframes |
9310 | 509 headers MUST be repeated at least twice (so they exist 3 times in a file) |
9295 | 510 |
9310 | 511 Index |
9580 | 512 the index can be repeated but there SHOULD be at least one for each stream at |
513 the end | |
9311
4b04416ada91
zero_bit for normal frames, so we can distinguish them from other packets
michael
parents:
9310
diff
changeset
|
514 Note: in case of realtime streaming there is no end, so no index there either |
9310 | 515 |
516 Info packets | |
517 the info_packet can be repeated, it can also contain different names & values | |
518 each time but only if allso the time is different | |
519 Info packets can be used to describe the file or some part of it (chapters) | |
520 | |
521 info packets, SHOULD be placed at the begin of the file at least | |
522 for realtime streaming info packets will normally be transmitted when they apply | |
523 for example, the current song title & artist of the currently shown music video | |
524 | |
525 Unknown packets | |
12184 | 526 MUST be ignored by the demuxer |
9310 | 527 |
9294 | 528 Sample code (GPL, & untested) |
529 | |
530 typedef BufferContext{ | |
531 uint8_t *buf; | |
532 uint8_t *buf_ptr; | |
533 }BufferContext; | |
534 | |
535 static inline uint64_t get_bytes(BufferContext *bc, int count){ | |
536 uint64_t val=0; | |
537 | |
538 assert(count>0 && count<9) | |
539 | |
540 for(i=0; i<count; i++){ | |
541 val <<=8; | |
542 val += *(bc->buf_ptr++); | |
543 } | |
544 | |
545 return val; | |
546 } | |
547 | |
548 static inline void put_bytes(BufferContext *bc, int count, uint64_t val){ | |
549 uint64_t val=0; | |
550 | |
551 assert(count>0 && count<9) | |
552 | |
553 for(i=count-1; i>=0; i--){ | |
554 *(bc->buf_ptr++)= val >> (8*i); | |
555 } | |
556 | |
557 return val; | |
558 } | |
559 | |
10061 | 560 static inline uint64_t get_v(BufferContext *bc){ |
9294 | 561 uint64_t val= 0; |
562 | |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
563 for(; space_left(bc) > 0; ){ |
9294 | 564 int tmp= *(bc->buf_ptr++); |
565 if(tmp&0x80) | |
566 val= (val<<7) + tmp - 0x80; | |
567 else | |
9299 | 568 return (val<<7) + tmp; |
9294 | 569 } |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
570 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
571 return -1; |
9294 | 572 } |
573 | |
10061 | 574 static inline int put_v(BufferContext *bc, uint64_t val){ |
9294 | 575 int i; |
576 | |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
577 if(space_left(bc) < 9) return -1; |
9294 | 578 |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
579 val &= 0x7FFFFFFFFFFFFFFFULL; // FIXME can only encode upto 63 bits currently |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
580 for(i=7; ; i+=7){ |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
581 if(val>>i == 0) break; |
9294 | 582 } |
583 | |
10827 | 584 for(i-=7; i>0; i-=7){ |
9294 | 585 *(bc->buf_ptr++)= 0x80 | (val>>i); |
586 } | |
587 *(bc->buf_ptr++)= val&0x7F; | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
588 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
589 return 0; |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
590 } |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
591 |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
592 Authors |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
593 |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
594 Folks from MPlayer Developers Mailinglist (http://www.mplayehrq.hu/). |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
595 Authors in ABC-order: (FIXME! Tell us if we left you out) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
596 Beregszaszi, Alex (alex@fsn.hu) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
597 Bunkus, Moritz (moritz@bunkus.org) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
598 Diedrich, Tobias (td@sim.uni-hannover.de) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
599 Franz, Fabian (FabianFranz@gmx.de) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
600 Gereoffy, Arpad (arpi@thot.banki.hu) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
601 Hess, Andreas (jaska@gmx.net) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
602 Niedermayer, Michael (michaelni@gmx.at) |