# HG changeset patch # User diego # Date 1128596923 0 # Node ID 93d4be7ef83efd3feda37e1abb9a9e3b6ee89a5a # Parent 403cfe2d017dd2e98d9a488561c68dcd35496c91 cosmetic reformatting: tabs --> spaces, prettyprinting, trailing whitespace diff -r 403cfe2d017d -r 93d4be7ef83e DOCS/tech/mpcf.txt --- a/DOCS/tech/mpcf.txt Thu Oct 06 11:07:12 2005 +0000 +++ b/DOCS/tech/mpcf.txt Thu Oct 06 11:08:43 2005 +0000 @@ -1,579 +1,591 @@ - NUT Open Container Format DRAFT 20050909 - ---------------------------------------- - - - - Intro: - -Features / goals: - (supported by the format, not necessarily by a specific implementation) - -Simple - use the same encoding for nearly all fields - simple decoding, so slow CPUs (and embedded systems) can handle it -Extendible - no limit for the possible values of all fields (using universal vlc) - allow adding of new headers in the future - allow adding more fields at the end of headers -Compact - ~0.2% overhead, for normal bitrates - index is <10kb per hour (1 keyframe every 3sec) - a usual header for a file is about 100 bytes (audio + video headers together) - a packet header is about ~1-8 bytes -Error resistant - seeking / playback without an index - headers & index can be repeated - damaged files can be played back with minimal data loss and fast - resync times - - - Definitions: - -MUST the specific part must be done to conform to this standard -SHOULD it is recommended to be done that way, but not strictly required + NUT Open Container Format DRAFT 20050909 + ---------------------------------------- - Syntax: + Intro: + +Features / goals: + (supported by the format, not necessarily by a specific implementation) + +Simple + use the same encoding for nearly all fields + simple decoding, so slow CPUs (and embedded systems) can handle it + +Extendible + no limit for the possible values of all fields (using universal vlc) + allow adding of new headers in the future + allow adding more fields at the end of headers + +Compact + ~0.2% overhead, for normal bitrates + index is <10kb per hour (1 keyframe every 3sec) + a usual header for a file is about 100 bytes (audio + video headers together) + a packet header is about ~1-8 bytes + +Error resistant + seeking / playback without an index + headers & index can be repeated + damaged files can be played back with minimal data loss and fast + resync times + + + Definitions: + +MUST the specific part must be done to conform to this standard +SHOULD it is recommended to be done that way, but not strictly required + + + + Syntax: Since NUT heavily uses variable length fields, the simplest way to describe it is using a pseudocode approach. - Conventions: + Conventions: The data types have a name, used in the bitstream syntax description, a short text description and a pseudocode (functional) definition, optional notes may follow: -name (text description) - functional definition - [Optional notes] +name (text description) + functional definition + [Optional notes] -The bitstream syntax elements have a tagname and a functional definition, they -are presented in a bottom up approach, again optional notes may follow and +The bitstream syntax elements have a tagname and a functional definition, they +are presented in a bottom up approach, again optional notes may follow and are reproduced in the tag description: -name: (optional note) - functional definition - [Optional notes] +name: (optional note) + functional definition + [Optional notes] The in-depth tag description follows the bitstream syntax. The functional definition has a C-like syntax. - Type definitions: + Type definitions: -f(n) (n fixed bits in big-endian order) -u(n) (unsigned number encoded in n bits in MSB-first order) +f(n) (n fixed bits in big-endian order) +u(n) (unsigned number encoded in n bits in MSB-first order) + +v (variable length value, unsigned) + value=0 + do{ + more_data u(1) + data u(7) + value= 128*value + data + }while(more_data) -v (variable length value, unsigned) - value=0 - do{ - more_data u(1) - data u(7) - value= 128*value + data - }while(more_data) - -s (variable length value, signed) - temp v - temp++ - if(temp&1) value= -(temp>>1) - else value= (temp>>1) +s (variable length value, signed) + temp v + temp++ + if(temp&1) value= -(temp>>1) + else value= (temp>>1) -b (binary data or string, to be use in vb, see below) - for(i=0; i0) tmp_pts s - if(tmp_fields>1) tmp_mul v - if(tmp_fields>2) tmp_stream v - if(tmp_fields>3) tmp_size v - else tmp_size=0 - if(tmp_fields>4) tmp_res v - else tmp_res=0 - if(tmp_fields>5) count v - else count= tmp_mul - tmp_size - for(j=6; j0) tmp_pts s + if(tmp_fields>1) tmp_mul v + if(tmp_fields>2) tmp_stream v + if(tmp_fields>3) tmp_size v + else tmp_size=0 + if(tmp_fields>4) tmp_res v + else tmp_res=0 + if(tmp_fields>5) count v + else count= tmp_mul - tmp_size + for(j=6; j no keyframe, - 1-> keyframe, - flags=4 can be used to mark illegal frame_code bytes - frame_code=78 must have flags=4 - Note: frames MUST NOT depend(1) upon frames prior to the last - frame_startcode - Important: depend(1) means dependency on the container level (NUT) not - dependency on the codec level + first of the flags from MSB to LSB are called KD + if D is 1 then data_size_msb is coded, otherwise data_size_msb is 0 + K is the keyframe_type + 0 -> no keyframe, + 1 -> keyframe, + flags=4 can be used to mark illegal frame_code bytes + frame_code=78 must have flags=4 + Note: frames MUST NOT depend(1) upon frames prior to the last + frame_startcode + Important: depend(1) means dependency on the container level (NUT) not + dependency on the codec level stream_id_plus1[frame_code] - must be <250 - if it is 0, then the stream_id is coded in the frame + must be <250 + if it is 0, then the stream_id is coded in the frame data_size_mul[frame_code] - must be <16384 + must be <16384 data_size_lsb[frame_code] - must be <16384 + must be <16384 pts_delta[frame_code] - must be <16384 and >-16384 + must be <16384 and >-16384 -data_size - data_size= data_size_lsb + data_size_msb*data_size_mul; +data_size + data_size= data_size_lsb + data_size_msb*data_size_mul; coded_pts - if coded_pts < (1< pts=0 - frame lsb_pts=3 -> pts=3 - frame lsb_pts=1 -> pts=1 - frame lsb_pts=2 -> pts=2 - ... - keyframe msb_pts=257 -> pts=257 - frame lsb_pts=255->pts=255 - frame lsb_pts=0 -> pts=256 - frame lsb_pts=4 -> pts=260 - frame lsb_pts=2 -> pts=258 - frame lsb_pts=3 -> pts=259 - all pts's of keyframes of a single stream MUST be monotone + keyframe pts=0 -> pts=0 + frame lsb_pts=3 -> pts=3 + frame lsb_pts=1 -> pts=1 + frame lsb_pts=2 -> pts=2 + ... + keyframe msb_pts=257 -> pts=257 + frame lsb_pts=255 -> pts=255 + frame lsb_pts=0 -> pts=256 + frame lsb_pts=4 -> pts=260 + frame lsb_pts=2 -> pts=258 + frame lsb_pts=3 -> pts=259 + all pts's of keyframes of a single stream MUST be monotone dts - dts is calculated by using a decode_delay+1 sized buffer for each - stream, into which the current pts is inserted and the element with - the smallest value is removed, this is then the current dts - this buffer is initalized with decode_delay -1 elements - all frames must be monotone, that means a frame - which occurs later in the stream must have a larger or equal dts - than an earlier frame + dts is calculated by using a decode_delay+1 sized buffer for each + stream, into which the current pts is inserted and the element with + the smallest value is removed, this is then the current dts + this buffer is initalized with decode_delay -1 elements + all frames must be monotone, that means a frame + which occurs later in the stream must have a larger or equal dts + than an earlier frame width/height - MUST be set to the coded width/height + MUST be set to the coded width/height sample_width/sample_height (aspect ratio) - sample_width is the horizontal distance between samples - sample_width and sample_height MUST be relatively prime if not zero - MUST be 0 if unknown - + sample_width is the horizontal distance between samples + sample_width and sample_height MUST be relatively prime if not zero + MUST be 0 if unknown + colorspace_type - 0 unknown - 1 ITU Rec 624 / ITU Rec 601 Y range: 16..235 Cb/Cr range: 16..240 - 2 ITU Rec 709 Y range: 16..235 Cb/Cr range: 16..240 - 17 ITU Rec 624 / ITU Rec 601 Y range: 0..255 Cb/Cr range: 0..255 - 18 ITU Rec 709 Y range: 0..255 Cb/Cr range: 0..255 + 0 unknown + 1 ITU Rec 624 / ITU Rec 601 Y range: 16..235 Cb/Cr range: 16..240 + 2 ITU Rec 709 Y range: 16..235 Cb/Cr range: 16..240 + 17 ITU Rec 624 / ITU Rec 601 Y range: 0..255 Cb/Cr range: 0..255 + 18 ITU Rec 709 Y range: 0..255 Cb/Cr range: 0..255 samplerate_nom / samplerate_denom = samplerate - the number of samples per second + the number of samples per second checksum - adler32 checksum - checksum is calculated for the area pointed to by forward_ptr not - including the checksum itself (from first byte after the - forward_ptr until last byte before the checksum). + adler32 checksum + checksum is calculated for the area pointed to by forward_ptr not + including the checksum itself (from first byte after the + forward_ptr until last byte before the checksum). max_pts - The highest pts in the stream. + The highest pts in the stream. index_pts - value of the pts of a keyframe relative to the last keyframe - stored in this index + value of the pts of a keyframe relative to the last keyframe + stored in this index index_position - position in bytes of the first byte of a keyframe, relative to the - last keyframe stored in this index - there MUST be no keyframe with the same stream_id as this index between - two consecutive index entries if they are more than max_index_distance - apart + position in bytes of the first byte of a keyframe, relative to the + last keyframe stored in this index + there MUST be no keyframe with the same stream_id as this index between + two consecutive index entries if they are more than max_index_distance + apart index_ptr - Length in bytes from the first byte of the first index startcode - to the first byte of the index_ptr. If there is no index, index_ptr - MUST NOT be written. + Length in bytes from the first byte of the first index startcode + to the first byte of the index_ptr. If there is no index, index_ptr + MUST NOT be written. id - the ID of the type/name pair, so it is more compact - 0 means end - + the ID of the type/name pair, so it is more compact + 0 means end + type - for example: "UTF8" -> string or "JPEG" -> JPEG image - Note: nonstandard fields should be prefixed by "X-" - Note: MUST be less than 6 byte long (might be increased to 64 later) + for example: "UTF8" -> string or "JPEG" -> JPEG image + Note: nonstandard fields should be prefixed by "X-" + Note: MUST be less than 6 byte long (might be increased to 64 later) info packet types - the name of the info entry, valid names are - "StreamId" the stream(s) to which the info packet applies - - "Author" - "Description" - "Copyright" - "Encoder" the name & version of the software used for encoding - "Title" - "Cover" an image of the (CD, DVD, VHS, ..) cover (preferably PNG or JPEG) - "Source" "DVD", "VCD", "CD", "MD", "FM radio", "VHS", "TV", - "LD" - Optional: appended PAL, NTSC, SECAM, ... in parentheses - "CaptureDevice" "BT878", "BT848", "webcam", ... (more exact names are fine too) - "CreationTime" "2003-01-20 20:13:15Z", ... - (ISO 8601 format, see http://www.cl.cam.ac.uk/~mgk25/iso-time.html) - Note: do not forget the timezone - "Keywords" - "TotalTime" total length of the stream in msecs - "Language" ISO 639 and ISO 3166 for language/country code - something like "eng" (US english), can be 0 if unknown - and "multi" if several languages - see http://www.loc.gov/standards/iso639-2/englangn.html - and http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1/en_listp1.html the language code - "Disposition" "original", "dub" (translated), "comment", "lyrics", "karaoke" - Note: if someone needs some others, please tell us about them, so we can - add them to the official standard (if they are sane) - Note: nonstandard fields should be prefixed by "X-" - Note: MUST be less than 64 bytes long + the name of the info entry, valid names are + "StreamId" + the stream(s) to which the info packet applies + "Author" + "Description" + "Copyright" + "Encoder" + the name & version of the software used for encoding + "Title" + "Cover" + image of the (CD, DVD, VHS, ..) cover (preferably PNG or JPEG) + "Source" + "DVD", "VCD", "CD", "MD", "FM radio", "VHS", "TV", "LD" + Optional: appended PAL, NTSC, SECAM, ... in parentheses + "CaptureDevice" + "BT878", "BT848", "webcam", ... (more exact names are fine too) + "CreationTime" + "2003-01-20 20:13:15Z", ... + (ISO 8601 format, see http://www.cl.cam.ac.uk/~mgk25/iso-time.html) + Note: do not forget the timezone + "Keywords" + "TotalTime" + total length of the stream in msecs + "Language" + ISO 639 and ISO 3166 for language/country code + something like "eng" (US english), can be 0 if unknown + and "multi" if several languages + see http://www.loc.gov/standards/iso639-2/englangn.html + and http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1/en_listp1.html + the language code + "Disposition" + "original", "dub" (translated), "comment", "lyrics", "karaoke" + Note: if someone needs some others, please tell us about them, so we + can add them to the official standard (if they are sane) + Note: nonstandard fields should be prefixed by "X-" + Note: MUST be less than 64 bytes long value - value of this name/type pair - + value of this name/type pair + stuffing - 0x80 can be placed in front of any type v entry for stuffing purposes + 0x80 can be placed in front of any type v entry for stuffing purposes info_table[][2]={ - {NULL , NULL }, // end - {NULL , NULL }, - {NULL , "UTF8"}, - {NULL , "v"}, - {NULL , "s"}, - {"StreamId" , "v"}, - {"Author" , "UTF8"}, - {"Titel" , "UTF8"}, - {"Language" , "UTF8"}, - {"Description" , "UTF8"}, - {"Copyright" , "UTF8"}, - {"Encoder" , "UTF8"}, - {"Keyword" , "UTF8"}, - {"Cover" , "JPEG"}, - {"Cover" , "PNG"}, - {"Disposition" , "UTF8"}, + {NULL , NULL }, // end + {NULL , NULL }, + {NULL , "UTF8"}, + {NULL , "v"}, + {NULL , "s"}, + {"StreamId" , "v"}, + {"Author" , "UTF8"}, + {"Titel" , "UTF8"}, + {"Language" , "UTF8"}, + {"Description" , "UTF8"}, + {"Copyright" , "UTF8"}, + {"Encoder" , "UTF8"}, + {"Keyword" , "UTF8"}, + {"Cover" , "JPEG"}, + {"Cover" , "PNG"}, + {"Disposition" , "UTF8"}, }; - Structure: + Structure: the headers MUST be in exactly the following order (to simplify demuxer design) main header @@ -582,7 +594,7 @@ ... stream_header (id=n) -headers may be repeated, but if they are, then they MUST all be repeated +headers may be repeated, but if they are, then they MUST all be repeated together and repeated headers MUST be identical headers MAY only repeat at the closest possible positions after 2^x where x is an integer and the file end, so the headers may be repeated at 4102 if that is @@ -594,24 +606,24 @@ there MUST be a sync point immediately before the first frame after any headers - Index + Index Note: with realtime streaming, there is no end, so no index there either An index SHOULD be written for every stream. Indices MUST be placed at end of file. Indices MAY be repeated for a stream. - Info frames + Info frames Info frames can be used to describe the file or some part of it (chapters) - Unknown packets + Unknown packets MUST be ignored by the demuxer - demuxer (non-normative) + demuxer (non-normative) in the absence of a valid header at the beginning, players SHOULD search for backup headers starting at offset 2^x; for each x players SHOULD end their search at a particular offset when any startcode is found (including syncpoint) - Semantic requirements + Semantic requirements If more than one stream of a given stream class is present, each one MUST have info tags specifying disposition, and if applicable, language. @@ -621,85 +633,85 @@ duplicate the role of a container. any such file is to be considered invalid. - Sample code (Public Domain, & untested) + Sample code (Public Domain, & untested) typedef BufferContext{ - uint8_t *buf; - uint8_t *buf_ptr; + uint8_t *buf; + uint8_t *buf_ptr; }BufferContext; static inline uint64_t get_bytes(BufferContext *bc, int count){ - uint64_t val=0; + uint64_t val=0; + + assert(count>0 && count<9); - assert(count>0 && count<9); - - for(i=0; ibuf_ptr++); - } - - return val; + for(i=0; ibuf_ptr++); + } + + return val; } static inline void put_bytes(BufferContext *bc, int count, uint64_t val){ - uint64_t val=0; + uint64_t val=0; - assert(count>0 && count<9); + assert(count>0 && count<9); - for(i=count-1; i>=0; i--){ - *(bc->buf_ptr++)= val >> (8*i); - } - - return val; + for(i=count-1; i>=0; i--){ + *(bc->buf_ptr++)= val >> (8*i); + } + + return val; } static inline uint64_t get_v(BufferContext *bc){ - uint64_t val= 0; + uint64_t val= 0; - for(; space_left(bc) > 0; ){ - int tmp= *(bc->buf_ptr++); - if(tmp&0x80) - val= (val<<7) + tmp - 0x80; - else - return (val<<7) + tmp; - } - - return -1; + for(; space_left(bc) > 0; ){ + int tmp= *(bc->buf_ptr++); + if(tmp&0x80) + val= (val<<7) + tmp - 0x80; + else + return (val<<7) + tmp; + } + + return -1; } static inline int put_v(BufferContext *bc, uint64_t val){ - int i; - - if(space_left(bc) < 9) return -1; + int i; + + if(space_left(bc) < 9) return -1; - val &= 0x7FFFFFFFFFFFFFFFULL; // FIXME can only encode upto 63 bits currently - for(i=7; ; i+=7){ - if(val>>i == 0) break; - } + val &= 0x7FFFFFFFFFFFFFFFULL; // FIXME can only encode upto 63 bits currently + for(i=7; ; i+=7){ + if(val>>i == 0) break; + } - for(i-=7; i>0; i-=7){ - *(bc->buf_ptr++)= 0x80 | (val>>i); - } - *(bc->buf_ptr++)= val&0x7F; - - return 0; + for(i-=7; i>0; i-=7){ + *(bc->buf_ptr++)= 0x80 | (val>>i); + } + *(bc->buf_ptr++)= val&0x7F; + + return 0; } static int64_t get_dts(int64_t pts, int64_t *pts_cache, int delay, int reset){ - if(reset) memset(pts_cache, -1, delay*sizeof(int64_t)); + if(reset) memset(pts_cache, -1, delay*sizeof(int64_t)); - while(delay--){ - int64_t t= pts_cache[delay]; - if(t < pts){ - pts_cache[delay]= pts; - pts= t; - } - } + while(delay--){ + int64_t t= pts_cache[delay]; + if(t < pts){ + pts_cache[delay]= pts; + pts= t; + } + } - return pts; + return pts; } - Authors + Authors Folks from the MPlayer developers mailing list (http://www.mplayerhq.hu/). Authors in alphabetical order: (FIXME! Tell us if we left you out)