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