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