2004-04-09 17:05:00 +00:00
|
|
|
NUT Open Container Format DRAFT 20040409
|
2003-09-05 18:45:12 +00:00
|
|
|
----------------------------------------
|
2003-02-06 15:33:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Intro:
|
|
|
|
|
|
|
|
Features / goals:
|
|
|
|
(supported by the format, not necessary by a specific implementation)
|
|
|
|
|
|
|
|
Simple
|
|
|
|
use the same encoding for nearly all fields
|
2003-05-23 12:17:36 +00:00
|
|
|
simple decoding, so slow cpus (and embedded systems) can handle it
|
2003-02-06 15:33:02 +00:00
|
|
|
Extendible
|
|
|
|
no limit for the possible values for 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)
|
2003-09-07 01:15:01 +00:00
|
|
|
a usual header for a file is about 100bytes (audio + video headers together)
|
2004-03-30 01:05:51 +00:00
|
|
|
a packet header is about ~1-8 bytes
|
2003-02-06 15:33:02 +00:00
|
|
|
Error resistant
|
|
|
|
seeking / playback without an index
|
|
|
|
headers & index can be repeated
|
2003-05-23 12:17:36 +00:00
|
|
|
damaged files can be played back with minimal data lost and fast
|
|
|
|
resyncing times
|
2003-02-06 15:33:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Definitions:
|
|
|
|
|
|
|
|
MUST the specific part must be done to conform to this standard
|
|
|
|
SHOULD its recommanded to be done that way but its not strictly required
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Syntax:
|
|
|
|
|
2003-02-06 17:19:09 +00:00
|
|
|
Type definitions:
|
2004-04-14 23:11:45 +00:00
|
|
|
|
|
|
|
f(x) n fixed bits in big endian order
|
|
|
|
u(x) unsigned number encoded in x bits in MSB first order
|
|
|
|
|
2003-02-06 17:19:09 +00:00
|
|
|
v
|
|
|
|
value=0
|
|
|
|
do{
|
|
|
|
more_data u(1)
|
|
|
|
data u(7)
|
|
|
|
value= 128*value + data
|
|
|
|
}while(more_data)
|
2003-03-13 15:32:48 +00:00
|
|
|
|
|
|
|
s
|
|
|
|
temp v
|
|
|
|
temp++
|
|
|
|
if(temp&1) value= -(temp>>1)
|
|
|
|
else value= (temp>>1)
|
2003-02-07 21:35:39 +00:00
|
|
|
|
|
|
|
b (binary data or string)
|
|
|
|
for(i=0; i<length; i++){
|
|
|
|
data[i] u(8)
|
2003-02-06 17:19:09 +00:00
|
|
|
}
|
2003-02-08 09:07:13 +00:00
|
|
|
Note: strings MUST be encoded in utf8
|
2003-02-06 17:19:09 +00:00
|
|
|
|
2004-04-04 22:40:48 +00:00
|
|
|
vb
|
|
|
|
length v
|
|
|
|
value b
|
|
|
|
|
2003-02-06 17:19:09 +00:00
|
|
|
|
|
|
|
Bitstream syntax:
|
2003-02-06 15:33:02 +00:00
|
|
|
packet header
|
2004-03-30 01:05:51 +00:00
|
|
|
forward ptr v
|
2003-02-06 15:33:02 +00:00
|
|
|
|
|
|
|
align_byte
|
|
|
|
while(not byte aligned)
|
|
|
|
one f(1)
|
|
|
|
|
|
|
|
reserved_bytes
|
|
|
|
for(i=0; i<forward_ptr - length_of_non_reserved; i++)
|
|
|
|
reserved u(8)
|
2004-04-13 00:49:47 +00:00
|
|
|
a demuxer MUST ignore any reserved bytes
|
|
|
|
a muxer MUST NOT write any reserved bytes, as this would make it
|
2003-09-06 13:21:08 +00:00
|
|
|
inpossible to add new fields at the end of packets in the future in
|
|
|
|
a compatible way
|
|
|
|
|
2003-02-06 15:33:02 +00:00
|
|
|
main header:
|
|
|
|
main_startcode f(64)
|
2003-09-07 01:15:01 +00:00
|
|
|
packet header
|
2003-02-06 15:33:02 +00:00
|
|
|
version v
|
|
|
|
stream_count v
|
2004-04-28 03:19:35 +00:00
|
|
|
max_distance v
|
2004-05-04 01:29:17 +00:00
|
|
|
global_time_base_nom v
|
|
|
|
global_time_base_denom v
|
|
|
|
short_startcode v
|
2004-03-31 01:44:57 +00:00
|
|
|
for(i=0; i<256; ){
|
|
|
|
tmp_flag v
|
2004-05-05 17:26:24 +00:00
|
|
|
tmp_fields v
|
|
|
|
if(tmp_fields>0) tmp_timestamp 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<tmp_fields; j++){
|
|
|
|
tmp_reserved[i] v
|
|
|
|
}
|
|
|
|
for(j=0; j<count && i<256; j++, i++){
|
2004-03-31 01:44:57 +00:00
|
|
|
flags[i]= tmp_flag;
|
|
|
|
stream_id_plus1[i]= tmp_stream;
|
|
|
|
data_size_mul[i]= tmp_mul;
|
2004-05-05 17:26:24 +00:00
|
|
|
data_size_lsb[i]= tmp_size + j;
|
2004-05-04 01:29:17 +00:00
|
|
|
timestamp_delta[i]= tmp_timestamp;
|
|
|
|
reserved_v[i]= tmp_res;
|
2004-03-30 01:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-06 15:33:02 +00:00
|
|
|
reserved_bytes
|
|
|
|
checksum u(32)
|
|
|
|
|
|
|
|
stream_header:
|
|
|
|
stream_startcode f(64)
|
2003-09-07 01:15:01 +00:00
|
|
|
packet_header
|
2003-02-06 15:33:02 +00:00
|
|
|
stream_id v
|
|
|
|
stream_class v
|
2004-04-07 13:00:33 +00:00
|
|
|
fourcc vb
|
2003-02-06 15:33:02 +00:00
|
|
|
average_bitrate v
|
2004-04-07 13:00:33 +00:00
|
|
|
language_code vb
|
2003-02-06 18:03:11 +00:00
|
|
|
time_base_nom v
|
|
|
|
time_base_denom v
|
2003-03-13 15:32:48 +00:00
|
|
|
msb_timestamp_shift v
|
2004-04-28 03:19:35 +00:00
|
|
|
decode_delay v
|
2003-02-06 15:33:02 +00:00
|
|
|
fixed_fps u(1)
|
2003-02-08 18:50:18 +00:00
|
|
|
index_flag u(1)
|
2003-02-09 00:11:18 +00:00
|
|
|
reserved u(6)
|
2003-02-09 01:29:21 +00:00
|
|
|
for(;;){
|
2003-02-09 10:58:23 +00:00
|
|
|
codec_specific_data_type v
|
|
|
|
if(codec_specific_data_type==0) break;
|
2004-04-04 22:40:48 +00:00
|
|
|
codec_specific_data vb
|
2003-02-09 01:29:21 +00:00
|
|
|
}
|
2003-02-06 15:33:02 +00:00
|
|
|
|
|
|
|
video_stream_header:
|
|
|
|
stream_header
|
|
|
|
width v
|
|
|
|
height v
|
|
|
|
sample_width v
|
|
|
|
sample_height v
|
|
|
|
colorspace_type v
|
|
|
|
reserved_bytes
|
|
|
|
checksum u(32)
|
|
|
|
|
|
|
|
audio_stream_header:
|
|
|
|
stream_header
|
2004-04-28 03:19:35 +00:00
|
|
|
samplerate_nom v
|
|
|
|
samplerate_denom v
|
2003-02-06 15:33:02 +00:00
|
|
|
channel_count v
|
|
|
|
reserved_bytes
|
|
|
|
checksum u(32)
|
2003-02-14 11:11:11 +00:00
|
|
|
|
2004-03-30 01:05:51 +00:00
|
|
|
|
2003-02-06 15:33:02 +00:00
|
|
|
frame
|
2004-03-30 01:05:51 +00:00
|
|
|
frame_code f(8)
|
2004-03-31 01:44:57 +00:00
|
|
|
if(stream_id_plus1[frame_code]==0){
|
2004-03-30 01:05:51 +00:00
|
|
|
stream_id v
|
|
|
|
}
|
2004-05-04 01:29:17 +00:00
|
|
|
if(timestamp_delta[frame_code]==0){
|
2004-04-23 15:48:17 +00:00
|
|
|
coded_timestamp v
|
2004-03-30 01:05:51 +00:00
|
|
|
}
|
2004-05-04 01:29:17 +00:00
|
|
|
if(flags[frame_code]&1){
|
2004-03-30 01:05:51 +00:00
|
|
|
data_size_msb v
|
|
|
|
}
|
2004-05-04 01:29:17 +00:00
|
|
|
for(i=0; i<reserved_v[frame_code]; i++)
|
|
|
|
reserved v
|
2004-03-30 01:05:51 +00:00
|
|
|
data
|
|
|
|
|
2003-02-06 15:33:02 +00:00
|
|
|
Index:
|
|
|
|
index_startcode f(64)
|
2003-09-07 01:15:01 +00:00
|
|
|
packet header
|
2003-02-06 15:33:02 +00:00
|
|
|
stream_id v
|
|
|
|
index_length v
|
|
|
|
for(i=0; i<index_length; i++){
|
|
|
|
index_timestamp v
|
|
|
|
index_position v
|
|
|
|
}
|
2003-02-07 09:48:06 +00:00
|
|
|
reserved_bytes
|
2003-02-06 15:33:02 +00:00
|
|
|
checksum u(32)
|
|
|
|
|
2003-02-07 09:48:06 +00:00
|
|
|
info_packet: (optional)
|
2003-02-06 15:33:02 +00:00
|
|
|
info_startcode f(64)
|
2003-09-07 01:15:01 +00:00
|
|
|
packet header
|
2003-02-07 21:35:39 +00:00
|
|
|
for(;;){
|
2003-03-13 15:32:48 +00:00
|
|
|
id v
|
|
|
|
if(id==0) break
|
|
|
|
name= info_table[id][0]
|
|
|
|
type= info_table[id][1]
|
|
|
|
if(type==NULL)
|
2004-04-04 22:40:48 +00:00
|
|
|
type vb
|
2003-03-13 15:32:48 +00:00
|
|
|
if(name==NULL)
|
2004-04-04 22:40:48 +00:00
|
|
|
name vb
|
2003-03-13 15:32:48 +00:00
|
|
|
if(type=="v")
|
|
|
|
value v
|
|
|
|
else
|
2004-04-04 22:40:48 +00:00
|
|
|
value vb
|
2003-02-07 21:35:39 +00:00
|
|
|
}
|
2003-02-07 09:48:06 +00:00
|
|
|
reserved_bytes
|
2003-02-06 15:33:02 +00:00
|
|
|
checksum u(32)
|
2003-02-07 21:35:39 +00:00
|
|
|
|
2004-05-04 01:29:17 +00:00
|
|
|
sync_point
|
|
|
|
frame_startcode f(64)
|
|
|
|
global_timestamp v
|
|
|
|
|
2004-04-20 23:00:28 +00:00
|
|
|
file
|
|
|
|
file_id_string
|
|
|
|
while(!eof){
|
|
|
|
main_header
|
|
|
|
for(i=0; i<stream_count; i++){
|
|
|
|
if(next_packet==video_stream_header)
|
|
|
|
video_stream_header
|
|
|
|
else
|
|
|
|
audio_stream_header
|
|
|
|
}
|
2004-05-04 01:29:17 +00:00
|
|
|
while(next_code != main_startcode){
|
|
|
|
if(next_code == info_startcode)
|
2004-04-20 23:00:28 +00:00
|
|
|
info_packet
|
2004-05-01 11:28:34 +00:00
|
|
|
else{
|
2004-05-04 01:29:17 +00:00
|
|
|
if(next_code == short_startcode)
|
|
|
|
short_startcode u(24)
|
|
|
|
else if(next_code == frame_startcode)
|
|
|
|
sync_point
|
2004-04-20 23:00:28 +00:00
|
|
|
frame
|
2004-05-01 11:28:34 +00:00
|
|
|
}
|
2004-04-20 23:00:28 +00:00
|
|
|
}
|
|
|
|
//FIXME index
|
|
|
|
}
|
2003-02-07 21:35:39 +00:00
|
|
|
|
2003-02-06 15:33:02 +00:00
|
|
|
forward_ptr
|
2004-04-20 17:58:24 +00:00
|
|
|
size of the packet (exactly the distance from the first byte of the
|
|
|
|
startcode of the current packet to the first byte of the following packet
|
2004-04-20 23:00:28 +00:00
|
|
|
|
|
|
|
file_id_string
|
|
|
|
"nut/multimedia container\0"
|
2003-02-07 21:35:39 +00:00
|
|
|
|
|
|
|
*_startcode
|
2004-04-09 18:40:48 +00:00
|
|
|
all startcodes start with 'N'
|
|
|
|
|
|
|
|
main_startcode
|
|
|
|
0x7A561F5F04ADULL + (((uint64_t)('N'<<8) + 'M')<<48)
|
|
|
|
stream_starcode
|
|
|
|
0x11405BF2F9DBULL + (((uint64_t)('N'<<8) + 'S')<<48)
|
2004-04-28 03:19:35 +00:00
|
|
|
frame_startcode
|
2004-04-09 18:40:48 +00:00
|
|
|
0xE4ADEECA4569ULL + (((uint64_t)('N'<<8) + 'K')<<48)
|
2004-05-02 01:37:49 +00:00
|
|
|
frame_startcodes SHOULD be placed immedeatly before a keyframe if the
|
|
|
|
previous frame of the same stream was a non-keyframe, unless such
|
|
|
|
non-keyframe - keyframe tansitions are very frequent
|
2004-04-30 22:53:59 +00:00
|
|
|
|
2004-04-09 18:40:48 +00:00
|
|
|
index_startcode
|
|
|
|
0xDD672F23E64EULL + (((uint64_t)('N'<<8) + 'X')<<48)
|
|
|
|
info_startcode
|
|
|
|
0xAB68B596BA78ULL + (((uint64_t)('N'<<8) + 'I')<<48)
|
2003-02-06 15:33:02 +00:00
|
|
|
|
|
|
|
version
|
2004-04-20 17:58:24 +00:00
|
|
|
2 for now
|
|
|
|
|
2004-04-28 03:19:35 +00:00
|
|
|
max_distance
|
|
|
|
max distance of frame_startcodes, the distance may only be larger if
|
|
|
|
there is only a single frame between the 2 frame_startcodes
|
|
|
|
this can be used by the demuxer to detect damaged frame headers if the
|
|
|
|
damage results in a too long chain
|
2004-04-20 17:58:24 +00:00
|
|
|
SHOULD be set to <=16384 to ensure reasonable error recovery
|
|
|
|
|
2004-05-04 01:29:17 +00:00
|
|
|
short_startcode
|
|
|
|
MUST be 3 bytes long and MUST have 'N' as first byte, the second byte
|
|
|
|
MUST not be a printable uppercase letter / must not be within 65..90,
|
|
|
|
default is 0x4EFE79
|
|
|
|
|
2003-02-06 15:33:02 +00:00
|
|
|
stream_id
|
|
|
|
Note: streams with a lower relative class MUST have a lower relative id
|
|
|
|
so a stream with class 0 MUST allways have a id which is lower then any
|
|
|
|
stream with class > 0
|
2004-04-07 13:00:33 +00:00
|
|
|
stream_id MUST be < stream_count
|
2003-02-06 15:33:02 +00:00
|
|
|
|
|
|
|
stream_class
|
|
|
|
0 video
|
|
|
|
32 audio
|
|
|
|
64 subtiles
|
|
|
|
Note the remaining values are reserved and MUST NOT be used
|
2004-04-13 00:49:47 +00:00
|
|
|
a demuxer MUST ignore streams with reserved classes
|
2003-02-06 15:33:02 +00:00
|
|
|
|
|
|
|
fourcc
|
|
|
|
identification for the codec
|
2003-02-07 21:35:39 +00:00
|
|
|
example: "H264"
|
2003-09-05 18:45:12 +00:00
|
|
|
MUST contain 2 or 4 bytes, note, this might be increased in the future
|
|
|
|
if needed
|
|
|
|
|
2003-02-06 15:33:02 +00:00
|
|
|
language_code
|
2003-02-08 09:07:13 +00:00
|
|
|
ISO 639 and ISO 3166 for language/country code
|
2003-02-07 22:13:54 +00:00
|
|
|
something like "usen" (US english), can be 0
|
2003-02-06 15:33:02 +00:00
|
|
|
if unknown
|
2003-02-08 09:07:13 +00:00
|
|
|
see http://www.loc.gov/standards/iso639-2/englangn.html
|
|
|
|
and http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1/en_listp1.html
|
2003-02-06 15:33:02 +00:00
|
|
|
|
2003-02-06 18:03:11 +00:00
|
|
|
time_base_nom / time_base_denom = time_base
|
2003-02-06 15:33:02 +00:00
|
|
|
the number of timer ticks per second, this MUST be equal to the fps
|
|
|
|
if the fixed_fps is 1
|
2003-02-06 18:03:11 +00:00
|
|
|
time_base_denom MUST not be 0
|
|
|
|
time_base_nom and time_base_denom MUST be relative prime
|
2004-04-22 15:00:30 +00:00
|
|
|
time_base_nom MUST be < 2^31
|
2003-02-06 18:03:11 +00:00
|
|
|
examples:
|
|
|
|
fps time_base_nom time_base_denom
|
|
|
|
30 30 1
|
|
|
|
29.97 30000 1001
|
|
|
|
23.976 24000 1001
|
2003-03-13 15:32:48 +00:00
|
|
|
sample_rate sample_rate_mul time_base_nom time_base_denom
|
|
|
|
44100 1 44100 1
|
|
|
|
44100 64 11025 16
|
|
|
|
48000 1024 375 8
|
|
|
|
Note: the advantage to using a large sample_rate_mul is that the
|
|
|
|
timestamps need fewer bits
|
|
|
|
|
2004-05-04 01:29:17 +00:00
|
|
|
global_time_base_nom / global_time_base_denom = global_time_base
|
|
|
|
the number of timer ticks per second
|
|
|
|
global_time_base_denom MUST not be 0
|
|
|
|
global_time_base_nom and global_time_base_denom MUST be relative prime
|
|
|
|
global_time_base_nom MUST be < 2^31
|
|
|
|
|
|
|
|
global_timestamp
|
|
|
|
timestamp in global_time_base units
|
|
|
|
when a global_timestamp is encountered the last_timestamp of all streams
|
|
|
|
is set to the following:
|
|
|
|
ln= global_time_base_denom*time_base_nom
|
|
|
|
sn= global_timestamp
|
|
|
|
d1= global_time_base_nom
|
|
|
|
d2= time_base_denom
|
|
|
|
last_timestamp= (ln/d1*sn + ln%d1*sn/d1)/d2
|
|
|
|
Note, this calculation MUST be done with unsigned 64 bit integers, and
|
|
|
|
is equivalent to (ln*sn)/(d1*d2) but this would require a 96bit integer
|
|
|
|
|
2003-03-13 15:32:48 +00:00
|
|
|
msb_timestamp_shift
|
2004-04-23 15:48:17 +00:00
|
|
|
amount of bits in lsb_timestamp
|
2003-02-06 15:33:02 +00:00
|
|
|
MUST be <16
|
|
|
|
|
2004-04-28 03:19:35 +00:00
|
|
|
decode_delay
|
|
|
|
maximum time between input and output for a codec, used to generate dts
|
|
|
|
from pts
|
|
|
|
is 0 for streams without b frames, and 1 for streams with b frames, may
|
|
|
|
be larger for future codecs
|
|
|
|
|
2003-02-06 15:33:02 +00:00
|
|
|
fixed_fps
|
|
|
|
1 indicates that the fps is fixed
|
|
|
|
|
2003-05-23 12:17:36 +00:00
|
|
|
index_flag
|
|
|
|
1 indicates that this file has an index
|
|
|
|
Note, all files SHOULD have an index at the end except, (realtime) streams
|
|
|
|
Note, all streams SHOULD have an index
|
|
|
|
|
2003-02-09 01:29:21 +00:00
|
|
|
codec_specific_data_type
|
2003-09-05 18:45:12 +00:00
|
|
|
0 none/end
|
2003-02-09 10:58:23 +00:00
|
|
|
1 native
|
|
|
|
2 bitmapinfoheader
|
|
|
|
3 waveformatex
|
|
|
|
4 imagedesc
|
|
|
|
5 sounddesc
|
2003-02-09 01:29:21 +00:00
|
|
|
"native", means a simple api & container independanet storage form,
|
|
|
|
for example some mpeg4-es headers
|
|
|
|
|
2003-02-09 00:11:18 +00:00
|
|
|
codec_specific_data
|
|
|
|
private global data for a codec (could be huffman tables or ...)
|
2004-03-30 01:05:51 +00:00
|
|
|
|
|
|
|
frame_code
|
|
|
|
the meaning of this byte is stored in the main header
|
|
|
|
the value 78 ('N') is forbidden to ensure that the byte is always
|
|
|
|
different from the first byte of any startcode
|
|
|
|
|
|
|
|
flags[frame_code]
|
2004-05-04 01:29:17 +00:00
|
|
|
the bits of the flags from MSB to LSB are KD
|
2004-04-23 15:48:17 +00:00
|
|
|
if D is 1 then data_size_msb is coded, otherwise data_size_msb is 0
|
2004-04-20 17:58:24 +00:00
|
|
|
K is the keyframe_type
|
|
|
|
0-> no keyframe,
|
|
|
|
1-> keyframe,
|
2004-05-04 01:29:17 +00:00
|
|
|
flags=4 can be used to mark illegal frame_code bytes
|
|
|
|
frame_code=78 must have flags=4
|
2004-04-28 03:19:35 +00:00
|
|
|
* frames MUST not depend(1) upon frames prior to the last
|
|
|
|
frame_startcode
|
2004-04-03 13:23:44 +00:00
|
|
|
depend(1) means dependancy on the container level (NUT) not dependancy
|
|
|
|
on the codec level
|
|
|
|
|
2004-03-31 01:44:57 +00:00
|
|
|
stream_id_plus1[frame_code]
|
2004-03-30 01:05:51 +00:00
|
|
|
must be <250
|
2004-03-31 01:44:57 +00:00
|
|
|
if its 0 then the stream_id is coded in the frame
|
2004-03-30 01:05:51 +00:00
|
|
|
|
|
|
|
data_size_mul[frame_code]
|
2004-05-01 18:48:42 +00:00
|
|
|
must be <16384
|
2004-03-30 01:05:51 +00:00
|
|
|
|
|
|
|
data_size_lsb[frame_code]
|
2004-05-01 18:48:42 +00:00
|
|
|
must be <16384
|
2004-03-30 01:05:51 +00:00
|
|
|
|
2004-05-04 01:29:17 +00:00
|
|
|
timestamp_delta[frame_code]
|
|
|
|
must be <16384 and >-16384
|
|
|
|
|
2004-03-31 01:44:57 +00:00
|
|
|
data_size
|
2004-04-23 15:48:17 +00:00
|
|
|
data_size= data_size_lsb + data_size_msb*data_size_mul;
|
|
|
|
|
|
|
|
coded_timestamp
|
|
|
|
if coded_timestamp < (1<<msb_timestamp_shift) then its a
|
|
|
|
lsb timestamp, otherwise its a full timestamp + (1<<msb_timestamp_shift)
|
|
|
|
lsb timestamps are converted to full timesamps by:
|
|
|
|
mask = (1<<msb_timestamp_shift)-1;
|
|
|
|
delta= last_timestamp - mask/2
|
|
|
|
timestamp= ((timestamp_lsb-delta)&mask) + delta
|
2004-04-28 03:19:35 +00:00
|
|
|
a full timestamp must be used if there is no reference timestamp
|
|
|
|
available after the last frame_startcode with the current stream_id
|
2004-04-23 15:48:17 +00:00
|
|
|
|
2003-02-06 15:33:02 +00:00
|
|
|
lsb_timestamp
|
2004-03-30 01:05:51 +00:00
|
|
|
least significant bits of the timestamp in time_base precission
|
2003-02-06 15:33:02 +00:00
|
|
|
Example: IBBP display order
|
2004-03-31 01:44:57 +00:00
|
|
|
keyframe timestamp=0 -> timestamp=0
|
2003-02-06 15:33:02 +00:00
|
|
|
frame lsb_timestamp=3 -> timestamp=3
|
|
|
|
frame lsb_timestamp=1 -> timestamp=1
|
|
|
|
frame lsb_timestamp=2 -> timestamp=2
|
|
|
|
...
|
2004-03-31 01:44:57 +00:00
|
|
|
keyframe msb_timestamp=257 -> timestamp=257
|
2004-03-30 01:05:51 +00:00
|
|
|
frame lsb_timestamp=255->timestamp=255
|
2003-03-13 15:32:48 +00:00
|
|
|
frame lsb_timestamp=0 -> timestamp=256
|
2003-02-06 15:33:02 +00:00
|
|
|
frame lsb_timestamp=4 -> timestamp=260
|
|
|
|
frame lsb_timestamp=2 -> timestamp=258
|
|
|
|
frame lsb_timestamp=3 -> timestamp=259
|
2004-04-03 13:23:44 +00:00
|
|
|
all timestamps of keyframes of a single stream MUST be monotone
|
2003-02-06 15:33:02 +00:00
|
|
|
|
2004-04-28 03:19:35 +00:00
|
|
|
dts
|
|
|
|
dts are 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 with dts == timestamp must be monotone, that means a frame
|
|
|
|
which occures later in the stream must have a larger or equal dts
|
|
|
|
then an earlier frame
|
|
|
|
FIXME rename timestamp* to pts* ?
|
|
|
|
|
2003-02-06 15:33:02 +00:00
|
|
|
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 relative prime if not zero
|
|
|
|
MUST be 0 if unknown
|
|
|
|
|
2003-05-23 12:17:36 +00:00
|
|
|
colorspace_type
|
2003-05-23 14:38:59 +00:00
|
|
|
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
|
|
|
|
|
2004-04-28 03:19:35 +00:00
|
|
|
samplerate_nom / samplerate_denom = samplerate
|
|
|
|
the number of samples per second
|
2003-02-06 15:33:02 +00:00
|
|
|
|
|
|
|
checksum
|
2004-04-05 12:06:30 +00:00
|
|
|
adler32 checksum
|
2003-02-06 15:33:02 +00:00
|
|
|
|
|
|
|
index_timestamp
|
|
|
|
value in time_base precission, relative to the last index_timestamp
|
|
|
|
|
|
|
|
index_position
|
|
|
|
position in bytes of the first byte of the keyframe header, relative
|
|
|
|
to the last index_position
|
|
|
|
|
2003-03-13 15:32:48 +00:00
|
|
|
id
|
|
|
|
the id of the type/name pair, so its more compact
|
|
|
|
0 means end
|
|
|
|
|
2003-02-07 21:35:39 +00:00
|
|
|
type
|
2003-02-08 18:50:18 +00:00
|
|
|
for example: "UTF8" -> String or "JPEG" -> jpeg image
|
2003-03-13 15:32:48 +00:00
|
|
|
Note: nonstandard fields should be prefixed by "X-"
|
|
|
|
Note: MUST be less than 6 byte long (might be increased to 64 later)
|
2003-02-07 21:35:39 +00:00
|
|
|
|
2003-02-06 17:19:09 +00:00
|
|
|
name
|
|
|
|
the name of the info entry, valid names are
|
2003-09-15 20:22:27 +00:00
|
|
|
"TotalTime" total length of the stream in msecs
|
2003-03-13 15:32:48 +00:00
|
|
|
"StreamId" the stream(s) to which the info packet applies
|
|
|
|
"StartTimestamp"
|
|
|
|
"EndTimestamp" the time range in msecs to which the info applies
|
|
|
|
"SegmentId" a unique id for the streams + time specified
|
2003-02-08 18:50:18 +00:00
|
|
|
"Author"
|
|
|
|
"Description"
|
|
|
|
"Copyright"
|
2003-02-09 16:45:08 +00:00
|
|
|
"Encoder" the name & version of the software used for encoding
|
2003-02-08 18:50:18 +00:00
|
|
|
"Title"
|
2003-02-09 19:01:00 +00:00
|
|
|
"Cover" an image of the (cd,dvd,vhs,..) cover (preferable PNG or JPEG)
|
2003-02-08 21:10:58 +00:00
|
|
|
"Source" "DVD", "VCD", "CD", "MD", "FM radio", "VHS", "TV",
|
|
|
|
"LD"
|
2003-02-09 19:01:00 +00:00
|
|
|
Optional: appended PAL,NTSC,SECAM, ... in parentheses
|
2003-02-08 21:10:58 +00:00
|
|
|
"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: dont forget the timezone
|
2004-02-18 13:33:57 +00:00
|
|
|
"ReplayGain"
|
2003-02-09 10:54:35 +00:00
|
|
|
"Keywords"
|
2003-02-06 17:19:09 +00:00
|
|
|
Note: if someone needs some others, please tell us about them, so we can
|
|
|
|
add them to the official standard (if they are sane)
|
2003-02-09 10:54:35 +00:00
|
|
|
Note: nonstandard fields should be prefixed by "X-"
|
2003-03-13 15:32:48 +00:00
|
|
|
Note: MUST be less than 64 bytes long
|
2003-02-06 17:19:09 +00:00
|
|
|
|
|
|
|
value
|
2003-03-13 15:32:48 +00:00
|
|
|
value of this name/type pair
|
2003-02-06 17:19:09 +00:00
|
|
|
|
2003-02-07 09:48:06 +00:00
|
|
|
stuffing
|
2003-03-13 15:32:48 +00:00
|
|
|
0x80 can be placed infront of any type v entry for stuffing
|
|
|
|
purposes
|
|
|
|
|
|
|
|
info_table[][2]={
|
|
|
|
{NULL , NULL }, // end
|
|
|
|
{NULL , NULL },
|
|
|
|
{NULL , "UTF8"},
|
|
|
|
{NULL , "v"},
|
|
|
|
{NULL , "s"},
|
|
|
|
{"StreamId" , "v"},
|
|
|
|
{"SegmentId" , "v"},
|
|
|
|
{"StartTimestamp" , "v"},
|
|
|
|
{"EndTimestamp" , "v"},
|
|
|
|
{"Author" , "UTF8"},
|
|
|
|
{"Titel" , "UTF8"},
|
|
|
|
{"Description" , "UTF8"},
|
|
|
|
{"Copyright" , "UTF8"},
|
|
|
|
{"Encoder" , "UTF8"},
|
|
|
|
{"Keyword" , "UTF8"},
|
|
|
|
{"Cover" , "JPEG"},
|
|
|
|
{"Cover" , "PNG"},
|
|
|
|
};
|
2003-02-06 15:33:02 +00:00
|
|
|
|
|
|
|
Structure:
|
|
|
|
|
|
|
|
the headers MUST be in exactly the following order (to simplify demuxer design)
|
|
|
|
main header
|
|
|
|
stream_header (id=0)
|
|
|
|
stream_header (id=1)
|
|
|
|
...
|
|
|
|
stream_header (id=n)
|
|
|
|
|
|
|
|
headers may be repated, but if they are then they MUST all be repeated together
|
|
|
|
and repeated headers MUST be identical
|
|
|
|
|
|
|
|
headers MUST be repeated every 10sec at least ? FIXME
|
2003-09-05 18:45:12 +00:00
|
|
|
headers MUST be repeated BEFORE keyframes
|
2003-02-07 09:48:06 +00:00
|
|
|
headers MUST be repeated at least twice (so they exist 3 times in a file)
|
|
|
|
|
|
|
|
Index
|
2003-03-13 15:50:41 +00:00
|
|
|
the index can be repeated but there SHOULD be at least one for each stream at
|
|
|
|
the end
|
2003-02-07 11:20:35 +00:00
|
|
|
Note: in case of realtime streaming there is no end, so no index there either
|
2003-02-07 09:48:06 +00:00
|
|
|
|
|
|
|
Info packets
|
|
|
|
the info_packet can be repeated, it can also contain different names & values
|
|
|
|
each time but only if allso the time is different
|
|
|
|
Info packets can be used to describe the file or some part of it (chapters)
|
|
|
|
|
|
|
|
info packets, SHOULD be placed at the begin of the file at least
|
|
|
|
for realtime streaming info packets will normally be transmitted when they apply
|
|
|
|
for example, the current song title & artist of the currently shown music video
|
|
|
|
|
|
|
|
Unknown packets
|
2004-04-13 00:49:47 +00:00
|
|
|
MUST be ignored by the demuxer
|
2003-02-06 17:19:09 +00:00
|
|
|
|
2003-02-06 15:33:02 +00:00
|
|
|
Sample code (GPL, & untested)
|
|
|
|
|
|
|
|
typedef BufferContext{
|
|
|
|
uint8_t *buf;
|
|
|
|
uint8_t *buf_ptr;
|
|
|
|
}BufferContext;
|
|
|
|
|
|
|
|
static inline uint64_t get_bytes(BufferContext *bc, int count){
|
|
|
|
uint64_t val=0;
|
|
|
|
|
|
|
|
assert(count>0 && count<9)
|
|
|
|
|
|
|
|
for(i=0; i<count; i++){
|
|
|
|
val <<=8;
|
|
|
|
val += *(bc->buf_ptr++);
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void put_bytes(BufferContext *bc, int count, uint64_t val){
|
|
|
|
uint64_t val=0;
|
|
|
|
|
|
|
|
assert(count>0 && count<9)
|
|
|
|
|
|
|
|
for(i=count-1; i>=0; i--){
|
|
|
|
*(bc->buf_ptr++)= val >> (8*i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2003-05-04 18:57:39 +00:00
|
|
|
static inline uint64_t get_v(BufferContext *bc){
|
2003-02-06 15:33:02 +00:00
|
|
|
uint64_t val= 0;
|
|
|
|
|
2003-05-23 12:17:36 +00:00
|
|
|
for(; space_left(bc) > 0; ){
|
2003-02-06 15:33:02 +00:00
|
|
|
int tmp= *(bc->buf_ptr++);
|
|
|
|
if(tmp&0x80)
|
|
|
|
val= (val<<7) + tmp - 0x80;
|
|
|
|
else
|
2003-02-06 20:18:59 +00:00
|
|
|
return (val<<7) + tmp;
|
2003-02-06 15:33:02 +00:00
|
|
|
}
|
2003-03-13 15:32:48 +00:00
|
|
|
|
|
|
|
return -1;
|
2003-02-06 15:33:02 +00:00
|
|
|
}
|
|
|
|
|
2003-05-04 18:57:39 +00:00
|
|
|
static inline int put_v(BufferContext *bc, uint64_t val){
|
2003-02-06 15:33:02 +00:00
|
|
|
int i;
|
|
|
|
|
2003-05-23 12:17:36 +00:00
|
|
|
if(space_left(bc) < 9) return -1;
|
2003-02-06 15:33:02 +00:00
|
|
|
|
2003-03-13 15:32:48 +00:00
|
|
|
val &= 0x7FFFFFFFFFFFFFFFULL; // FIXME can only encode upto 63 bits currently
|
|
|
|
for(i=7; ; i+=7){
|
|
|
|
if(val>>i == 0) break;
|
2003-02-06 15:33:02 +00:00
|
|
|
}
|
|
|
|
|
2003-09-06 14:32:26 +00:00
|
|
|
for(i-=7; i>0; i-=7){
|
2003-02-06 15:33:02 +00:00
|
|
|
*(bc->buf_ptr++)= 0x80 | (val>>i);
|
|
|
|
}
|
|
|
|
*(bc->buf_ptr++)= val&0x7F;
|
2003-03-13 15:32:48 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-04-28 03:19:35 +00:00
|
|
|
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));
|
|
|
|
|
|
|
|
while(delay--){
|
|
|
|
int64_t t= pts_cache[delay];
|
|
|
|
if(t < pts){
|
|
|
|
pts_cache[delay]= pts;
|
|
|
|
pts= t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pts;
|
|
|
|
}
|
|
|
|
|
2003-05-23 12:17:36 +00:00
|
|
|
Authors
|
|
|
|
|
|
|
|
Folks from MPlayer Developers Mailinglist (http://www.mplayehrq.hu/).
|
|
|
|
Authors in ABC-order: (FIXME! Tell us if we left you out)
|
|
|
|
Beregszaszi, Alex (alex@fsn.hu)
|
|
|
|
Bunkus, Moritz (moritz@bunkus.org)
|
|
|
|
Diedrich, Tobias (td@sim.uni-hannover.de)
|
2004-04-26 12:45:47 +00:00
|
|
|
Felker, Rich (dalias@aerifal.cx)
|
2003-05-23 12:17:36 +00:00
|
|
|
Franz, Fabian (FabianFranz@gmx.de)
|
|
|
|
Gereoffy, Arpad (arpi@thot.banki.hu)
|
|
|
|
Hess, Andreas (jaska@gmx.net)
|
|
|
|
Niedermayer, Michael (michaelni@gmx.at)
|