Mercurial > mplayer.hg
annotate DOCS/tech/mpcf.txt @ 9697:5025150738eb
10000l (YUV vs. YVU swscale fix/cleanup)
author | michael |
---|---|
date | Thu, 27 Mar 2003 16:04:53 +0000 |
parents | 88eabd7a3b3b |
children | 76b1c7d20da8 |
rev | line source |
---|---|
9347
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
1 nut format draft 0.02 |
9294 | 2 |
3 | |
4 | |
5 Intro: | |
6 | |
7 Features / goals: | |
8 (supported by the format, not necessary by a specific implementation) | |
9 | |
10 Simple | |
11 use the same encoding for nearly all fields | |
9295 | 12 simple decoding, so slow cpus can handle it |
9294 | 13 Extendible |
14 no limit for the possible values for all fields (using universal vlc) | |
15 allow adding of new headers in the future | |
16 allow adding more fields at the end of headers | |
17 Compact | |
18 ~0.2% overhead, for normal bitrates | |
19 index is <10kb per hour (1 keyframe every 3sec) | |
20 Error resistant | |
21 seeking / playback without an index | |
22 headers & index can be repeated | |
23 audio packet reshuffle | |
24 checksums to allow quick redownloading of damaged parts | |
25 | |
26 | |
27 | |
28 Definitions: | |
29 | |
30 MUST the specific part must be done to conform to this standard | |
31 SHOULD its recommanded to be done that way but its not strictly required | |
32 | |
33 | |
34 | |
35 Syntax: | |
36 | |
9295 | 37 Type definitions: |
38 v | |
39 value=0 | |
40 do{ | |
41 more_data u(1) | |
42 data u(7) | |
43 value= 128*value + data | |
44 }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
|
45 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
46 s |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
47 temp v |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
48 temp++ |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
49 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
|
50 else value= (temp>>1) |
9323 | 51 |
52 b (binary data or string) | |
53 length v | |
54 for(i=0; i<length; i++){ | |
55 data[i] u(8) | |
9295 | 56 } |
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
|
57 Note: strings MUST be encoded in utf8 |
9295 | 58 |
9323 | 59 |
9295 | 60 f(x) n fixed bits |
61 u(x) unsigned number encoded in x bits in MSB first order | |
62 | |
63 | |
64 Bitstream syntax: | |
9294 | 65 packet header |
66 forward ptr v | |
67 backward ptr v | |
68 | |
69 align_byte | |
70 while(not byte aligned) | |
71 one f(1) | |
72 | |
73 reserved_bytes | |
74 for(i=0; i<forward_ptr - length_of_non_reserved; i++) | |
75 reserved u(8) | |
76 | |
77 main header: | |
78 packet header | |
79 main_startcode f(64) | |
80 version v | |
81 stream_count v | |
82 file_size v | |
9310 | 83 length_in_msec v |
9294 | 84 reserved_bytes |
85 checksum u(32) | |
86 | |
87 stream_header: | |
88 packet_header | |
89 stream_startcode f(64) | |
90 stream_id v | |
91 stream_class v | |
9323 | 92 fourcc b |
9294 | 93 average_bitrate v |
9325 | 94 language_code b |
9297 | 95 time_base_nom v |
96 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
|
97 msb_timestamp_shift v |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
98 shuffle_type v |
9294 | 99 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
|
100 index_flag u(1) |
9356 | 101 reserved u(6) |
9357
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
102 for(;;){ |
9361 | 103 codec_specific_data_type v |
104 if(codec_specific_data_type==0) break; | |
9357
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
105 codec_specific_data b |
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
106 } |
9294 | 107 |
108 video_stream_header: | |
109 stream_header | |
110 width v | |
111 height v | |
112 sample_width v | |
113 sample_height v | |
114 colorspace_type v | |
115 depth v | |
116 reserved_bytes | |
117 checksum u(32) | |
118 | |
119 audio_stream_header: | |
120 stream_header | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
121 samplerate_mul v |
9294 | 122 channel_count v |
123 reserved_bytes | |
124 checksum u(32) | |
9420 | 125 |
9294 | 126 frame |
127 packet header | |
128 if(keyframe){ | |
129 keyframe_startcode f(64) | |
130 } | |
9311
4b04416ada91
zero_bit for normal frames, so we can distinguish them from other packets
michael
parents:
9310
diff
changeset
|
131 zero_bit f(1) |
9294 | 132 priority u(2) |
133 checksum_flag u(1) | |
134 msb_timestamp_flag u(1) | |
9420 | 135 subpacket_type u(2) |
136 reserved u(1) | |
9311
4b04416ada91
zero_bit for normal frames, so we can distinguish them from other packets
michael
parents:
9310
diff
changeset
|
137 stream_id v |
9294 | 138 if(msb_timestamp_flag) |
139 msb_timestamp v | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
140 lsb_timestamp s |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
141 if(sub_packet_type==01) |
9420 | 142 sub_packet[0] |
143 else{ | |
144 subpacket_count v | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
145 if(sub_packet_type&01) |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
146 for(i=0; ; i++) |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
147 keyframe_run[i] v |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
148 for(i=0; ; i++){ |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
149 timestamp_diff[i] v |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
150 if(timestamp_diff[i] & 1) |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
151 timestamp_diff_run[i] v |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
152 } |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
153 if(sub_packet_type&10){ |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
154 for(i=0; i<subpacket_count-1; i++) |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
155 subpacket_size_diff[i] s |
9420 | 156 } |
157 for(i=0; i<subpacket_count; i++) | |
158 subpacket[i] | |
159 } | |
160 } | |
161 if(checksum_flag) | |
9312 | 162 frame_checksum u(32) |
9294 | 163 |
164 Index: | |
165 packet header | |
166 index_startcode f(64) | |
167 stream_id v | |
168 index_length v | |
169 for(i=0; i<index_length; i++){ | |
170 index_timestamp v | |
171 index_position v | |
172 } | |
9310 | 173 reserved_bytes |
9294 | 174 checksum u(32) |
175 | |
9310 | 176 info_packet: (optional) |
9294 | 177 packet header |
178 info_startcode f(64) | |
9323 | 179 for(;;){ |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
180 id v |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
181 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
|
182 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
|
183 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
|
184 if(type==NULL) |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
185 type b |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
186 if(name==NULL) |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
187 name b |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
188 if(type=="v") |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
189 value v |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
190 else if(type=="s") |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
191 value s |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
192 else |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
193 value b |
9323 | 194 } |
9310 | 195 reserved_bytes |
9294 | 196 checksum u(32) |
9323 | 197 |
198 | |
9294 | 199 forward_ptr |
200 backward_ptr | |
201 pointer to the next / previous packet | |
9323 | 202 pointers are relative and backward pointer is implicitelly negative |
9294 | 203 Note: a frame with 0 bytes means that its skiped |
9323 | 204 Note: the forward pointer is equal to the size of this packet including |
205 the header | |
206 the backward pointer is equal to the size of the previous packet | |
207 Example: | |
208 0 | |
209 size1 (size of frame1 including header) | |
210 frame1 | |
211 | |
212 size1 | |
213 size2 | |
214 frame2 | |
215 | |
216 size2 | |
217 size3 | |
218 frame3 | |
219 | |
220 | |
221 *_startcode | |
222 the first bit is allways set | |
9294 | 223 |
224 version | |
225 0 for now | |
226 | |
227 file_size | |
228 size in bytes, can be 0 if not meaningfull (realtime streams, ...) | |
229 | |
230 length_in_msec | |
231 length of the file in milli seconds (can be 0 if realtime or such) | |
9347
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
232 |
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
233 index_flag |
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
234 1 indicates that this file has an index |
9372 | 235 Note, all files SHOULD have an index at the end except, (realtime) streams |
9580 | 236 Note, all streams SHOULD have an index |
9294 | 237 |
238 stream_id | |
239 Note: streams with a lower relative class MUST have a lower relative id | |
240 so a stream with class 0 MUST allways have a id which is lower then any | |
241 stream with class > 0 | |
9295 | 242 streams should use low ids |
9294 | 243 |
244 stream_class | |
245 0 video | |
246 32 audio | |
247 64 subtiles | |
248 Note the remaining values are reserved and MUST NOT be used | |
9312 | 249 a decoder MUST ignore streams with reserved classes |
9294 | 250 |
251 fourcc | |
252 identification for the codec | |
9323 | 253 example: "H264" |
9325 | 254 MUST contain 4 bytes, note, this might be increasd in the future if |
255 needed | |
9294 | 256 |
257 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
|
258 ISO 639 and ISO 3166 for language/country code |
9325 | 259 something like "usen" (US english), can be 0 |
9294 | 260 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
|
261 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
|
262 and http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1/en_listp1.html |
9294 | 263 |
9297 | 264 time_base_nom / time_base_denom = time_base |
9294 | 265 the number of timer ticks per second, this MUST be equal to the fps |
266 if the fixed_fps is 1 | |
9297 | 267 time_base_denom MUST not be 0 |
268 time_base_nom and time_base_denom MUST be relative prime | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
269 time_base_nom MUST be < 2^16 |
9297 | 270 examples: |
271 fps time_base_nom time_base_denom | |
272 30 30 1 | |
273 29.97 30000 1001 | |
274 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 timestamps need fewer bits |
9294 | 281 |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
282 msb_timestamp_shift |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
283 amount of bits msb_timestamp is shifted left before adding lsb_timestamp |
9294 | 284 MUST be <16 |
285 | |
286 fixed_fps | |
287 1 indicates that the fps is fixed | |
288 | |
9357
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
289 codec_specific_data_type |
9361 | 290 0 end |
291 1 native | |
292 2 bitmapinfoheader | |
293 3 waveformatex | |
294 4 imagedesc | |
295 5 sounddesc | |
9357
21347f49e8d8
supprting various codec specific/private headers for different APIs (ideas by arpi/alex/fabian)
michael
parents:
9356
diff
changeset
|
296 "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
|
297 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
|
298 |
9356 | 299 codec_specific_data |
300 private global data for a codec (could be huffman tables or ...) | |
9294 | 301 |
302 msb_timestamp_flag | |
303 indicates that the msb_timestamp is coded | |
304 MUST be 1 for keyframes | |
305 | |
9420 | 306 subpacket_type |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
307 subpacket_count subpacket_size keyframe_flag |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
308 00 >1 constant constant |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
309 01 1 NA NA |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
310 10 >1 variable constant |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
311 11 >1 variable variable |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
312 the only legal subpacket_type for video streams is 01, so video streams |
9422
5e990417accf
disallow multiple subpackets per packet for video streams idea by (me & Moritz Bunkus <moritz at bunkus dot org>)
michael
parents:
9421
diff
changeset
|
313 MUST NOT contain multiple subpackets per packet |
9420 | 314 Note, if there are multiple subpackets then the timestamp of the packet |
315 is the timestamp of the first subpacket | |
316 Note, if multiple subpackets are stored in one frame then the resulting | |
317 framesize SHOULD be < 16kbyte and not more then 0.5 sec of data SHOULD | |
318 be put in a single packet | |
319 | |
320 subpacket_count | |
321 the number of subpackets, if not pressent then 1 | |
322 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
323 keyframe_run[i] |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
324 the number of subpackets with an identical keyframe_flag |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
325 Note, the value of first flag is stored in the packet header |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
326 is equal to subpacket count if not coded |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
327 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
328 timestamp_diff[i] |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
329 the difference from the last subpacket timestamp to the current one in |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
330 time_base precission |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
331 the lowwest bit is used to indicate if timestamp_diff_run[i] is coded |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
332 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
333 timestamp_diff_run[i] |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
334 the number of subpackets which have the same timestamp_diff |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
335 if not coded than 1 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
336 0 is forbidden |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
337 |
9420 | 338 subpacket_size_diff |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
339 the difference between the predicted size of this subpacket and the |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
340 actual size |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
341 the predicted size is 64 for the first subpacket in a packet |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
342 otherwise it is MAX(64, last_subpacket_size) |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
343 the size of the last subpacket is not coded and is simply the space left |
9420 | 344 Note a subpacket MUST be in exactly one packet, it cannot be split |
345 | |
9294 | 346 msb_timestamp |
347 most significant bits of the timestamp, SHOULD be 0 for the first frame | |
348 | |
349 lsb_timestamp | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
350 difference from the msb_timestamp in time_base precission |
9294 | 351 Example: IBBP display order |
352 keyframe msb_timestamp=0 lsb_timestamp=0 -> timestamp=0 | |
353 frame lsb_timestamp=3 -> timestamp=3 | |
354 frame lsb_timestamp=1 -> timestamp=1 | |
355 frame lsb_timestamp=2 -> timestamp=2 | |
356 ... | |
357 keyframe msb_timestamp=1 lsb_timestamp=1 -> timestamp=257 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
358 frame lsb_timestamp=-1-> timestamp=255 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
359 frame lsb_timestamp=0 -> timestamp=256 |
9294 | 360 frame lsb_timestamp=4 -> timestamp=260 |
361 frame lsb_timestamp=2 -> timestamp=258 | |
362 frame lsb_timestamp=3 -> timestamp=259 | |
363 | |
364 width/height | |
365 MUST be set to the coded width/height | |
366 | |
367 sample_width/sample_height (aspect ratio) | |
368 sample_width is the horizontal distance between samples | |
369 sample_width and sample_height MUST be relative prime if not zero | |
370 MUST be 0 if unknown | |
371 | |
372 depth | |
373 for compatibility with some win32 codecs | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
374 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
375 samplerate_mul |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
376 the number of samples per second in one time_base unit |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
377 samplerate = time_base*samplerate_mul |
9294 | 378 |
9311
4b04416ada91
zero_bit for normal frames, so we can distinguish them from other packets
michael
parents:
9310
diff
changeset
|
379 zero_bit |
4b04416ada91
zero_bit for normal frames, so we can distinguish them from other packets
michael
parents:
9310
diff
changeset
|
380 MUST be 0, its there to distinguish non keyframes from other packets, |
4b04416ada91
zero_bit for normal frames, so we can distinguish them from other packets
michael
parents:
9310
diff
changeset
|
381 Note: all packets have a 64-bit startcode except non-keyframes to reduce |
4b04416ada91
zero_bit for normal frames, so we can distinguish them from other packets
michael
parents:
9310
diff
changeset
|
382 their size, and all startcodes start with a 1 bit |
4b04416ada91
zero_bit for normal frames, so we can distinguish them from other packets
michael
parents:
9310
diff
changeset
|
383 |
9294 | 384 priority |
385 if 0 then the frame isnt used as reference (b frame) and can be droped | |
386 MUST be > 0 for keyframes | |
387 | |
388 shuffle_type | |
9420 | 389 audio is often encoded in small subpackets, and to increase the |
9294 | 390 error robustness these can be shuffled |
391 0 -> no shuffle | |
392 1-16 -> interleave packets by 2^n | |
393 | |
394 checksum | |
9307
ec18ad315bbe
10l (copy & pasting the generator poly for crc32 from ogg was a bad idea...)
michael
parents:
9299
diff
changeset
|
395 crc32 checksum using the generator polynomial 0x104c11db7 (same as ogg) |
9294 | 396 |
397 checksum_flag | |
398 indicates that the frame_checksum is coded | |
399 must be 1 for the last non keyframe before a keyframe | |
400 | |
401 frame_checksum | |
402 identical to checksum, but instead of covering just the current | |
403 packet, it covers all frames of the same stream id since the last | |
9312 | 404 frame_checksum |
9294 | 405 this field is only coded if checksum_flag=1 |
406 | |
407 index_timestamp | |
408 value in time_base precission, relative to the last index_timestamp | |
409 | |
410 index_position | |
411 position in bytes of the first byte of the keyframe header, relative | |
412 to the last index_position | |
413 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
414 id |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
415 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
|
416 0 means end |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
417 |
9323 | 418 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
|
419 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
|
420 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
|
421 Note: MUST be less than 6 byte long (might be increased to 64 later) |
9323 | 422 |
9295 | 423 name |
424 the name of the info entry, valid names are | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
425 "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
|
426 "StartTimestamp" |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
427 "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
|
428 "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
|
429 "Author" |
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
430 "Description" |
97888c25ae60
changing name to "nut" for now, we can change it again if we agree on something else
michael
parents:
9335
diff
changeset
|
431 "Copyright" |
9369 | 432 "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
|
433 "Title" |
9373 | 434 "Cover" an image of the (cd,dvd,vhs,..) cover (preferable PNG or JPEG) |
9350 | 435 "Source" "DVD", "VCD", "CD", "MD", "FM radio", "VHS", "TV", |
436 "LD" | |
9373 | 437 Optional: appended PAL,NTSC,SECAM, ... in parentheses |
9350 | 438 "CaptureDevice" "BT878", "BT848", "webcam", ... (more exact names are fine too) |
439 "CreationTime" "2003-01-20 20:13:15Z", ... | |
440 (ISO 8601 format, see http://www.cl.cam.ac.uk/~mgk25/iso-time.html) | |
441 Note: dont forget the timezone | |
9360
add934b25d6d
"X-" prefix for nonstd fields & "keywords" idea by (Andreas Hess <jaska at gmx dot net>)
michael
parents:
9357
diff
changeset
|
442 "Keywords" |
9295 | 443 Note: if someone needs some others, please tell us about them, so we can |
444 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
|
445 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
|
446 Note: MUST be less than 64 bytes long |
9295 | 447 |
448 value | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
449 value of this name/type pair |
9295 | 450 |
9310 | 451 stuffing |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
452 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
|
453 purposes |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
454 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
455 info_table[][2]={ |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
456 {NULL , NULL }, // end |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
457 {NULL , NULL }, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
458 {NULL , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
459 {NULL , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
460 {NULL , "s"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
461 {"StreamId" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
462 {"SegmentId" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
463 {"StartTimestamp" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
464 {"EndTimestamp" , "v"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
465 {"Author" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
466 {"Titel" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
467 {"Description" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
468 {"Copyright" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
469 {"Encoder" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
470 {"Keyword" , "UTF8"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
471 {"Cover" , "JPEG"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
472 {"Cover" , "PNG"}, |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
473 }; |
9294 | 474 |
475 Structure: | |
476 | |
477 the headers MUST be in exactly the following order (to simplify demuxer design) | |
478 main header | |
479 stream_header (id=0) | |
480 stream_header (id=1) | |
481 ... | |
482 stream_header (id=n) | |
483 | |
484 headers may be repated, but if they are then they MUST all be repeated together | |
485 and repeated headers MUST be identical | |
486 | |
487 headers MUST be repeated every 10sec at least ? FIXME | |
9310 | 488 headers MUST be repeated at least twice (so they exist 3 times in a file) |
9295 | 489 |
9310 | 490 Index |
9580 | 491 the index can be repeated but there SHOULD be at least one for each stream at |
492 the end | |
9311
4b04416ada91
zero_bit for normal frames, so we can distinguish them from other packets
michael
parents:
9310
diff
changeset
|
493 Note: in case of realtime streaming there is no end, so no index there either |
9310 | 494 |
495 Info packets | |
496 the info_packet can be repeated, it can also contain different names & values | |
497 each time but only if allso the time is different | |
498 Info packets can be used to describe the file or some part of it (chapters) | |
499 | |
500 info packets, SHOULD be placed at the begin of the file at least | |
501 for realtime streaming info packets will normally be transmitted when they apply | |
502 for example, the current song title & artist of the currently shown music video | |
503 | |
504 Stuffing packets | |
505 can be used as a filler, for example to leave some empty space at the begin for | |
506 a copy of the index | |
507 | |
508 Unknown packets | |
509 MUST be ignored by the decoder | |
510 | |
9294 | 511 Sample code (GPL, & untested) |
512 | |
513 typedef BufferContext{ | |
514 uint8_t *buf; | |
515 uint8_t *buf_ptr; | |
516 }BufferContext; | |
517 | |
518 static inline uint64_t get_bytes(BufferContext *bc, int count){ | |
519 uint64_t val=0; | |
520 | |
521 assert(count>0 && count<9) | |
522 | |
523 for(i=0; i<count; i++){ | |
524 val <<=8; | |
525 val += *(bc->buf_ptr++); | |
526 } | |
527 | |
528 return val; | |
529 } | |
530 | |
531 static inline void put_bytes(BufferContext *bc, int count, uint64_t val){ | |
532 uint64_t val=0; | |
533 | |
534 assert(count>0 && count<9) | |
535 | |
536 for(i=count-1; i>=0; i--){ | |
537 *(bc->buf_ptr++)= val >> (8*i); | |
538 } | |
539 | |
540 return val; | |
541 } | |
542 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
543 static inline uint64_t get_v(ByteStream *bc){ |
9294 | 544 uint64_t val= 0; |
545 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
546 for(; spaceLeft(bc) > 0; ){ |
9294 | 547 int tmp= *(bc->buf_ptr++); |
548 if(tmp&0x80) | |
549 val= (val<<7) + tmp - 0x80; | |
550 else | |
9299 | 551 return (val<<7) + tmp; |
9294 | 552 } |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
553 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
554 return -1; |
9294 | 555 } |
556 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
557 static inline int put_v(ByteStream *bc, uint64_t val){ |
9294 | 558 int i; |
559 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
560 if(spaceLeft(bc) < 9) return -1; |
9294 | 561 |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
562 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
|
563 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
|
564 if(val>>i == 0) break; |
9294 | 565 } |
566 | |
9579
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
567 for(i-=7; i>0; i-=8){ |
9294 | 568 *(bc->buf_ptr++)= 0x80 | (val>>i); |
569 } | |
570 *(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
|
571 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
572 return 0; |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
573 } |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
574 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
575 static inline int put_s(ByteStream *bc, uint64_t val){ |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
576 if(val<=0) return put_v(bc, -2*val ); |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
577 else return put_v(bc, 2*val-1); |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
578 } |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
579 |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
580 static inline int64_t get_s(ByteStream *bc){ |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
581 int64_t v= get_v(bc) + 1; |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
582 if(v&1) return -(v>>1); |
89d27a306886
*signed int vlc (needs only 5 lines of code so its no increase of complexity)
michael
parents:
9422
diff
changeset
|
583 else return (v>>1); |
9294 | 584 } |
585 | |
586 | |
587 Example stream | |
588 | |
589 main header | |
590 video_stream_header (stream 0, video jpjp, timebase 30, lsb_timestamp_length=8) | |
591 video_stream_header (stream 1 subtitle usen, timebase 30, lsb_timestamp_length=8) | |
592 video_stream_header (stream 2 subtitle atde, timebase 30, lsb_timestamp_length=8) | |
593 audio_stream_header (stream 3, audio jpjp, timebase 1 , lsb_timestamp_length=8) | |
594 audio_stream_header (stream 4, audio usen, timebase 1 , lsb_timestamp_length=8) | |
595 index (stream 0) | |
596 keyframe (stream 0, msb_timestamp=0, lsb_timestamp=0) | |
597 keyframe (stream 1, msb_timestamp=0, lsb_timestamp=0) | |
598 keyframe (stream 2, msb_timestamp=0, lsb_timestamp=0) | |
599 keyframe (stream 3, msb_timestamp=0, lsb_timestamp=0) | |
600 keyframe (stream 4, msb_timestamp=0, lsb_timestamp=0) | |
601 frame (stream 0, lsb_timestamp=1) | |
602 frame (stream 0, lsb_timestamp=2) | |
603 ... | |
604 frame (stream 0, lsb_timestamp=30) | |
605 keyframe (stream 3, msb_timestamp=0, lsb_timestamp=1) | |
606 keyframe (stream 4, msb_timestamp=0, lsb_timestamp=1) | |
607 frame (stream 0, lsb_timestamp=31) | |
608 frame (stream 0, lsb_timestamp=32) | |
609 ... | |
610 frame (stream 0, lsb_timestamp=60) | |
611 frame (stream 1, lsb_timestamp=60) | |
612 frame (stream 2, lsb_timestamp=60) | |
613 keyframe (stream 3, msb_timestamp=0, lsb_timestamp=2) | |
614 keyframe (stream 4, msb_timestamp=0, lsb_timestamp=2) | |
615 frame (stream 0, lsb_timestamp=61) | |
616 frame (stream 0, lsb_timestamp=62) | |
617 ... | |
618 main header | |
619 video_stream_header (stream 0, video jpjp, timebase 30, lsb_timestamp_length=8) | |
620 video_stream_header (stream 1 subtitle usen, timebase 30, lsb_timestamp_length=8) | |
621 video_stream_header (stream 2 subtitle atde, timebase 30, lsb_timestamp_length=8) | |
622 audio_stream_header (stream 3, audio jpjp, timebase 1 , lsb_timestamp_length=8) | |
623 audio_stream_header (stream 4, audio usen, timebase 1 , lsb_timestamp_length=8) | |
624 frame (stream 0, lsb_timestamp=255) | |
625 frame (stream 0, msb_timestamp=1 lsb_timestamp=0) | |
626 frame (stream 0, lsb_timestamp=1) | |
627 frame (stream 0, lsb_timestamp=2) | |
628 frame (stream 1, msb_timestamp=1 lsb_timestamp=2) | |
629 frame (stream 2, msb_timestamp=1 lsb_timestamp=2) | |
630 frame (stream 0, lsb_timestamp=3) | |
631 frame (stream 0, lsb_timestamp=4) | |
632 ... | |
633 keyframe (stream 3, msb_timestamp=0, lsb_timestamp=9) | |
634 keyframe (stream 4, msb_timestamp=0, lsb_timestamp=9) | |
635 main header | |
636 video_stream_header (stream 0, video jpjp, timebase 30, lsb_timestamp_length=8) | |
637 video_stream_header (stream 1 subtitle usen, timebase 30, lsb_timestamp_length=8) | |
638 video_stream_header (stream 2 subtitle atde, timebase 30, lsb_timestamp_length=8) | |
639 audio_stream_header (stream 3, audio jpjp, timebase 1 , lsb_timestamp_length=8) | |
640 audio_stream_header (stream 4, audio usen, timebase 1 , lsb_timestamp_length=8) | |
641 index (stream 0) |