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