Mercurial > mplayer.hg
annotate DOCS/tech/mpcf.txt @ 12413:87a6dc69b65a
proposals by rich:
remove predicted delta timestamps
delta timestamp in the frame_code table
reserved vlc count in the frame_code table
global timestamp after frame_startcode
author | michael |
---|---|
date | Tue, 04 May 2004 01:29:17 +0000 |
parents | f4878bfe49c8 |
children | bfa269cec22b |
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 | |
12333 | 91 max_distance v |
12413 | 92 global_time_base_nom v |
93 global_time_base_denom v | |
94 short_startcode 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 tmp_size v |
12413 | 100 tmp_timestamp s |
101 tmp_res 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 data_size_lsb[i]= tmp_size; |
12413 | 108 timestamp_delta[i]= tmp_timestamp; |
109 reserved_v[i]= tmp_res; | |
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
|
110 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
|
111 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
|
112 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
|
113 } |
12082 | 114 } |
115 } | |
9294 | 116 reserved_bytes |
117 checksum u(32) | |
118 | |
119 stream_header: | |
10831 | 120 stream_startcode f(64) |
9294 | 121 packet_header |
122 stream_id v | |
123 stream_class v | |
12150 | 124 fourcc vb |
9294 | 125 average_bitrate v |
12150 | 126 language_code vb |
9297 | 127 time_base_nom v |
128 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
|
129 msb_timestamp_shift v |
12333 | 130 decode_delay v |
9294 | 131 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
|
132 index_flag u(1) |
9356 | 133 reserved u(6) |
9357
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
134 for(;;){ |
9361 | 135 codec_specific_data_type v |
136 if(codec_specific_data_type==0) break; | |
12117 | 137 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
|
138 } |
9294 | 139 |
140 video_stream_header: | |
141 stream_header | |
142 width v | |
143 height v | |
144 sample_width v | |
145 sample_height v | |
146 colorspace_type v | |
147 reserved_bytes | |
148 checksum u(32) | |
149 | |
150 audio_stream_header: | |
151 stream_header | |
12333 | 152 samplerate_nom v |
153 samplerate_denom v | |
9294 | 154 channel_count v |
155 reserved_bytes | |
156 checksum u(32) | |
9420 | 157 |
12082 | 158 |
9294 | 159 frame |
12082 | 160 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
|
161 if(stream_id_plus1[frame_code]==0){ |
12082 | 162 stream_id v |
163 } | |
12413 | 164 if(timestamp_delta[frame_code]==0){ |
12261 | 165 coded_timestamp v |
166 } | |
12413 | 167 if(flags[frame_code]&1){ |
12082 | 168 data_size_msb v |
169 } | |
12413 | 170 for(i=0; i<reserved_v[frame_code]; i++) |
171 reserved v | |
12082 | 172 data |
173 | |
9294 | 174 Index: |
10831 | 175 index_startcode f(64) |
9294 | 176 packet header |
177 stream_id v | |
178 index_length v | |
179 for(i=0; i<index_length; i++){ | |
180 index_timestamp v | |
181 index_position v | |
182 } | |
9310 | 183 reserved_bytes |
9294 | 184 checksum u(32) |
185 | |
9310 | 186 info_packet: (optional) |
10831 | 187 info_startcode f(64) |
9294 | 188 packet header |
9323 | 189 for(;;){ |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
190 id v |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 if(type==NULL) |
12117 | 195 type vb |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
196 if(name==NULL) |
12117 | 197 name vb |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
198 if(type=="v") |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
199 value v |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
200 else |
12117 | 201 value vb |
9323 | 202 } |
9310 | 203 reserved_bytes |
9294 | 204 checksum u(32) |
9323 | 205 |
12413 | 206 sync_point |
207 frame_startcode f(64) | |
208 global_timestamp v | |
209 | |
12242 | 210 file |
211 file_id_string | |
212 while(!eof){ | |
213 main_header | |
214 for(i=0; i<stream_count; i++){ | |
215 if(next_packet==video_stream_header) | |
216 video_stream_header | |
217 else | |
218 audio_stream_header | |
219 } | |
12413 | 220 while(next_code != main_startcode){ |
221 if(next_code == info_startcode) | |
12242 | 222 info_packet |
12368 | 223 else{ |
12413 | 224 if(next_code == short_startcode) |
225 short_startcode u(24) | |
226 else if(next_code == frame_startcode) | |
227 sync_point | |
12242 | 228 frame |
12368 | 229 } |
12242 | 230 } |
231 //FIXME index | |
232 } | |
9323 | 233 |
9294 | 234 forward_ptr |
12238 | 235 size of the packet (exactly the distance from the first byte of the |
236 startcode of the current packet to the first byte of the following packet | |
12242 | 237 |
238 file_id_string | |
239 "nut/multimedia container\0" | |
9323 | 240 |
241 *_startcode | |
12162 | 242 all startcodes start with 'N' |
243 | |
244 main_startcode | |
245 0x7A561F5F04ADULL + (((uint64_t)('N'<<8) + 'M')<<48) | |
246 stream_starcode | |
247 0x11405BF2F9DBULL + (((uint64_t)('N'<<8) + 'S')<<48) | |
12333 | 248 frame_startcode |
12162 | 249 0xE4ADEECA4569ULL + (((uint64_t)('N'<<8) + 'K')<<48) |
12392 | 250 frame_startcodes SHOULD be placed immedeatly before a keyframe if the |
251 previous frame of the same stream was a non-keyframe, unless such | |
252 non-keyframe - keyframe tansitions are very frequent | |
12365
dc05db3f172f
additional start_code rule (implemenattion does this since a long time already)
michael
parents:
12333
diff
changeset
|
253 |
12162 | 254 index_startcode |
255 0xDD672F23E64EULL + (((uint64_t)('N'<<8) + 'X')<<48) | |
256 info_startcode | |
257 0xAB68B596BA78ULL + (((uint64_t)('N'<<8) + 'I')<<48) | |
9294 | 258 |
259 version | |
12238 | 260 2 for now |
261 | |
12333 | 262 max_distance |
263 max distance of frame_startcodes, the distance may only be larger if | |
264 there is only a single frame between the 2 frame_startcodes | |
265 this can be used by the demuxer to detect damaged frame headers if the | |
266 damage results in a too long chain | |
12238 | 267 SHOULD be set to <=16384 to ensure reasonable error recovery |
268 | |
12413 | 269 short_startcode |
270 MUST be 3 bytes long and MUST have 'N' as first byte, the second byte | |
271 MUST not be a printable uppercase letter / must not be within 65..90, | |
272 default is 0x4EFE79 | |
273 | |
9294 | 274 stream_id |
275 Note: streams with a lower relative class MUST have a lower relative id | |
276 so a stream with class 0 MUST allways have a id which is lower then any | |
277 stream with class > 0 | |
12150 | 278 stream_id MUST be < stream_count |
9294 | 279 |
280 stream_class | |
281 0 video | |
282 32 audio | |
283 64 subtiles | |
284 Note the remaining values are reserved and MUST NOT be used | |
12184 | 285 a demuxer MUST ignore streams with reserved classes |
9294 | 286 |
287 fourcc | |
288 identification for the codec | |
9323 | 289 example: "H264" |
10817 | 290 MUST contain 2 or 4 bytes, note, this might be increased in the future |
291 if needed | |
292 | |
9294 | 293 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
|
294 ISO 639 and ISO 3166 for language/country code |
9325 | 295 something like "usen" (US english), can be 0 |
9294 | 296 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
|
297 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
|
298 and http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1/en_listp1.html |
9294 | 299 |
9297 | 300 time_base_nom / time_base_denom = time_base |
9294 | 301 the number of timer ticks per second, this MUST be equal to the fps |
302 if the fixed_fps is 1 | |
9297 | 303 time_base_denom MUST not be 0 |
304 time_base_nom and time_base_denom MUST be relative prime | |
12254 | 305 time_base_nom MUST be < 2^31 |
9297 | 306 examples: |
307 fps time_base_nom time_base_denom | |
308 30 30 1 | |
309 29.97 30000 1001 | |
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 timestamps need fewer bits |
9294 | 317 |
12413 | 318 global_time_base_nom / global_time_base_denom = global_time_base |
319 the number of timer ticks per second | |
320 global_time_base_denom MUST not be 0 | |
321 global_time_base_nom and global_time_base_denom MUST be relative prime | |
322 global_time_base_nom MUST be < 2^31 | |
323 | |
324 global_timestamp | |
325 timestamp in global_time_base units | |
326 when a global_timestamp is encountered the last_timestamp of all streams | |
327 is set to the following: | |
328 ln= global_time_base_denom*time_base_nom | |
329 sn= global_timestamp | |
330 d1= global_time_base_nom | |
331 d2= time_base_denom | |
332 last_timestamp= (ln/d1*sn + ln%d1*sn/d1)/d2 | |
333 Note, this calculation MUST be done with unsigned 64 bit integers, and | |
334 is equivalent to (ln*sn)/(d1*d2) but this would require a 96bit integer | |
335 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
336 msb_timestamp_shift |
12261 | 337 amount of bits in lsb_timestamp |
9294 | 338 MUST be <16 |
339 | |
12333 | 340 decode_delay |
341 maximum time between input and output for a codec, used to generate dts | |
342 from pts | |
343 is 0 for streams without b frames, and 1 for streams with b frames, may | |
344 be larger for future codecs | |
345 | |
9294 | 346 fixed_fps |
347 1 indicates that the fps is fixed | |
348 | |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
349 index_flag |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
350 1 indicates that this file has an index |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
351 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
|
352 Note, all streams SHOULD have an index |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
353 |
9357
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
354 codec_specific_data_type |
10817 | 355 0 none/end |
9361 | 356 1 native |
357 2 bitmapinfoheader | |
358 3 waveformatex | |
359 4 imagedesc | |
360 5 sounddesc | |
9357
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
361 "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
|
362 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
|
363 |
9356 | 364 codec_specific_data |
365 private global data for a codec (could be huffman tables or ...) | |
12082 | 366 |
367 frame_code | |
368 the meaning of this byte is stored in the main header | |
369 the value 78 ('N') is forbidden to ensure that the byte is always | |
370 different from the first byte of any startcode | |
9420 | 371 |
12082 | 372 flags[frame_code] |
12413 | 373 the bits of the flags from MSB to LSB are KD |
12261 | 374 if D is 1 then data_size_msb is coded, otherwise data_size_msb is 0 |
12238 | 375 K is the keyframe_type |
376 0-> no keyframe, | |
377 1-> keyframe, | |
12413 | 378 flags=4 can be used to mark illegal frame_code bytes |
379 frame_code=78 must have flags=4 | |
12333 | 380 * frames MUST not depend(1) upon frames prior to the last |
381 frame_startcode | |
12110
a34dc5a369ca
restrictions to ensure that O(log n) seeking and error recovery is possible
michael
parents:
12084
diff
changeset
|
382 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
|
383 on the codec level |
a34dc5a369ca
restrictions to ensure that O(log n) seeking and error recovery is possible
michael
parents:
12084
diff
changeset
|
384 |
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 stream_id_plus1[frame_code] |
12082 | 386 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
|
387 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
|
388 |
12082 | 389 data_size_mul[frame_code] |
12379
4100528fadf1
limits too small, my CBR mp3 samples have 2x overhead after removial of size prediction
michael
parents:
12368
diff
changeset
|
390 must be <16384 |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
391 |
12082 | 392 data_size_lsb[frame_code] |
12379
4100528fadf1
limits too small, my CBR mp3 samples have 2x overhead after removial of size prediction
michael
parents:
12368
diff
changeset
|
393 must be <16384 |
12082 | 394 |
12413 | 395 timestamp_delta[frame_code] |
396 must be <16384 and >-16384 | |
397 | |
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
|
398 data_size |
12261 | 399 data_size= data_size_lsb + data_size_msb*data_size_mul; |
12082 | 400 |
12261 | 401 coded_timestamp |
402 if coded_timestamp < (1<<msb_timestamp_shift) then its a | |
403 lsb timestamp, otherwise its a full timestamp + (1<<msb_timestamp_shift) | |
404 lsb timestamps are converted to full timesamps by: | |
405 mask = (1<<msb_timestamp_shift)-1; | |
406 delta= last_timestamp - mask/2 | |
407 timestamp= ((timestamp_lsb-delta)&mask) + delta | |
12333 | 408 a full timestamp must be used if there is no reference timestamp |
409 available after the last frame_startcode with the current stream_id | |
12261 | 410 |
9294 | 411 lsb_timestamp |
12082 | 412 least significant bits of the timestamp in time_base precission |
9294 | 413 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
|
414 keyframe timestamp=0 -> timestamp=0 |
9294 | 415 frame lsb_timestamp=3 -> timestamp=3 |
416 frame lsb_timestamp=1 -> timestamp=1 | |
417 frame lsb_timestamp=2 -> timestamp=2 | |
418 ... | |
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
|
419 keyframe msb_timestamp=257 -> timestamp=257 |
12082 | 420 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
|
421 frame lsb_timestamp=0 -> timestamp=256 |
9294 | 422 frame lsb_timestamp=4 -> timestamp=260 |
423 frame lsb_timestamp=2 -> timestamp=258 | |
424 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
|
425 all timestamps of keyframes of a single stream MUST be monotone |
9294 | 426 |
12333 | 427 dts |
428 dts are calculated by using a decode_delay+1 sized buffer for each | |
429 stream, into which the current pts is inserted and the element with | |
430 the smallest value is removed, this is then the current dts | |
431 this buffer is initalized with decode_delay -1 elements | |
432 all frames with dts == timestamp must be monotone, that means a frame | |
433 which occures later in the stream must have a larger or equal dts | |
434 then an earlier frame | |
435 FIXME rename timestamp* to pts* ? | |
436 | |
9294 | 437 width/height |
438 MUST be set to the coded width/height | |
439 | |
440 sample_width/sample_height (aspect ratio) | |
441 sample_width is the horizontal distance between samples | |
442 sample_width and sample_height MUST be relative prime if not zero | |
443 MUST be 0 if unknown | |
444 | |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
445 colorspace_type |
10166 | 446 0 unknown |
447 1 ITU Rec 624 / ITU Rec 601 Y range: 16..235 Cb/Cr range: 16..240 | |
448 2 ITU Rec 709 Y range: 16..235 Cb/Cr range: 16..240 | |
449 17 ITU Rec 624 / ITU Rec 601 Y range: 0..255 Cb/Cr range: 0..255 | |
450 18 ITU Rec 709 Y range: 0..255 Cb/Cr range: 0..255 | |
451 | |
12333 | 452 samplerate_nom / samplerate_denom = samplerate |
453 the number of samples per second | |
9294 | 454 |
455 checksum | |
12118
b8fea9441d02
switching from crc32 to adler32 checksums, cuz they are faster and simpler
michael
parents:
12117
diff
changeset
|
456 adler32 checksum |
9294 | 457 |
458 index_timestamp | |
459 value in time_base precission, relative to the last index_timestamp | |
460 | |
461 index_position | |
462 position in bytes of the first byte of the keyframe header, relative | |
463 to the last index_position | |
464 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
465 id |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
466 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
|
467 0 means end |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
468 |
9323 | 469 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
|
470 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
|
471 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
|
472 Note: MUST be less than 6 byte long (might be increased to 64 later) |
9323 | 473 |
9295 | 474 name |
475 the name of the info entry, valid names are | |
10873 | 476 "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
|
477 "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
|
478 "StartTimestamp" |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
479 "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
|
480 "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
|
481 "Author" |
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
482 "Description" |
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
483 "Copyright" |
9369 | 484 "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
|
485 "Title" |
9373 | 486 "Cover" an image of the (cd,dvd,vhs,..) cover (preferable PNG or JPEG) |
9350 | 487 "Source" "DVD", "VCD", "CD", "MD", "FM radio", "VHS", "TV", |
488 "LD" | |
9373 | 489 Optional: appended PAL,NTSC,SECAM, ... in parentheses |
9350 | 490 "CaptureDevice" "BT878", "BT848", "webcam", ... (more exact names are fine too) |
491 "CreationTime" "2003-01-20 20:13:15Z", ... | |
492 (ISO 8601 format, see http://www.cl.cam.ac.uk/~mgk25/iso-time.html) | |
493 Note: dont forget the timezone | |
11975 | 494 "ReplayGain" |
9360
add934b25d6d
"X-" prefix for nonstd fields & "keywords" idea by (Andreas Hess <jaska at gmx dot net>)
michael
parents:
9357
diff
changeset
|
495 "Keywords" |
9295 | 496 Note: if someone needs some others, please tell us about them, so we can |
497 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
|
498 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
|
499 Note: MUST be less than 64 bytes long |
9295 | 500 |
501 value | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
502 value of this name/type pair |
9295 | 503 |
9310 | 504 stuffing |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
505 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
|
506 purposes |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
507 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
508 info_table[][2]={ |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
509 {NULL , NULL }, // end |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
510 {NULL , NULL }, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
511 {NULL , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
512 {NULL , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
513 {NULL , "s"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
514 {"StreamId" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
515 {"SegmentId" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
516 {"StartTimestamp" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
517 {"EndTimestamp" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
518 {"Author" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
519 {"Titel" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
520 {"Description" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
521 {"Copyright" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
522 {"Encoder" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
523 {"Keyword" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
524 {"Cover" , "JPEG"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
525 {"Cover" , "PNG"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
526 }; |
9294 | 527 |
528 Structure: | |
529 | |
530 the headers MUST be in exactly the following order (to simplify demuxer design) | |
531 main header | |
532 stream_header (id=0) | |
533 stream_header (id=1) | |
534 ... | |
535 stream_header (id=n) | |
536 | |
537 headers may be repated, but if they are then they MUST all be repeated together | |
538 and repeated headers MUST be identical | |
539 | |
540 headers MUST be repeated every 10sec at least ? FIXME | |
10817 | 541 headers MUST be repeated BEFORE keyframes |
9310 | 542 headers MUST be repeated at least twice (so they exist 3 times in a file) |
9295 | 543 |
9310 | 544 Index |
9580 | 545 the index can be repeated but there SHOULD be at least one for each stream at |
546 the end | |
9311
4b04416ada91
zero_bit for normal frames, so we can distinguish them from other packets
michael
parents:
9310
diff
changeset
|
547 Note: in case of realtime streaming there is no end, so no index there either |
9310 | 548 |
549 Info packets | |
550 the info_packet can be repeated, it can also contain different names & values | |
551 each time but only if allso the time is different | |
552 Info packets can be used to describe the file or some part of it (chapters) | |
553 | |
554 info packets, SHOULD be placed at the begin of the file at least | |
555 for realtime streaming info packets will normally be transmitted when they apply | |
556 for example, the current song title & artist of the currently shown music video | |
557 | |
558 Unknown packets | |
12184 | 559 MUST be ignored by the demuxer |
9310 | 560 |
9294 | 561 Sample code (GPL, & untested) |
562 | |
563 typedef BufferContext{ | |
564 uint8_t *buf; | |
565 uint8_t *buf_ptr; | |
566 }BufferContext; | |
567 | |
568 static inline uint64_t get_bytes(BufferContext *bc, int count){ | |
569 uint64_t val=0; | |
570 | |
571 assert(count>0 && count<9) | |
572 | |
573 for(i=0; i<count; i++){ | |
574 val <<=8; | |
575 val += *(bc->buf_ptr++); | |
576 } | |
577 | |
578 return val; | |
579 } | |
580 | |
581 static inline void put_bytes(BufferContext *bc, int count, uint64_t val){ | |
582 uint64_t val=0; | |
583 | |
584 assert(count>0 && count<9) | |
585 | |
586 for(i=count-1; i>=0; i--){ | |
587 *(bc->buf_ptr++)= val >> (8*i); | |
588 } | |
589 | |
590 return val; | |
591 } | |
592 | |
10061 | 593 static inline uint64_t get_v(BufferContext *bc){ |
9294 | 594 uint64_t val= 0; |
595 | |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
596 for(; space_left(bc) > 0; ){ |
9294 | 597 int tmp= *(bc->buf_ptr++); |
598 if(tmp&0x80) | |
599 val= (val<<7) + tmp - 0x80; | |
600 else | |
9299 | 601 return (val<<7) + tmp; |
9294 | 602 } |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
603 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
604 return -1; |
9294 | 605 } |
606 | |
10061 | 607 static inline int put_v(BufferContext *bc, uint64_t val){ |
9294 | 608 int i; |
609 | |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
610 if(space_left(bc) < 9) return -1; |
9294 | 611 |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
612 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
|
613 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
|
614 if(val>>i == 0) break; |
9294 | 615 } |
616 | |
10827 | 617 for(i-=7; i>0; i-=7){ |
9294 | 618 *(bc->buf_ptr++)= 0x80 | (val>>i); |
619 } | |
620 *(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
|
621 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
622 return 0; |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
623 } |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
624 |
12333 | 625 static int64_t get_dts(int64_t pts, int64_t *pts_cache, int delay, int reset){ |
626 if(reset) memset(pts_cache, -1, delay*sizeof(int64_t)); | |
627 | |
628 while(delay--){ | |
629 int64_t t= pts_cache[delay]; | |
630 if(t < pts){ | |
631 pts_cache[delay]= pts; | |
632 pts= t; | |
633 } | |
634 } | |
635 | |
636 return pts; | |
637 } | |
638 | |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
639 Authors |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
640 |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
641 Folks from MPlayer Developers Mailinglist (http://www.mplayehrq.hu/). |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
642 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
|
643 Beregszaszi, Alex (alex@fsn.hu) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
644 Bunkus, Moritz (moritz@bunkus.org) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
645 Diedrich, Tobias (td@sim.uni-hannover.de) |
12297 | 646 Felker, Rich (dalias@aerifal.cx) |
10158
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
647 Franz, Fabian (FabianFranz@gmx.de) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
648 Gereoffy, Arpad (arpi@thot.banki.hu) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
649 Hess, Andreas (jaska@gmx.net) |
93e5428d0b3e
some changes (michael: is the colorspace_type field needed?)
alex
parents:
10061
diff
changeset
|
650 Niedermayer, Michael (michaelni@gmx.at) |