~ubuntu-dev/mplayer/ubuntu-feisty

« back to all changes in this revision

Viewing changes to DOCS/tech/mpcf.txt

  • Committer: Reinhard Tartler
  • Date: 2006-07-08 08:47:54 UTC
  • Revision ID: siretart@tauware.de-20060708084754-c3ff228cc9c2d8de
upgrade to pre8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
========================================
2
 
NUT Open Container Format DRAFT 20060105
 
2
NUT Open Container Format DRAFT 20060322
3
3
========================================
4
4
 
5
5
 
21
21
 
22
22
Compact
23
23
    ~0.2% overhead, for normal bitrates
24
 
    index is <10kb per hour (1 keyframe every 3sec)
 
24
    index is <100kb per hour
25
25
    a usual header for a file is about 100 bytes (audio + video headers together)
26
26
    a packet header is about ~1-5 bytes
27
27
 
98
98
        data[i]                         u(8)
99
99
    }
100
100
    [Note: strings MUST be encoded in UTF-8]
 
101
    [Note: the character NUL (U+0000) is not legal within
 
102
    or at the end of a string.]
101
103
 
102
104
vb  (variable length binary data or string)
103
105
    length                              v
104
106
    value                               b
105
107
 
 
108
t (v coded universal timestamp)
 
109
    tmp                                 v
 
110
    id= tmp % time_base_count
 
111
    value= (tmp / time_base_count) * time_base[id]
106
112
 
107
113
 
108
114
Bitstream syntax:
111
117
Common elements:
112
118
----------------
113
119
 
114
 
packet header:
115
 
    forward ptr                         v
116
 
 
117
120
reserved_bytes:
118
121
    for(i=0; i<forward_ptr - length_of_non_reserved; i++)
119
122
        reserved                        u(8)
122
125
    impossible to add new fields at the end of packets in the future
123
126
    in a compatible way]
124
127
 
 
128
packet_header
 
129
    startcode                           f(64)
 
130
    forward_ptr                         v
 
131
    if(forward_ptr > 4096)
 
132
        header_checksum                 u(32)
 
133
 
 
134
packet_footer
 
135
    reserved_bytes
 
136
    checksum                            u(32)
 
137
    [Note: in index packet, reserved_bytes comes before index_ptr]
 
138
 
 
139
reserved_headers
 
140
    while(next_byte == 'N' && next_code !=      main_startcode
 
141
                           && next_code !=    stream_startcode
 
142
                           && next_code !=      info_startcode
 
143
                           && next_code !=     index_startcode
 
144
                           && next_code != syncpoint_startcode){
 
145
        packet_header
 
146
        packet_footer
 
147
    }
 
148
 
125
149
        Headers:
126
150
 
127
151
main header:
128
 
    main_startcode                      f(64)
129
 
    packet header
130
152
    version                             v
131
153
    stream_count                        v
132
154
    max_distance                        v
133
 
    max_index_distance                  v
 
155
    time_base_count                     v
 
156
    for(i=0; i<time_base_count; i++)
 
157
        time_base_nom                   v
 
158
        time_base_denom                 v
 
159
        time_base[i]= time_base_nom/time_base_denom
 
160
    tmp_pts=0
 
161
    tmp_mul=1
 
162
    tmp_stream=0
134
163
    for(i=0; i<256; ){
135
164
        tmp_flag                        v
136
165
        tmp_fields                      v
147
176
            tmp_reserved[i]             v
148
177
        }
149
178
        for(j=0; j<count && i<256; j++, i++){
 
179
            if (i == 'N') {
 
180
                flags[i]= FLAG_INVALID;
 
181
                j--;
 
182
                continue;
 
183
            }
150
184
            flags[i]= tmp_flag;
151
 
            stream_id_plus1[i]= tmp_stream;
 
185
            stream_id[i]= tmp_stream;
152
186
            data_size_mul[i]= tmp_mul;
153
187
            data_size_lsb[i]= tmp_size + j;
154
188
            pts_delta[i]= tmp_pts;
155
189
            reserved_count[i]= tmp_res;
156
190
        }
157
191
    }
158
 
    reserved_bytes
159
 
    checksum                            u(32)
160
192
 
161
193
stream_header:
162
 
    stream_startcode                    f(64)
163
 
    packet_header
164
194
    stream_id                           v
165
195
    stream_class                        v
166
196
    fourcc                              vb
167
 
    time_base_nom                       v
168
 
    time_base_denom                     v
 
197
    time_base_id                        v
169
198
    msb_pts_shift                       v
 
199
    max_pts_distance                    v
170
200
    decode_delay                        v
171
 
    fixed_fps                           u(1)
172
 
    reserved                            u(7)
 
201
    stream_flags                        v
173
202
    codec_specific_data                 vb
174
 
 
175
 
video_stream_header:
176
 
    stream_header
177
 
    width                               v
178
 
    height                              v
179
 
    sample_width                        v
180
 
    sample_height                       v
181
 
    colorspace_type                     v
182
 
    reserved_bytes
183
 
    checksum                            u(32)
184
 
 
185
 
audio_stream_header:
186
 
    stream_header
187
 
    samplerate_nom                      v
188
 
    samplerate_denom                    v
189
 
    channel_count                       v
190
 
    reserved_bytes
191
 
    checksum                            u(32)
192
 
 
193
 
other_stream_header:
194
 
    stream_header
195
 
    reserved_bytes
196
 
    checksum                            u(32)
 
203
    if(stream_class == video){
 
204
        width                           v
 
205
        height                          v
 
206
        sample_width                    v
 
207
        sample_height                   v
 
208
        colorspace_type                 v
 
209
    }else if(stream_class == audio){
 
210
        samplerate_nom                  v
 
211
        samplerate_denom                v
 
212
        channel_count                   v
 
213
    }
197
214
 
198
215
        Basic Packets:
199
216
 
200
217
frame:
201
218
    frame_code                          f(8)
202
 
    if(stream_id_plus1[frame_code]==0){
 
219
    frame_flags= flags[frame_code]
 
220
    if(frame_flags&FLAG_CODED){
 
221
        coded_flags                     v
 
222
        frame_flags ^= coded_flags
 
223
    }
 
224
    if(frame_flags&FLAG_STREAM_ID){
203
225
        stream_id                       v
204
226
    }
205
 
    if(pts_delta[frame_code]==0){
 
227
    if(frame_flags&FLAG_CODED_PTS){
206
228
        coded_pts                       v
207
229
    }
208
 
    if(flags[frame_code]&1){
 
230
    if(frame_flags&FLAG_SIZE_MSB){
209
231
        data_size_msb                   v
210
232
    }
 
233
    if(frame_flags&FLAG_RESERVED)
 
234
        reserved_count[frame_code]      v
211
235
    for(i=0; i<reserved_count[frame_code]; i++)
212
236
        reserved                        v
 
237
    if(frame_flags&FLAG_CHECKSUM){
 
238
        checksum                        u(32)
 
239
    }
213
240
    data
214
241
 
215
242
index:
216
 
    index_startcode                     f(64)
217
 
    packet header
218
 
    stream_id                           v
219
 
    max_pts                             v
220
 
    index_length                        v
221
 
    for(i=0; i<index_length; i++){
222
 
        index_pts                       v
223
 
        index_position                  v
 
243
    max_pts                             t
 
244
    syncpoints                          v
 
245
    for(i=0; i<syncpoints; i++){
 
246
        syncpoint_pos_div16             v
 
247
    }
 
248
    for(i=0; i<stream_count; i++){
 
249
        last_pts= -1
 
250
        for(j=0; j<syncpoints; ){
 
251
            x                           v
 
252
            type= x & 1
 
253
            x>>=1
 
254
            n=j
 
255
            if(type){
 
256
                flag= x & 1
 
257
                x>>=1
 
258
                while(x--)
 
259
                    has_keyframe[n++][i]=flag
 
260
                has_keyframe[n++][i]=!flag;
 
261
            }else{
 
262
                while(x != 1){
 
263
                    has_keyframe[n++][i]=x&1;
 
264
                    x>>=1;
 
265
                }
 
266
            }
 
267
            for(; j<n && j<syncpoints; j++){
 
268
                if (!has_keyframe[j][i]) continue
 
269
                A                           v
 
270
                if(!A){
 
271
                    A                       v
 
272
                    B                       v
 
273
                    eor_pts[j][i] = last_pts + A + B
 
274
                }else
 
275
                    B=0
 
276
                keyframe_pts[j][i] = last_pts + A
 
277
                last_pts += A + B
 
278
            }
 
279
        }
224
280
    }
225
281
    reserved_bytes
226
 
    checksum                            u(32)
 
282
    index_ptr                           u(64)
227
283
 
228
 
info_frame: (optional)
229
 
    for(;;){
230
 
        id                              v
231
 
        if(id==0) break
232
 
        name= info_table[id][0]
233
 
        type= info_table[id][1]
234
 
        if(type==NULL)
 
284
info_packet:
 
285
    stream_id_plus1                     v
 
286
    chapter_id                          v
 
287
    chapter_start                       t
 
288
    chapter_len                         v
 
289
    count                               v
 
290
    for(i=0; i<count; i++){
 
291
        name                            vb
 
292
        value                           s
 
293
        if (value==-1){
 
294
            type= "UTF-8"
 
295
            value                       vb
 
296
        }else if (value==-2){
235
297
            type                        vb
236
 
        if(name==NULL)
237
 
            name                        vb
238
 
        if(type=="v")
239
 
            value                       v
240
 
        else if(type=="s")
 
298
            value                       vb
 
299
        }else if (value==-3){
 
300
            type= "s"
241
301
            value                       s
242
 
        else
243
 
            value                       vb
 
302
        }else if (value==-4){
 
303
            type= "t"
 
304
            value                       t
 
305
        }else if (value<-4){
 
306
            type= "r"
 
307
            value.den= -value-4
 
308
            value.num                   s
 
309
        }else{
 
310
            type= "v"
 
311
        }
244
312
    }
245
 
    reserved_bytes
246
 
        checksum                        u(32)
247
 
 
248
 
info_packet: (optional)
249
 
    info_startcode                      f(64)
250
 
    packet header
251
 
    info_frame
252
313
 
253
314
syncpoint:
254
 
    syncpoint_startcode                 f(64)
255
 
    coded_pts                           v
256
 
    stream = coded_pts % stream_count
257
 
    global_key_pts = coded_pts/stream_count
258
 
    back_ptr                            v
 
315
    global_key_pts                      t
 
316
    back_ptr_div16                      v
259
317
 
260
318
            Complete definition:
261
319
 
262
320
file:
263
321
    file_id_string
264
 
    while(!eof && next_code != index_startcode){
265
 
        main_header
 
322
    while(!eof){
 
323
        if(next_byte == 'N'){
 
324
            packet_header
 
325
            switch(startcode){
 
326
                case      main_startcode:  main_header; break;
 
327
                case    stream_startcode:stream_header; break;
 
328
                case      info_startcode:  info_packet; break;
 
329
                case     index_startcode:        index; break;
 
330
                case syncpoint_startcode:    syncpoint; break;
 
331
            }
 
332
            packet_footer
 
333
        }else
 
334
            frame
 
335
    }
 
336
 
 
337
the structure of a undamaged file should look like the following, but
 
338
demuxers should be flexible and be able to deal with damaged headers so the
 
339
above is a better loop in practice (not to mention its simpler)
 
340
note, demuxers MUST be able to deal with new and unknown headers
 
341
 
 
342
file:
 
343
    file_id_string
 
344
    while(!eof){
 
345
        packet_header, main_header, packet_footer
 
346
        reserved_headers
266
347
        for(i=0; i<stream_count; i++){
267
 
            if(next_packet==video_stream_header)
268
 
                video_stream_header
269
 
            else if(next_packet==audio_stream_header)
270
 
                audio_stream_header
271
 
            else
272
 
                other_stream_header
 
348
            packet_header, stream_header, packet_footer
 
349
            reserved_headers
273
350
        }
274
351
        while(next_code == info_startcode){
275
 
            info_packet
276
 
        }
277
 
        while(next_code != main_startcode){
278
 
            if(next_code == syncpoint_startcode)
279
 
                syncpoint
 
352
            packet_header, info_packet, packet_footer
 
353
            reserved_headers
 
354
        }
 
355
        if(next_code == index_startcode){
 
356
            packet_header, index_packet, packet_footer
 
357
        }
 
358
        if (!eof) while(next_code != main_startcode){
 
359
            if(next_code == syncpoint_startcode){
 
360
                packet_header, syncpoint, packet_footer
 
361
            }
280
362
            frame
281
 
        }
282
 
    }
283
 
    if (next_code == index_startcode){
284
 
        while(!eof){
285
 
            index
286
 
        }
287
 
        index_ptr                       u(64)
 
363
            reserved_headers
 
364
        }
288
365
    }
289
366
 
290
367
 
291
368
Tag description:
292
369
----------------
293
370
 
294
 
forward_ptr
295
 
    size of the packet data (exactly the distance from the first byte
296
 
    after the forward_ptr to the first byte of the next packet)
297
 
 
298
 
back_ptr
299
 
    real_back_ptr = back_ptr * 8 + 7
300
 
    real_back_ptr must point to a position such that a syncpoint
301
 
    startcode begins within the next 8 bytes, and such that at least
302
 
    one keyframe for each stream lies between the syncpoint to which
303
 
    real_back_ptr points, and the current syncpoint.
304
 
 
305
 
global_key_pts
306
 
    After a syncpoint, last_pts of each stream is to be set to:
307
 
    last_pts[i] = convert_ts(global_key_pts, timebase[stream], timebase[i])
308
 
 
309
371
file_id_string
310
372
    "nut/multimedia container\0"
311
373
 
321
383
syncpoint_startcode
322
384
    0xE4ADEECA4569ULL + (((uint64_t)('N'<<8) + 'K')<<48)
323
385
 
324
 
    syncpoint_startcodes SHOULD be placed immediately before a keyframe if the
325
 
    previous frame of the same stream was a non-keyframe, unless such
326
 
    non-keyframe - keyframe transitions are very frequent
327
 
 
328
386
index_startcode
329
387
    0xDD672F23E64EULL + (((uint64_t)('N'<<8) + 'X')<<48)
330
388
 
334
392
version
335
393
    NUT version. The current value is 2.
336
394
 
 
395
forward_ptr
 
396
    size of the packet data (exactly the distance from the first byte
 
397
    after the packet_header to the first byte of the next packet)
 
398
 
337
399
max_distance
338
 
    max distance of syncpoints, the distance may only be larger if
339
 
    there is no more than a single frame between the two syncpoints. This can
340
 
    be used by the demuxer to detect damaged frame headers if the damage
341
 
    results in too long of a chain
342
 
 
343
 
    SHOULD be set to <=32768 or at least <=65536 unless there is a very
344
 
    good reason to set it higher, otherwise reasonable error recovery will
345
 
    be impossible
346
 
 
347
 
max_index_distance
348
 
    max distance of keyframes which are represented in the index, the
349
 
    distance between consecutive entries A and B may only be larger if
350
 
    there are no keyframes within this stream between A and B
351
 
    SHOULD be set to <=32768 or at least <=65536 unless there is a very
352
 
    good reason to set it higher
 
400
    max distance between startcodes. If p1 and p2 are the byte
 
401
    positions of the first byte of two consecutive startcodes, then
 
402
    p2-p1 MUST be less than or equal to max_distance unless the entire
 
403
    span from p1 to p2 comprises a single packet or a syncpoint
 
404
    followed by a single frame. This imposition places efficient upper
 
405
    bounds on seek operations and allows for the detection of damaged
 
406
    frame headers, should a chain of frame headers pass max_distance
 
407
    without encountering any startcode.
 
408
 
 
409
    syncpoints SHOULD be placed immediately before a keyframe if the
 
410
    previous frame of the same stream was a non-keyframe, unless such
 
411
    non-keyframe - keyframe transitions are very frequent
 
412
 
 
413
    SHOULD be set to <=32768
 
414
    if the stored value is >65536 then max_distance MUST be set to 65536
 
415
 
 
416
    This is also half the max frame size without a checksum after the
 
417
    frameheader.
 
418
 
 
419
 
 
420
max_pts_distance
 
421
    max absoloute difference of pts of new frame from last_pts in the
 
422
    timebase of the stream, without a checksum after the frameheader.
 
423
    A frame header MUST include a checksum if abs(pts-last_pts) is
 
424
    strictly greater than max_pts_distance.
 
425
    Note that last_pts is not necessarily the pts of the last frame
 
426
    on the same stream, as it is altered by syncpoint timestamps.
 
427
    SHOULD NOT be higher than 1/timebase
353
428
 
354
429
stream_id
355
430
    Stream identifier
359
434
    0    video
360
435
    1    audio
361
436
    2    subtiles
362
 
    3    metadata
363
 
    4    userdata
364
 
    in metadata streams each frame contains exactly one info frame
 
437
    3    userdata
365
438
    Note: the remaining values are reserved and MUST NOT be used
366
439
          a demuxer MUST ignore streams with reserved classes
367
440
 
373
446
 
374
447
time_base_nom / time_base_denom = time_base
375
448
    the length of a timer tick in seconds, this MUST be equal to the 1/fps
376
 
    if fixed_fps is 1
 
449
    if FLAG_FIXED_FPS is set
377
450
    time_base_nom and time_base_denom MUST NOT be 0
378
451
    time_base_nom and time_base_denom MUST be relatively prime
379
452
    time_base_denom MUST be < 2^31
382
455
        30        1                30
383
456
        29.97     1001             30000
384
457
        23.976    1001             24000
 
458
    There MUST NOT be 2 identical timebases in a file.
 
459
    There SHOULD NOT be more timebases than streams.
 
460
 
 
461
time_base_id
 
462
    id to time_base table
385
463
 
386
464
convert_ts
387
465
    To switch from 2 different timebases, the following calculation is
395
473
    Note: this calculation MUST be done with unsigned 64 bit integers, and
396
474
    is equivalent to (ln*sn)/(d1*d2) but this would require a 96bit integer
397
475
 
 
476
compare_ts
 
477
    Compares timestamps from 2 different timebases,
 
478
    if a is before b then compare_ts(a, b) = -1
 
479
    if a is after  b then compare_ts(a, b) =  1
 
480
    else                  compare_ts(a, b) =  0
 
481
 
 
482
    Care must be taken that this is done exactly with no rounding errors,
 
483
    simply casting to float or double and doing the obvious
 
484
    a*timebase > b*timebase is not compliant or correct, neither is the
 
485
    same with integers, and
 
486
    a*a_timebase.num*b_timebase.den > b*b_timebase.num*a_timebase.den
 
487
    will overflow. One possible implementation which shouldn't overflow
 
488
    within the range of legal timestamps and timebases is:
 
489
 
 
490
    if (convert_ts(a, a_timebase, b_timebase) < b) return -1;
 
491
    if (convert_ts(b, b_timebase, a_timebase) < a) return  1;
 
492
    return 0;
 
493
 
398
494
msb_pts_shift
399
495
    amount of bits in lsb_pts
400
496
    MUST be <16
404
500
    dts from pts
405
501
    is set to 0 for streams without B-frames, and set to 1 for streams with
406
502
    B-frames, may be larger for future codecs
 
503
    decode_delay MUST NOT be set higher than necessary for a codec.
407
504
 
408
 
fixed_fps
409
 
    1 indicates that the fps is fixed
 
505
stream_flags
 
506
     Bit  Name            Description
 
507
       1  FLAG_FIXED_FPS  indicates that the fps is fixed
410
508
 
411
509
codec_specific_data
412
510
    private global data for a codec (could be huffman tables or ...)
415
513
    the meaning of this byte is stored in the main header
416
514
    the value 78 ('N') is forbidden to ensure that the byte is always
417
515
    different from the first byte of any startcode
418
 
 
419
 
flags[frame_code]
420
 
    first of the flags from MSB to LSB are called KD
421
 
    if D is 1 then data_size_msb is coded, otherwise data_size_msb is 0
422
 
    K is the keyframe_type
423
 
        0 -> no keyframe,
424
 
        1 -> keyframe,
425
 
    flags=4 can be used to mark illegal frame_code bytes
426
 
    frame_code=78 must have flags=4
427
 
    Note: frames MUST NOT depend(1) upon frames prior to the last
428
 
          frame_startcode
429
 
    Important: depend(1) means dependency on the container level (NUT) not
430
 
    dependency on the codec level
431
 
 
432
 
stream_id_plus1[frame_code]
433
 
    must be <250
434
 
    if it is 0, then the stream_id is coded in the frame
 
516
    a muxer SHOULD mark 0x00 and 0xFF as invalid to improve error
 
517
    detection
 
518
 
 
519
flags[frame_code], frame_flags
 
520
     Bit  Name             Description
 
521
       1  FLAG_KEY         if set, frame is keyframe
 
522
       2  FLAG_EOR         if set, stream has no relevance on
 
523
                           presentation. (EOR)
 
524
       8  FLAG_CODED_PTS   if set, coded_pts is in the frame header
 
525
      16  FLAG_STREAM_ID   if set, stream_id is coded in the frame header
 
526
      32  FLAG_SIZE_MSB    if set, data_size_msb is at frame header,
 
527
                           otherwise data_size_msb is 0
 
528
      64  FLAG_CHECKSUM    if set then the frame header contains a checksum
 
529
     128  FLAG_RESERVED    if set, reserved_count is coded in the frame header
 
530
    4096  FLAG_CODED       if set, coded_flags are stored in the frame header.
 
531
    8192  FLAG_INVALID     if set, frame_code is invalid.
 
532
 
 
533
    EOR frames MUST be zero-length and must be set keyframe.
 
534
    All streams SHOULD end with EOR, where the pts of the EOR indicates the
 
535
    end presentation time of the final frame.
 
536
    An EOR set stream is unset by the first content frames.
 
537
    EOR can only be unset in streams with zero decode_delay .
 
538
    FLAG_CHECKSUM MUST be set if the frame's data_size is strictly greater than
 
539
    2*max_distance or the difference abs(pts-last_pts) is strictly greater than
 
540
    max_pts_distance (where pts represents this frame's pts and last_pts is
 
541
    defined as below).
 
542
 
 
543
stream_id[frame_code]
 
544
    MUST be <250
435
545
 
436
546
data_size_mul[frame_code]
437
 
    must be <16384
 
547
    MUST be <16384
438
548
 
439
549
data_size_lsb[frame_code]
440
 
    must be <16384
 
550
    MUST be <16384
441
551
 
442
552
pts_delta[frame_code]
443
 
    must be <16384 and >-16384
 
553
    MUST be <16384 and >-16384
 
554
 
 
555
reserved_count[frame_code]
 
556
    MUST be <256
444
557
 
445
558
data_size
446
559
    data_size= data_size_lsb + data_size_msb*data_size_mul;
476
589
    this buffer is initalized with decode_delay -1 elements
477
590
 
478
591
    Pts of all frames in all streams MUST be bigger or equal to dts of all
479
 
    previous frames in all streams, compared in common timebase.
 
592
    previous frames in all streams, compared in common timebase. (EOR
 
593
    frames are NOT exempt from this rule)
480
594
 
481
595
width/height
482
 
    MUST be set to the coded width/height
 
596
    MUST be set to the coded width/height, MUST NOT be 0
483
597
 
484
598
sample_width/sample_height (aspect ratio)
485
599
    sample_width is the horizontal distance between samples
486
600
    sample_width and sample_height MUST be relatively prime if not zero
487
 
    MUST be 0 if unknown
 
601
    both MUST be 0 if unknown otherwise both MUST be non zero
488
602
 
489
603
colorspace_type
490
604
     0    unknown
494
608
    18    ITU Rec 709               Y range:  0..255 Cb/Cr range:  0..255
495
609
 
496
610
samplerate_nom / samplerate_denom = samplerate
497
 
    the number of samples per second
 
611
    the number of samples per second, MUST NOT be 0
 
612
 
 
613
crc32 checksum
 
614
    Generator polynomial is 0x104C11DB7. Starting value is zero.
498
615
 
499
616
checksum
500
 
    adler32 checksum
 
617
    crc32 checksum
501
618
    checksum is calculated for the area pointed to by forward_ptr not
502
619
    including the checksum itself (from first byte after the
503
 
    forward_ptr until last byte before the checksum).
 
620
    packet_header until last byte before the checksum).
 
621
    for frame headers the checksum contains the framecode byte and all
 
622
    following bytes upto the checksum itself
 
623
 
 
624
header_checksum
 
625
    checksum over the startcode and forward pointer
 
626
 
 
627
Syncpoint tags:
 
628
---------------
 
629
 
 
630
back_ptr_div16
 
631
    back_ptr = back_ptr_div16 * 16 + 15
 
632
    back_ptr must point to a position within 16 bytes of a syncpoint
 
633
    startcode. This syncpoint MUST be the closest syncpoint such that at
 
634
    least one keyframe with a pts lower or equal to the original syncpoint's
 
635
    global_key_pts for all streams lies between it and the current syncpoint.
 
636
 
 
637
    A stream where EOR is set is to be ignored for back_ptr.
 
638
 
 
639
global_key_pts
 
640
    After a syncpoint, last_pts of each stream is to be set to:
 
641
    last_pts[i] = convert_ts(global_key_pts, time_base[id], time_base[i])
 
642
 
 
643
    global_key_pts MUST be bigger or equal to dts of all past frames across
 
644
    all streams, and smaller or equal to pts of all future frames.
 
645
 
 
646
Index tags:
 
647
-----------
504
648
 
505
649
max_pts
506
 
    The highest pts in the stream.
507
 
 
508
 
index_pts
509
 
    value of the pts of a keyframe relative to the last keyframe
510
 
    stored in this index
511
 
 
512
 
index_position
513
 
    position in bytes of the first byte of a keyframe, relative to the
514
 
    last keyframe stored in this index
515
 
    there MUST be no keyframe with the same stream_id as this index between
516
 
    two consecutive index entries if they are more than max_index_distance
517
 
    apart
 
650
    The highest pts in the entire file
 
651
 
 
652
syncpoint_pos_div16
 
653
    offset from begginning of file to up to 15 bytes before the syncpoint
 
654
    referred to in this index entry. Relative to position of last
 
655
    syncpoint.
 
656
 
 
657
has_keyframe
 
658
    indicates whether this stream has a keyframe between this syncpoint and
 
659
    the last syncpoint.
 
660
 
 
661
keyframe_pts
 
662
    The pts of the first keyframe for this stream in the region between the
 
663
    2 syncpoints, in the stream's timebase. (EOR frames are also keyframes)
 
664
 
 
665
eor_pts
 
666
    Coded only if EOR is set at the position of the syncpoint. The pts of
 
667
    that EOR. EOR is unset by the first keyframe after it.
518
668
 
519
669
index_ptr
520
 
    Length in bytes from the first byte of the first index startcode
521
 
    to the first byte of the index_ptr. If there is no index, index_ptr
522
 
    MUST NOT be written.
523
 
 
524
 
id
525
 
    the ID of the type/name pair, so it is more compact
526
 
    0 means end
 
670
    Length in bytes of the entire index, from the first byte of the
 
671
    startcode until the last byte of the checksum.
 
672
    Note: A demuxer can use this to find the index when it is written at
 
673
    EOF, as index_ptr will always be 12 bytes before the end of file if
 
674
    there is an index at all.
 
675
 
 
676
 
 
677
Info tags:
 
678
----------
 
679
 
 
680
stream_id_plus1
 
681
    Stream this info packet applies to. If zero, packet applies to whole
 
682
    file.
 
683
 
 
684
chapter_id
 
685
    Id of chapter this packet applies to. If zero, packet applies to whole
 
686
    file. Positive chapter_id's are real chapters and MUST NOT overlap.
 
687
    Negative chapter_id indicate a sub region of file and not a real
 
688
    chapter. chapter_id MUST be unique to the region it represents.
 
689
    chapter_id n MUST not be used unless there are at least n chapters in the
 
690
    file
 
691
 
 
692
chapter_start
 
693
    timestamp of start of chapter
 
694
 
 
695
chapter_len
 
696
    Length of chapter in same timebase of chapter_start.
527
697
 
528
698
type
529
699
    for example: "UTF8" -> string or "JPEG" -> JPEG image
 
700
    "v" -> unsigned integer
 
701
    "s" -> signed integer
 
702
    "r" -> rational
530
703
    Note: nonstandard fields should be prefixed by "X-"
531
704
    Note: MUST be less than 6 byte long (might be increased to 64 later)
532
705
 
533
706
info packet types
534
707
    the name of the info entry, valid names are
535
 
    "StreamId"
536
 
        the stream(s) to which the info packet applies
537
708
    "Author"
538
709
    "Description"
539
710
    "Copyright"
540
711
    "Encoder"
541
712
        the name & version of the software used for encoding
542
713
    "Title"
543
 
    "Cover"
 
714
    "Cover" (allowed types are "PNG" and "JPEG")
544
715
        image of the (CD, DVD, VHS, ..) cover (preferably PNG or JPEG)
545
716
    "Source"
546
717
        "DVD", "VCD", "CD", "MD", "FM radio", "VHS", "TV", "LD"
552
723
        (ISO 8601 format, see http://www.cl.cam.ac.uk/~mgk25/iso-time.html)
553
724
        Note: do not forget the timezone
554
725
    "Keywords"
555
 
    "TotalTime"
556
 
        total length of the stream in msecs
557
726
    "Language"
558
727
        ISO 639 and ISO 3166 for language/country code
559
728
        something like "eng" (US english), can be 0 if unknown
566
735
        Note: if someone needs some others, please tell us about them, so we
567
736
              can add them to the official standard (if they are sane)
568
737
        Note: nonstandard fields should be prefixed by "X-"
 
738
        Note: names of fields SHOULD be in English if a word with the same
 
739
              meaning exists in English
569
740
        Note: MUST be less than 64 bytes long
570
741
 
571
742
value
573
744
 
574
745
stuffing
575
746
    0x80 can be placed in front of any type v entry for stuffing purposes
576
 
 
577
 
info_table[][2]={
578
 
    {NULL            ,  NULL }, // end
579
 
    {NULL            ,  NULL },
580
 
    {NULL            , "UTF8"},
581
 
    {NULL            , "v"},
582
 
    {NULL            , "s"},
583
 
    {"StreamId"      , "v"},
584
 
    {"Author"        , "UTF8"},
585
 
    {"Title"         , "UTF8"},
586
 
    {"Language"      , "UTF8"},
587
 
    {"Description"   , "UTF8"},
588
 
    {"Copyright"     , "UTF8"},
589
 
    {"Encoder"       , "UTF8"},
590
 
    {"Keyword"       , "UTF8"},
591
 
    {"Cover"         , "JPEG"},
592
 
    {"Cover"         , "PNG"},
593
 
    {"Disposition"   , "UTF8"},
594
 
};
 
747
    except the forward_ptr and all fields in the frame header where a
 
748
    maximum of 8 stuffing bytes per field are allowed
595
749
 
596
750
 
597
751
Structure:
606
760
 
607
761
headers may be repeated, but if they are, then they MUST all be repeated
608
762
together and repeated headers MUST be identical
609
 
headers MAY only repeat at the closest possible positions after 2^x where x is
 
763
 
 
764
Each set of repeated headers not at the beginning or end of the file SHOULD
 
765
be stored at the earliest possible position after 2^x where x is
610
766
an integer and the file end, so the headers may be repeated at 4102 if that is
611
767
the closest position after 2^12=4096 at which the headers can be placed
612
768
 
 
769
Note: this allows an implementation reading the file to locate backup
 
770
headers in O(log filesize) time as opposed to O(filesize)
 
771
 
613
772
headers MUST be placed at least at the start of the file and immediately before
614
773
the index or at the file end if there is no index
615
774
headers MUST be repeated at least twice (so they exist three times in a file)
621
780
------
622
781
 
623
782
Note: with realtime streaming, there is no end, so no index there either
624
 
An index SHOULD be written for every stream. Indices MUST be placed at end
625
 
of file. Indices MAY be repeated for a stream.
626
 
 
627
 
 
628
 
Info frames:
629
 
------------
630
 
 
631
 
Info frames can be used to describe the file or some part of it (chapters)
632
 
 
633
 
 
634
 
Unknown packets:
635
 
----------------
636
 
 
637
 
MUST be ignored by the demuxer
638
 
 
 
783
Index MAY only be repeated after main headers.
 
784
If an index is written anywhere in the file, it MUST be written at end of
 
785
file as well.
 
786
 
 
787
 
 
788
Info:
 
789
-----
 
790
 
 
791
If a info packet is stored anywhere then a muxer MUST also store an identical
 
792
info packet after every main-stream-header set
 
793
 
 
794
If a demuxer has seen several info packets with the same chapter_id and
 
795
stream_id then it MUST ignore all but the one with the highest position in
 
796
the file
 
797
 
 
798
demxuxers SHOULD not search the whole file for info packets
639
799
 
640
800
demuxer (non-normative):
641
801
------------------------
656
816
A demuxer MUST NOT demux a stream which contains more than one stream, or which
657
817
is wrapped in a structure to facilitate more than one stream or otherwise
658
818
duplicate the role of a container. any such file is to be considered invalid.
 
819
for example vorbis in ogg in nut is invalid, as is 
 
820
mpegvideo+mpegaudio in mpeg-ps/ts in nut or dvvideo + dvaudio in dv in nut
659
821
 
660
822
 
661
823