[Matroska-devel] MPEG2 in MKV!

spyder spyder at matroska.org
Thu Oct 30 08:06:03 CET 2003


Okay, after some discussion with Pamel.  I think i found a solution that 
could work if the streams are all structured the same.

The repeat first field pulldown works like this:

You have 4 progressive frames, 1/6 of a second of 24fps video:
(r indicates the RFF flag is set)

[A] [B] [Cr] [Dr] 

which decodes into (uppercase = first field, lowercase = second field):

[Aa] [Bb] [Cc] [CD] [dD]

not the incorrect matching of the fields at the end and the increase in frame 
count to 30fps

I think we can make frame D have a double length duration to compensate for 
the time difference.  The decoder must receive frame D before it can create 
the extra frame so it must be frame D.  If a decoder wants to drop the 
pulldown, it can simply ignore the RFF flag and then only output one frame 
with a double duration or just output at 24fps assuming of course that there 
is no real interlaced content or the decoder will handle that itself.  In my 
samples, these RFF combinations occur in sequntial pairs.  So this method 
should work.  However, you could technically have:

[Ar] [B] [C] [Dr] -> [Aa] [AB] [bC] [cD] [Dd]

This makes a godawful mess but could happen.

So the way I see it, we do the following:
[{SequenceHeader}{GOPHeader}{I-Frame}] [P] [B] [B] ...

We set timecodes for the frame following the first RFF to double length.  The 
other timecodes are just normally computed using the framerate.

Ok, new problem...Pamel and I were discussing this and removing sections of 
an MPEG2 MKV file could produce erroneous files if you remove a sequence 
header that changed the quantizers in mid-stream which would make the rest of 
the file invalid.  We need a better way to store the sequence header or 
otherwise the overhead for storing the sequence headers with every GOP would 
be tremendous, a few hundred extra bytes per I frame.  The sequence header 
can change properties of the video stream so it must be written in the file 
and not just tucked away in codec private.

MPEG2 is one ugly codec.  It's very error resilient.  You don't even have to 
have the GOP headers it turns out.  And on top of that, you don't need I 
frames either...Of course, you can't expect perfect playback then ;)

John



More information about the Matroska-devel mailing list