[mythtv] Questions for MPEG2 knowledgable folks

Geoffrey Hausheer mythtv0368 at phracturedblue.com
Wed Oct 19 02:32:54 UTC 2005


I am currently looking into MPEG2 processing again.

  I got myself a ROKU HD 1000, which makes a very nice frontend
capable of displaying HD, but it can only play MPEG2 streams, and even
then it is quite picky.  It does fine on my ATSC streams, but I have
some other TS streams that it really doesn't like.  I tried running
replex on these streams, but it dies about 12mins in with a
ring-buffer overflow.  However, the ROKU plays those 12 minutes (the
output of replex) flawlessly.  I pulled out the mpeg stream parser I
wrote 2 years ago, and checked out the original stream.  It turns out
that there are 440 video frames missing in a 30 minute show (about 15
sec).  I'm not sure whether these frames are not in the original
transmission, or whether this is an artifact of the capture card that
aquired them.  If these weren't corrected, the audio would be about 15
seconds ahead of the video by the end of the program.  The reason myth
has no issues with the videos (as far as I can tell) is that the PTS
(presentation times) are skewed such that occasionally (not
consistantly) the video is slowed down to compensate.  The roku
doesn't seem to like this (and, as far as I can tell, it isn't allowed
in the DVD (or strict MPEG) spec either).  The MPEG spec seems to say
that while the PTS can be used to sync audio and video streams, video
frames should occur at a fixed frame rate (unless changed via a SEQ
header).  So to build a fully compliant stream, it appears I need to
present the video at fixed a fixed frequency.  I could do this by
inserting a redundant I-frame whenever the video is off by more than 1
frame (I should in theory be able to be within 1/2 of a frame from the
audio during these 'slow mo' periods.  However, (a) the video will
appear to stutter slightly, which may be annoying, and (b) the video
still won't be DVD compliant as the DVD spec requires a strict GOP
with a fixed number of I/P/B frames per GOP.  Of course, (b) may be a
non-issue, as the TS streams don't comply with the fixed GOP-size
requirements (or resolution, though that could be dealt with perhaps)
of the DVD spec anyway.
  Anyhow,  I'm looking for ideas on how else to approach the problem. 
The only other thing I've thought of is to reencode sections of the
audio at a slightly increased speed to keep it in line with the video.
 This would likely present the smoothest result, if I can learn how
the pitch-corrected video code works.
  Another thing I was wondering, as I'm not at all familiar with the
actual mpeg2 encoding stuff, is whetehr there is any way to convert
between I, P, and B frames without reencoding (i.e. losslessly).  I
guess it depends on whether motion-estimation occurs before or after
the macroblocks are decoded, but i'm really fuzzy on this stuff.  If
this were possible, I could actually build a DVD compliant stream from
my streams, which would be pretty cool.
  Once I figure out a reasonable method, I'll likely try to
incorporate it into mythtranscode, though with the job-queue, it may
prove more advantageous just to keep it as a completely seperate app.



More information about the mythtv-dev mailing list