147
176
tmp_reserved[i] v
149
178
for(j=0; j<count && i<256; j++, i++){
180
flags[i]= FLAG_INVALID;
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;
162
stream_startcode f(64)
173
202
codec_specific_data vb
203
if(stream_class == video){
209
}else if(stream_class == audio){
202
if(stream_id_plus1[frame_code]==0){
219
frame_flags= flags[frame_code]
220
if(frame_flags&FLAG_CODED){
222
frame_flags ^= coded_flags
224
if(frame_flags&FLAG_STREAM_ID){
205
if(pts_delta[frame_code]==0){
227
if(frame_flags&FLAG_CODED_PTS){
208
if(flags[frame_code]&1){
230
if(frame_flags&FLAG_SIZE_MSB){
233
if(frame_flags&FLAG_RESERVED)
234
reserved_count[frame_code] v
211
235
for(i=0; i<reserved_count[frame_code]; i++)
237
if(frame_flags&FLAG_CHECKSUM){
216
index_startcode f(64)
221
for(i=0; i<index_length; i++){
245
for(i=0; i<syncpoints; i++){
246
syncpoint_pos_div16 v
248
for(i=0; i<stream_count; i++){
250
for(j=0; j<syncpoints; ){
259
has_keyframe[n++][i]=flag
260
has_keyframe[n++][i]=!flag;
263
has_keyframe[n++][i]=x&1;
267
for(; j<n && j<syncpoints; j++){
268
if (!has_keyframe[j][i]) continue
273
eor_pts[j][i] = last_pts + A + B
276
keyframe_pts[j][i] = last_pts + A
228
info_frame: (optional)
232
name= info_table[id][0]
233
type= info_table[id][1]
290
for(i=0; i<count; i++){
296
}else if (value==-2){
299
}else if (value==-3){
302
}else if (value==-4){
248
info_packet: (optional)
254
syncpoint_startcode f(64)
256
stream = coded_pts % stream_count
257
global_key_pts = coded_pts/stream_count
260
318
Complete definition:
264
while(!eof && next_code != index_startcode){
323
if(next_byte == 'N'){
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;
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
345
packet_header, main_header, packet_footer
266
347
for(i=0; i<stream_count; i++){
267
if(next_packet==video_stream_header)
269
else if(next_packet==audio_stream_header)
348
packet_header, stream_header, packet_footer
274
351
while(next_code == info_startcode){
277
while(next_code != main_startcode){
278
if(next_code == syncpoint_startcode)
352
packet_header, info_packet, packet_footer
355
if(next_code == index_startcode){
356
packet_header, index_packet, packet_footer
358
if (!eof) while(next_code != main_startcode){
359
if(next_code == syncpoint_startcode){
360
packet_header, syncpoint, packet_footer
283
if (next_code == index_startcode){
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)
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.
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])
310
372
"nut/multimedia container\0"
335
393
NUT version. The current value is 2.
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)
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
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
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.
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
413
SHOULD be set to <=32768
414
if the stored value is >65536 then max_distance MUST be set to 65536
416
This is also half the max frame size without a checksum after the
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
355
430
Stream identifier
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
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
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:
490
if (convert_ts(a, a_timebase, b_timebase) < b) return -1;
491
if (convert_ts(b, b_timebase, a_timebase) < a) return 1;
399
495
amount of bits in lsb_pts
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
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
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
429
Important: depend(1) means dependency on the container level (NUT) not
430
dependency on the codec level
432
stream_id_plus1[frame_code]
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
519
flags[frame_code], frame_flags
521
1 FLAG_KEY if set, frame is keyframe
522
2 FLAG_EOR if set, stream has no relevance on
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.
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
543
stream_id[frame_code]
436
546
data_size_mul[frame_code]
439
549
data_size_lsb[frame_code]
442
552
pts_delta[frame_code]
443
must be <16384 and >-16384
553
MUST be <16384 and >-16384
555
reserved_count[frame_code]
446
559
data_size= data_size_lsb + data_size_msb*data_size_mul;
476
589
this buffer is initalized with decode_delay -1 elements
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)
482
MUST be set to the coded width/height
596
MUST be set to the coded width/height, MUST NOT be 0
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
601
both MUST be 0 if unknown otherwise both MUST be non zero
494
608
18 ITU Rec 709 Y range: 0..255 Cb/Cr range: 0..255
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
614
Generator polynomial is 0x104C11DB7. Starting value is zero.
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
625
checksum over the startcode and forward pointer
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.
637
A stream where EOR is set is to be ignored for back_ptr.
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])
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.
506
The highest pts in the stream.
509
value of the pts of a keyframe relative to the last keyframe
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
650
The highest pts in the entire file
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
658
indicates whether this stream has a keyframe between this syncpoint and
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)
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.
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
525
the ID of the type/name pair, so it is more compact
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.
681
Stream this info packet applies to. If zero, packet applies to whole
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
693
timestamp of start of chapter
696
Length of chapter in same timebase of chapter_start.
529
699
for example: "UTF8" -> string or "JPEG" -> JPEG image
700
"v" -> unsigned integer
701
"s" -> signed integer
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)
533
706
info packet types
534
707
the name of the info entry, valid names are
536
the stream(s) to which the info packet applies
541
712
the name & version of the software used for encoding
714
"Cover" (allowed types are "PNG" and "JPEG")
544
715
image of the (CD, DVD, VHS, ..) cover (preferably PNG or JPEG)
546
717
"DVD", "VCD", "CD", "MD", "FM radio", "VHS", "TV", "LD"
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
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
769
Note: this allows an implementation reading the file to locate backup
770
headers in O(log filesize) time as opposed to O(filesize)
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)
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.
631
Info frames can be used to describe the file or some part of it (chapters)
637
MUST be ignored by the demuxer
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
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
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
798
demxuxers SHOULD not search the whole file for info packets
640
800
demuxer (non-normative):
641
801
------------------------