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