[mythtv] Questions for MPEG2 knowledgable folks

Geoffrey Hausheer mythtv0368 at phracturedblue.com
Thu Oct 20 15:39:20 UTC 2005


On 10/20/05, Cory Papenfuss wrote:
>  ProjectX appears to be
> the closest thing to being able to clean up the streams at the moment.
> Unfortunately, it's a 900-lb Java-flavored gorilla.
Hmm, maybe I'll take a look.

> >>         Basically MPEG2 was never meant to be edited... :)
> > Actually, MPEG2 is designed to be edited...sort of.  the spec allows
> > for discontinuous PTS if you set the broken bit.
>         Is the behavior of a playback device defined for when this
> happens?  I'd only heard of applying to broken bit when a GOP gets mangled
> (e.g. non-keyframe editing).
It is my understanding that you set the 'broken bit' to ignore any
B-frames which would be presented before the 1st I-frame after a GOP. 
This happens when you have discontinuity between two GOPs (i.e. you
chopped out info).  At this time, PTS can jump without any side
effects.

>>  But DVDs require a strict GOP structure, so this wouldn't be
> > a DVD-compliant stream.
>         There's open vs. closed GOPs, as well as different GOP structures.
> I didn't think that DVD-compliance implied either of those, however... I
> thought that open/closed and variable-length GOP structures were OK.
> Maybe it's just that the settop players are often tolerant of them and
> I've never noticed.
Well, MPEG2 (unlike MPEG1) doesn't actually require a GOP at all. 
However, DVD does.  I don't have a DVD spec around, but as I recall,
the GOP on a DVD must comprise:
IBBPBBPBBPBBPBB

>         ... that brings us back to your original question.  Can P/B frames
> be "losslessly" converted into I-frames.  I know very little about the
> internals of MPEG2 compression, so I can't help there.  I do know that the
> MPEG2 streams produced from ivtv card are pretty dirty.  In most captures
> I've played with, I've seen lost packets, very short PUs (generally a few
> dozen GOPs), fixed GOP length/structure (leading to poor choices on
> I-frames during scene changes, etc), open or closed GOP structures, etc.
> If the *structure* of the stream could be cleaned up without introducing a
> "generation loss," that would be great.  I suspect it would be pretty
> expensive, computationally.  It does fix all the problems, however.
Well, fixing GOPs are easy (sort of).  A GOP MUST start (streamwise
not temporally) with an I-frame, assuming I frames come at a
reasonable frequency, the GOPs can be set to be  correct from an MPEG2
persepctive.  The problem is again DVD-compliance, and for that, you
need an I-frame every 15 frames (to my kowledge), which implies frame
conversion.  Note that even if frame conversion (without reencoding)
is possible, the video quality will be identical to what you have now.
 If the B-frame prediction was off, converting a B-frame to an I-frame
would capure that 'badness'.  Anyhow, this is all speculation at this
point.  I either need to learn how the video encoding works, or wait
for someone to chime in who has enough knoledge.  What I can do is to
ensure that A/V ES are in sync, so demuxing/remuxing works, and that
is what I'm working on.

>         Sounds great, but won't it still be non-standard?  The problem is
> only partially that the encapsulation is funky.  The ES's themselves can
> be wrong (wrong GOP structure for instance).  They'll be especially wrong
> once frames are added/removed to fix PTS/DTS sync loss.  If you're right
> about the DVD-standard ONLY allowing a fixed GOP structure, you're kinda
> screwed to reencode ("losslessly" into I-frames or otherwise).  If it
> allows for variable, you could transcode only around dropped frames (and
> by trivial extension, commercial cuts).
Well, they will (hopefully) be standard MPEG2 streams, though not
DVD-compliant. But I'm not looking for DVD-compliance right now. It
looks like it is likely an intractable problem (unless frame
conversion is possible, or we pay the price of a reconversion).

I could make a much more informative statement if I had any
documentation about DVD requirements, but I don't.



More information about the mythtv-dev mailing list