[MPlayer-dev-eng] NUT cleanup
Oded Shimon
ods15 at ods15.dyndns.org
Mon Sep 5 21:36:06 CEST 2005
On Mon, Sep 05, 2005 at 02:59:46PM -0400, Rich Felker wrote:
> On Mon, Sep 05, 2005 at 09:43:47PM +0300, Oded Shimon wrote:
> > 2. adding other_stream_header, for subtitles and metadata
>
> IMO these probably need to be separate and thought out better..
>
> > 3. adding last_pts to index
>
> Is this the starting pts of the last frame? IMO it makes more sense to
> know the _ending_ pts of the last frame, i.e.
> last_frame_pts+last_frame_duration, tho this is not always known to
> the program generating the file I suppose.. :(
Hmm.. Yeah I guess it can never be accurate for VFR... But I think I can
live with a pts mistake of one frame...
It is kind of interesting.. For a player, what IS the frame duration of the
last frame?... heh.
Anyway, changing now to more accurately say "starting pts of the last
frame".
> I also wanted to store a zero-byte pseudo-frame at the end of each
> stream to store the final pts so that a duration for the last frame
> would be known, but the idea was (at least partly) shot down because
> it might not be known.
Heh I don't like this idea... Hackish.
> > 7. change forward_ptr behavior, starts right after forward_ptr, ends before
> > checksum
>
> Why ending before checksum?? IMO forward_ptr should point to the next
> startcode after the current packet. This is so the demuxer can demux
> new headers added in the future which it does not understand.
Ohh... Good point. I'll fix that.
> > 9. time_base_nom must also be non zero if i'm not mistaken?
>
> You forgot to switch the names of time_base_nom and denom, I think.
OK, I'll mix it with this patch.
I'm changing the order in the bitstream after all.
> > 13. specify that stream classes which have multiple streams must have an
> > info packet..
>
> Like I said on IRC, if we have a requirement like this IMO it belongs
> in a separate "semantic requirements" section.
I missed that.. I guess I don't listen to you either. :P
> > Things mentioned in this thread that are left:
> > 1. remove stream_id ?
>
> From headers? Rejected.
>
> > 2. change num/denom - i'll do this in a seperate patch - actually, it's
> > more than just a rename - it means time_base changes meaning - currently
> > it's the number of ticks in a second (which is bad definition imo),
> > changing it will make it into "length of a tick in seconds".
>
> Yes. But please include it.
Added.
> > 3. remove channel_count ?
>
> Not sure still..
>
> > 4. rename fourcc ?
>
> Yes, but to what? My vote would be "encoding" or something similar.
>
> > 5. remove mncf.txt
>
> Agree.
Somebody do that please... I'm not touching CVS file operations...
> > 6. rename ALL 'timestamp' in the file to 'pts' - Should I make a patch for
> > this?
Added. While doing this I also noticed the obsolete:
a full timestamp MUST be used if there is no reference timestamp
available after the last frame_startcode with the current stream_id
I'm removing this too...
New patch.
- ods15
-------------- next part --------------
--- ../main/DOCS/tech/mpcf.txt 2005-06-19 12:17:44.000000000 +0300
+++ mpcf.txt 2005-09-05 22:32:21.000000000 +0300
@@ -126,7 +126,7 @@
for(i=0; i<256; ){
tmp_flag v
tmp_fields v
- if(tmp_fields>0) tmp_timestamp s
+ if(tmp_fields>0) tmp_pts s
if(tmp_fields>1) tmp_mul v
if(tmp_fields>2) tmp_stream v
if(tmp_fields>3) tmp_size v
@@ -143,7 +143,7 @@
stream_id_plus1[i]= tmp_stream;
data_size_mul[i]= tmp_mul;
data_size_lsb[i]= tmp_size + j;
- timestamp_delta[i]= tmp_timestamp;
+ pts_delta[i]= tmp_pts;
reserved_count[i]= tmp_res;
}
}
@@ -156,10 +156,9 @@
stream_id v
stream_class v
fourcc vb
- average_bitrate v
time_base_nom v
time_base_denom v
- msb_timestamp_shift v
+ msb_pts_shift v
decode_delay v
fixed_fps u(1)
reserved u(6)
@@ -183,6 +182,11 @@
reserved_bytes
checksum u(32)
+other_stream_header:
+ stream_header
+ reserved_bytes
+ checksum u(32)
+
Basic Packets:
frame:
@@ -190,8 +194,8 @@
if(stream_id_plus1[frame_code]==0){
stream_id v
}
- if(timestamp_delta[frame_code]==0){
- coded_timestamp v
+ if(pts_delta[frame_code]==0){
+ coded_pts v
}
if(flags[frame_code]&1){
data_size_msb v
@@ -204,9 +208,10 @@
index_startcode f(64)
packet header
stream_id v
+ last_pts v
index_length v
for(i=0; i<index_length; i++){
- index_timestamp v
+ index_pts v
index_position v
}
reserved_bytes
@@ -234,19 +239,21 @@
sync_point:
frame_startcode f(64)
- global_timestamp v
+ global_pts v
Complete definition:
file:
file_id_string
- while(!eof && next_code != index_startcode){
+ while(next_code != end_startcode && next_code != index_startcode){
main_header
for(i=0; i<stream_count; i++){
if(next_packet==video_stream_header)
video_stream_header
- else
+ else if(next_packet==audio_stream_header)
audio_stream_header
+ else
+ other_stream_header
}
while(next_code != main_startcode){
if(next_code == info_startcode)
@@ -258,16 +265,18 @@
}
}
}
- index
-
+ while(next_code != end_startcode){
+ index
+ }
+ end_startcode f(64)
+ index_ptr v
Tag description:
forward_ptr
- 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
+ size of the packet data (exactly the distance from the first byte
+ after the forward_ptr to the first byte of the next packet)
file_id_string
"nut/multimedia container\0"
@@ -292,6 +301,8 @@
0xDD672F23E64EULL + (((uint64_t)('N'<<8) + 'X')<<48)
info_startcode
0xAB68B596BA78ULL + (((uint64_t)('N'<<8) + 'I')<<48)
+end_startcode
+ 0xE8154EDB2A7CULL + (((uint64_t)('N'<<8) + 'E')<<48)
version
NUT version. The current value is 2.
@@ -313,11 +324,8 @@
SHOULD be set to <=32768 or at least <=65536 unless there is a very
good reason to set it higher
-stream_id[FIXME]
+stream_id
Stream identifier
- Note: streams with a lower relative class MUST have a lower relative id
- so a stream with class 0 MUST always have an id which is lower than any
- stream with class > 0
stream_id MUST be < stream_count
stream_class
@@ -327,6 +335,8 @@
3 metadata
Note: the remaining values are reserved and MUST NOT be used
a demuxer MUST ignore streams with reserved classes
+ Note: stream_class MUST be bigger or equal to the stream_class of
+ the previous stream.
fourcc
identification for the codec
@@ -335,45 +345,38 @@
if needed
time_base_nom / time_base_denom = time_base
- the number of timer ticks per second, this MUST be equal to the fps
+ the length of a timer tick in seconds, this MUST be equal to the 1/fps
if the fixed_fps is 1
- time_base_denom MUST NOT be 0
+ time_base_nom and time_base_denom MUST NOT be 0
time_base_nom and time_base_denom MUST be relatively prime
- time_base_nom MUST be < 2^31
+ time_base_denom MUST be < 2^31
examples:
fps time_base_nom time_base_denom
- 30 30 1
- 29.97 30000 1001
- 23.976 24000 1001
- 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
+ 30 1 30
+ 29.97 1001 30000
+ 23.976 1001 24000
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
+ the length of a timer tick in seconds
+ global_time_base_nom and global_time_base_denom MUST NOT be 0
global_time_base_nom and global_time_base_denom MUST be relatively prime
- global_time_base_nom MUST be < 2^31
+ global_time_base_denom MUST be < 2^31
-global_timestamp
- timestamp in global_time_base units
- when a global_timestamp is encountered the last_timestamp of all
+global_pts
+ pts in global_time_base units
+ when a global_pts is encountered the last_pts 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
+ ln= global_time_base_nom*time_base_denom
+ sn= global_pts
+ d1= global_time_base_denom
+ d2= time_base_nom
+ last_pts= (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
-msb_timestamp_shift
- amount of bits in lsb_timestamp
+msb_pts_shift
+ amount of bits in lsb_pts
MUST be <16
decode_delay
@@ -416,47 +419,44 @@
data_size_lsb[frame_code]
must be <16384
-timestamp_delta[frame_code]
+pts_delta[frame_code]
must be <16384 and >-16384
data_size
data_size= data_size_lsb + data_size_msb*data_size_mul;
-coded_timestamp
- if coded_timestamp < (1<<msb_timestamp_shift) then it is an lsb
- timestamp, otherwise it is 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
- a full timestamp MUST be used if there is no reference timestamp
- available after the last frame_startcode with the current stream_id
+coded_pts
+ if coded_pts < (1<<msb_pts_shift) then it is an lsb
+ pts, otherwise it is a full pts + (1<<msb_pts_shift)
+ lsb pts is converted to a full pts by:
+ mask = (1<<msb_pts_shift)-1;
+ delta= last_pts - mask/2
+ pts= ((pts_lsb-delta)&mask) + delta
-lsb_timestamp
- least significant bits of the timestamp in time_base precision
+lsb_pts
+ least significant bits of the pts in time_base precision
Example: IBBP display order
- keyframe timestamp=0 -> timestamp=0
- frame lsb_timestamp=3 -> timestamp=3
- frame lsb_timestamp=1 -> timestamp=1
- frame lsb_timestamp=2 -> timestamp=2
+ 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_timestamp=257 -> timestamp=257
- frame lsb_timestamp=255->timestamp=255
- frame lsb_timestamp=0 -> timestamp=256
- frame lsb_timestamp=4 -> timestamp=260
- frame lsb_timestamp=2 -> timestamp=258
- frame lsb_timestamp=3 -> timestamp=259
- all timestamps of keyframes of a single stream MUST be monotone
+ 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 with dts == timestamp must be monotone, that means a frame
- which occures later in the stream must have a larger or equal dts
- than an earlier frame
- FIXME rename timestamp* to pts* ?
+ all frames must be monotone, that means a frame which occures 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
@@ -478,9 +478,15 @@
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).
-index_timestamp
- value of the timestamp of a keyframe relative to the last keyframe
+last_pts
+ The starting pts of the last frame
+
+index_pts
+ value of the pts of a keyframe relative to the last keyframe
stored in this index
index_position
@@ -490,6 +496,11 @@
2 consecutive index entries if they are more than max_index_distance
apart
+index_ptr
+ length in bytes from the first bytes of the first index startcode
+ to the first byte of the index_ptr. If there is no index, index_ptr
+ MUST be zero.
+
id
the id of the type/name pair, so it's more compact
0 means end
@@ -582,6 +593,8 @@
Index
Note: with realtime streaming, there is no end, so no index there either
+An index SHOULD be written for every stream. Indexes MUST be placed at end
+of file. Indexes MAY be repeated for a stream.
Info packets
the info_packet can be repeated, and can also contain different names & values
@@ -601,6 +614,10 @@
headers starting at offset 2^x for each x players SHOULD end their search from
a particular offset when any startcode is found (including syncpoint)
+ 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.
Sample code (GPL, & untested)
@@ -692,3 +709,4 @@
Gereoffy, Arpad (arpi at thot.banki.hu)
Hess, Andreas (jaska at gmx.net)
Niedermayer, Michael (michaelni at gmx.at)
+ Shimon, Oded (ods15 at ods15.dyndns.org)
More information about the MPlayer-dev-eng
mailing list