[mythtv-users] How to improve deinterlacing?
danielk at cuymedia.net
Sun Jun 10 14:00:56 UTC 2007
On Fri, 2007-06-08 at 20:19 -0400, Doug Larrick wrote:
> Thomas Kessler wrote:
> > I use Bob as my playback deinterlace setting. When I watch HDTV recorded
> > shows I can still see horizontal scan lines when scenes change. It's not
> > all the time just every so often (just enough to be annoying). Is there
> > anyway I can make deinterlacing perfect, the way HDTV looks on my TV's
> > tuner (flawless)?
> I've noticed that MythTV is quick to trust the source material's
> indication of progressive vs. interlaced frames. If your HD broadcaster
> is sending progressive-marked frames in a 1080i broadcast, Myth switches
> off deinterlacing for that frame. Even though it's probably wrong. You
> can fix for the duration of that recording by using the OSD menu to
> select Video Scan -> Interlaced.
Yep, I added that option to deal with this very problem.
MythTV trusts the frame markings in the MPEG stream and
if the stream is marked as progressive MythTV disables
the deinterlacing to show the progressive frames in their
full glory. But if the stream is broken you always have
the option of forcing MythTV to do the deinterlacing.
There is nothing preventing someone from writing a patch
to analyse the the video stream to detect a mislabeled
stream. A trivial algorithm for doing this would the to
look at a few lines in the middle of each frame and
calculating the difference between the odd and even lines
and the difference between each line from itself at the
previous frame. If the dx^2 of the interline difference
jumps more than the dx^2 of the intraline difference
several times in a row (say over a one minute span), then
the stream is probably interlaced. This calculation should
only be done if the frames are marked as progressive, and
if this then detects interlaced video the MPEG frame markings
should be ignored and the video should be deinterlaced.
A less trivial algorithm would be to calculate the motion
in each line, b-spline it, and then compare the motion of the
odd and even lines and see if one precedes the other by half
the frame interval. Calculating the motion is more complicated
but allows you to actually determine whether the odd or even
lines are first temporally and so detect frames where these
are out of order as well. (Note you don't actually have to
calculate the motion if you look at the motion vectors in the
MPEG stream, but unless you're an ffmpeg expert hooking into
ffmpeg in this way is probably more complicated than doing
the calculation yourself.)
The first algorithm would take me a couple days to write
and the second algorithm would take about a week. But I
would probably write the second one because it is more
interesting and tells us more about the video. I would
accept either as a patch.
More information about the mythtv-users