Mercurial > mplayer.hg
annotate DOCS/tech/mpcf.txt @ 12261:d43f1c599701
remove data_size prediction
merge lsb and full timestamp
maybe clarify flags
author | michael |
---|---|
date | Fri, 23 Apr 2004 15:48:17 +0000 |
parents | 362cf8df665e |
children | a6b64a263ca2 |
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 |
9294 | 73 |
74 align_byte | |
75 while(not byte aligned) | |
76 one f(1) | |
77 | |
78 reserved_bytes | |
79 for(i=0; i<forward_ptr - length_of_non_reserved; i++) | |
80 reserved u(8) | |
12184 | 81 a demuxer MUST ignore any reserved bytes |
82 a muxer MUST NOT write any reserved bytes, as this would make it | |
10824 | 83 inpossible to add new fields at the end of packets in the future in |
84 a compatible way | |
85 | |
9294 | 86 main header: |
10831 | 87 main_startcode f(64) |
9294 | 88 packet header |
89 version v | |
90 stream_count v | |
12238 | 91 max_type0_size 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) |
9294 | 124 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
|
125 index_flag u(1) |
9356 | 126 reserved u(6) |
9357
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
127 for(;;){ |
9361 | 128 codec_specific_data_type v |
129 if(codec_specific_data_type==0) break; | |
12117 | 130 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
|
131 } |
9294 | 132 |
133 video_stream_header: | |
134 stream_header | |
135 width v | |
136 height v | |
137 sample_width v | |
138 sample_height v | |
139 colorspace_type v | |
140 reserved_bytes | |
141 checksum u(32) | |
142 | |
143 audio_stream_header: | |
144 stream_header | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
145 samplerate_mul v |
9294 | 146 channel_count v |
147 reserved_bytes | |
148 checksum u(32) | |
9420 | 149 |
12082 | 150 |
9294 | 151 frame |
12082 | 152 if(frame_type == 2){ |
153 frame_type2_startcode f(64) | |
9294 | 154 } |
12082 | 155 frame_code f(8) |
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
|
156 if(stream_id_plus1[frame_code]==0){ |
12082 | 157 stream_id v |
158 } | |
12261 | 159 if((flags[frame_code]&3)==3){ |
160 coded_timestamp v | |
161 } | |
12238 | 162 if(flags[frame_code]&4){ |
12082 | 163 data_size_msb v |
164 } | |
165 data | |
166 | |
9294 | 167 Index: |
10831 | 168 index_startcode f(64) |
9294 | 169 packet header |
170 stream_id v | |
171 index_length v | |
172 for(i=0; i<index_length; i++){ | |
173 index_timestamp v | |
174 index_position v | |
175 } | |
9310 | 176 reserved_bytes |
9294 | 177 checksum u(32) |
178 | |
9310 | 179 info_packet: (optional) |
10831 | 180 info_startcode f(64) |
9294 | 181 packet header |
9323 | 182 for(;;){ |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
183 id v |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 if(type==NULL) |
12117 | 188 type vb |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
189 if(name==NULL) |
12117 | 190 name vb |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
191 if(type=="v") |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
192 value v |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
193 else |
12117 | 194 value vb |
9323 | 195 } |
9310 | 196 reserved_bytes |
9294 | 197 checksum u(32) |
9323 | 198 |
12242 | 199 file |
200 file_id_string | |
201 while(!eof){ | |
202 main_header | |
203 for(i=0; i<stream_count; i++){ | |
204 if(next_packet==video_stream_header) | |
205 video_stream_header | |
206 else | |
207 audio_stream_header | |
208 } | |
209 while(next_packet != main_header){ | |
210 if(next_packet == info_packet) | |
211 info_packet | |
212 else | |
213 frame | |
214 } | |
215 //FIXME index | |
216 } | |
9323 | 217 |
9294 | 218 forward_ptr |
12238 | 219 size of the packet (exactly the distance from the first byte of the |
220 startcode of the current packet to the first byte of the following packet | |
12242 | 221 |
222 file_id_string | |
223 "nut/multimedia container\0" | |
9323 | 224 |
225 *_startcode | |
12162 | 226 all startcodes start with 'N' |
227 | |
228 main_startcode | |
229 0x7A561F5F04ADULL + (((uint64_t)('N'<<8) + 'M')<<48) | |
230 stream_starcode | |
231 0x11405BF2F9DBULL + (((uint64_t)('N'<<8) + 'S')<<48) | |
232 frame_type2_startcode | |
233 0xE4ADEECA4569ULL + (((uint64_t)('N'<<8) + 'K')<<48) | |
234 index_startcode | |
235 0xDD672F23E64EULL + (((uint64_t)('N'<<8) + 'X')<<48) | |
236 info_startcode | |
237 0xAB68B596BA78ULL + (((uint64_t)('N'<<8) + 'I')<<48) | |
9294 | 238 |
239 version | |
12238 | 240 2 for now |
241 | |
242 max_type0_size | |
243 max cummulative sum of type0 frames between type not 0 frames, this can | |
244 be used by the deocoder to detect damaged type 0 headers if the damage | |
245 results in a too long chain | |
246 SHOULD be set to <=16384 to ensure reasonable error recovery | |
247 | |
9294 | 248 stream_id |
249 Note: streams with a lower relative class MUST have a lower relative id | |
250 so a stream with class 0 MUST allways have a id which is lower then any | |
251 stream with class > 0 | |
12150 | 252 stream_id MUST be < stream_count |
9294 | 253 |
254 stream_class | |
255 0 video | |
256 32 audio | |
257 64 subtiles | |
258 Note the remaining values are reserved and MUST NOT be used | |
12184 | 259 a demuxer MUST ignore streams with reserved classes |
9294 | 260 |
261 fourcc | |
262 identification for the codec | |
9323 | 263 example: "H264" |
10817 | 264 MUST contain 2 or 4 bytes, note, this might be increased in the future |
265 if needed | |
266 | |
9294 | 267 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
|
268 ISO 639 and ISO 3166 for language/country code |
9325 | 269 something like "usen" (US english), can be 0 |
9294 | 270 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
|
271 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
|
272 and http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1/en_listp1.html |
9294 | 273 |
9297 | 274 time_base_nom / time_base_denom = time_base |
9294 | 275 the number of timer ticks per second, this MUST be equal to the fps |
276 if the fixed_fps is 1 | |
9297 | 277 time_base_denom MUST not be 0 |
278 time_base_nom and time_base_denom MUST be relative prime | |
12254 | 279 time_base_nom MUST be < 2^31 |
9297 | 280 examples: |
281 fps time_base_nom time_base_denom | |
282 30 30 1 | |
283 29.97 30000 1001 | |
284 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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 timestamps need fewer bits |
9294 | 291 |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
292 msb_timestamp_shift |
12261 | 293 amount of bits in lsb_timestamp |
9294 | 294 MUST be <16 |
295 | |
296 fixed_fps | |
297 1 indicates that the fps is fixed | |
298 | |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
299 index_flag |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
300 1 indicates that this file has an index |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
301 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
|
302 Note, all streams SHOULD have an index |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
303 |
9357
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
304 codec_specific_data_type |
10817 | 305 0 none/end |
9361 | 306 1 native |
307 2 bitmapinfoheader | |
308 3 waveformatex | |
309 4 imagedesc | |
310 5 sounddesc | |
9357
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
311 "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
|
312 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
|
313 |
9356 | 314 codec_specific_data |
315 private global data for a codec (could be huffman tables or ...) | |
12082 | 316 |
317 frame_code | |
318 the meaning of this byte is stored in the main header | |
319 the value 78 ('N') is forbidden to ensure that the byte is always | |
320 different from the first byte of any startcode | |
9420 | 321 |
12082 | 322 flags[frame_code] |
12261 | 323 the bits of the flags from MSB to LSB are KDTT |
324 TT is the timestamp_code | |
325 00,01,10 predicted delta timestamps | |
326 11 timestamp coded, either lsb or full timestamp | |
327 | |
328 predicted delta timestamp use the last timestamp from the | |
329 current stream + the first, second and third last unique | |
330 timestamp difference, so if the timestamp differences, where | |
331 +3,+1,+2,+2,+1 then last difference is +1, second is +2 and | |
332 third is +3 | |
333 predicted delta timestamps MUST NOT be used in type > 0 frames | |
334 or in type 0 frames if there was no full timestamp in the | |
335 current stream after the last type > 0 frame | |
336 | |
337 the least recent used delta timestamps are reset to the | |
12184 | 338 initial_timestamp_predictor values from the stream header if a |
339 packet of type not 0 in encountered | |
12261 | 340 if D is 1 then data_size_msb is coded, otherwise data_size_msb is 0 |
12238 | 341 K is the keyframe_type |
342 0-> no keyframe, | |
343 1-> keyframe, | |
12261 | 344 flags=16 can be used to mark illegal frame_code bytes |
345 frame_code=78 must have flags=16 | |
9420 | 346 |
12082 | 347 frame_type |
12238 | 348 if the first byte of a frame is 'N' then the frame_type is 2 otherwise |
349 its 0 | |
12082 | 350 there SHOULD not be more then 0.5 seconds or 16kbyte of type 0 frames |
351 wihout a intervening frame of different frame_type | |
12238 | 352 * type 2 frames MUST not depend(1) upon any other frames, this means, |
12110
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 |
12238 | 355 2 frame |
12110
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 |
12261 | 370 data_size= data_size_lsb + data_size_msb*data_size_mul; |
12082 | 371 |
12261 | 372 coded_timestamp |
373 if coded_timestamp < (1<<msb_timestamp_shift) then its a | |
374 lsb timestamp, otherwise its a full timestamp + (1<<msb_timestamp_shift) | |
375 lsb timestamps are converted to full timesamps by: | |
376 mask = (1<<msb_timestamp_shift)-1; | |
377 delta= last_timestamp - mask/2 | |
378 timestamp= ((timestamp_lsb-delta)&mask) + delta | |
379 a full timestamp must be used if the packet_type is not 0 or there is no | |
380 reference timestamp available after the last not 0 frame with the | |
381 current stream_id | |
382 | |
9294 | 383 lsb_timestamp |
12082 | 384 least significant bits of the timestamp in time_base precission |
9294 | 385 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
|
386 keyframe timestamp=0 -> timestamp=0 |
9294 | 387 frame lsb_timestamp=3 -> timestamp=3 |
388 frame lsb_timestamp=1 -> timestamp=1 | |
389 frame lsb_timestamp=2 -> timestamp=2 | |
390 ... | |
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
|
391 keyframe msb_timestamp=257 -> timestamp=257 |
12082 | 392 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
|
393 frame lsb_timestamp=0 -> timestamp=256 |
9294 | 394 frame lsb_timestamp=4 -> timestamp=260 |
395 frame lsb_timestamp=2 -> timestamp=258 | |
396 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
|
397 all timestamps of keyframes of a single stream MUST be monotone |
9294 | 398 |
399 width/height | |
400 MUST be set to the coded width/height | |
401 | |
402 sample_width/sample_height (aspect ratio) | |
403 sample_width is the horizontal distance between samples | |
404 sample_width and sample_height MUST be relative prime if not zero | |
405 MUST be 0 if unknown | |
406 | |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
407 colorspace_type |
10166 | 408 0 unknown |
409 1 ITU Rec 624 / ITU Rec 601 Y range: 16..235 Cb/Cr range: 16..240 | |
410 2 ITU Rec 709 Y range: 16..235 Cb/Cr range: 16..240 | |
411 17 ITU Rec 624 / ITU Rec 601 Y range: 0..255 Cb/Cr range: 0..255 | |
412 18 ITU Rec 709 Y range: 0..255 Cb/Cr range: 0..255 | |
413 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
414 samplerate_mul |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
415 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
|
416 samplerate = time_base*samplerate_mul |
9294 | 417 |
418 checksum | |
12118
b8fea9441d02
switching from crc32 to adler32 checksums, cuz they are faster and simpler
michael
parents:
12117
diff
changeset
|
419 adler32 checksum |
9294 | 420 |
421 index_timestamp | |
422 value in time_base precission, relative to the last index_timestamp | |
423 | |
424 index_position | |
425 position in bytes of the first byte of the keyframe header, relative | |
426 to the last index_position | |
427 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
428 id |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
429 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
|
430 0 means end |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
431 |
9323 | 432 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
|
433 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
|
434 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
|
435 Note: MUST be less than 6 byte long (might be increased to 64 later) |
9323 | 436 |
9295 | 437 name |
438 the name of the info entry, valid names are | |
10873 | 439 "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
|
440 "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
|
441 "StartTimestamp" |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
442 "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
|
443 "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
|
444 "Author" |
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
445 "Description" |
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
446 "Copyright" |
9369 | 447 "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
|
448 "Title" |
9373 | 449 "Cover" an image of the (cd,dvd,vhs,..) cover (preferable PNG or JPEG) |
9350 | 450 "Source" "DVD", "VCD", "CD", "MD", "FM radio", "VHS", "TV", |
451 "LD" | |
9373 | 452 Optional: appended PAL,NTSC,SECAM, ... in parentheses |
9350 | 453 "CaptureDevice" "BT878", "BT848", "webcam", ... (more exact names are fine too) |
454 "CreationTime" "2003-01-20 20:13:15Z", ... | |
455 (ISO 8601 format, see http://www.cl.cam.ac.uk/~mgk25/iso-time.html) | |
456 Note: dont forget the timezone | |
11975 | 457 "ReplayGain" |
9360
add934b25d6d
"X-" prefix for nonstd fields & "keywords" idea by (Andreas Hess <jaska at gmx dot net>)
michael
parents:
9357
diff
changeset
|
458 "Keywords" |
9295 | 459 Note: if someone needs some others, please tell us about them, so we can |
460 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
|
461 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
|
462 Note: MUST be less than 64 bytes long |
9295 | 463 |
464 value | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
465 value of this name/type pair |
9295 | 466 |
9310 | 467 stuffing |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
468 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
|
469 purposes |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
470 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
471 info_table[][2]={ |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
472 {NULL , NULL }, // end |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
473 {NULL , NULL }, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
474 {NULL , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
475 {NULL , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
476 {NULL , "s"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
477 {"StreamId" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
478 {"SegmentId" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
479 {"StartTimestamp" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
480 {"EndTimestamp" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
481 {"Author" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
482 {"Titel" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
483 {"Description" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
484 {"Copyright" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
485 {"Encoder" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
486 {"Keyword" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
487 {"Cover" , "JPEG"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
488 {"Cover" , "PNG"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
489 }; |
9294 | 490 |
491 Structure: | |
492 | |
493 the headers MUST be in exactly the following order (to simplify demuxer design) | |
494 main header | |
495 stream_header (id=0) | |
496 stream_header (id=1) | |
497 ... | |
498 stream_header (id=n) | |
499 | |
500 headers may be repated, but if they are then they MUST all be repeated together | |
501 and repeated headers MUST be identical | |
502 | |
503 headers MUST be repeated every 10sec at least ? FIXME | |
10817 | 504 headers MUST be repeated BEFORE keyframes |
9310 | 505 headers MUST be repeated at least twice (so they exist 3 times in a file) |
9295 | 506 |
9310 | 507 Index |
9580 | 508 the index can be repeated but there SHOULD be at least one for each stream at |
509 the end | |
9311
4b04416ada91
zero_bit for normal frames, so we can distinguish them from other packets
michael
parents:
9310
diff
changeset
|
510 Note: in case of realtime streaming there is no end, so no index there either |
9310 | 511 |
512 Info packets | |
513 the info_packet can be repeated, it can also contain different names & values | |
514 each time but only if allso the time is different | |
515 Info packets can be used to describe the file or some part of it (chapters) | |
516 | |
517 info packets, SHOULD be placed at the begin of the file at least | |
518 for realtime streaming info packets will normally be transmitted when they apply | |
519 for example, the current song title & artist of the currently shown music video | |
520 | |
521 Unknown packets | |
12184 | 522 MUST be ignored by the demuxer |
9310 | 523 |
9294 | 524 Sample code (GPL, & untested) |
525 | |
526 typedef BufferContext{ | |
527 uint8_t *buf; | |
528 uint8_t *buf_ptr; | |
529 }BufferContext; | |
530 | |
531 static inline uint64_t get_bytes(BufferContext *bc, int count){ | |
532 uint64_t val=0; | |
533 | |
534 assert(count>0 && count<9) | |
535 | |
536 for(i=0; i<count; i++){ | |
537 val <<=8; | |
538 val += *(bc->buf_ptr++); | |
539 } | |
540 | |
541 return val; | |
542 } | |
543 | |
544 static inline void put_bytes(BufferContext *bc, int count, uint64_t val){ | |
545 uint64_t val=0; | |
546 | |
547 assert(count>0 && count<9) | |
548 | |
549 for(i=count-1; i>=0; i--){ | |
550 *(bc->buf_ptr++)= val >> (8*i); | |
551 } | |
552 | |
553 return val; | |
554 } | |
555 | |
10061 | 556 static inline uint64_t get_v(BufferContext *bc){ |
9294 | 557 uint64_t val= 0; |
558 | |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
559 for(; space_left(bc) > 0; ){ |
9294 | 560 int tmp= *(bc->buf_ptr++); |
561 if(tmp&0x80) | |
562 val= (val<<7) + tmp - 0x80; | |
563 else | |
9299 | 564 return (val<<7) + tmp; |
9294 | 565 } |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
566 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
567 return -1; |
9294 | 568 } |
569 | |
10061 | 570 static inline int put_v(BufferContext *bc, uint64_t val){ |
9294 | 571 int i; |
572 | |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
573 if(space_left(bc) < 9) return -1; |
9294 | 574 |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
575 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
|
576 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
|
577 if(val>>i == 0) break; |
9294 | 578 } |
579 | |
10827 | 580 for(i-=7; i>0; i-=7){ |
9294 | 581 *(bc->buf_ptr++)= 0x80 | (val>>i); |
582 } | |
583 *(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
|
584 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
585 return 0; |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
586 } |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
587 |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
588 Authors |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
589 |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
590 Folks from MPlayer Developers Mailinglist (http://www.mplayehrq.hu/). |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
591 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
|
592 Beregszaszi, Alex (alex@fsn.hu) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
593 Bunkus, Moritz (moritz@bunkus.org) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
594 Diedrich, Tobias (td@sim.uni-hannover.de) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
595 Franz, Fabian (FabianFranz@gmx.de) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
596 Gereoffy, Arpad (arpi@thot.banki.hu) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
597 Hess, Andreas (jaska@gmx.net) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
598 Niedermayer, Michael (michaelni@gmx.at) |