[mythtv] automatic 14:9 or 4:3 zoom based on black bars detection?

Daniel Kristjansson danielk at cuymedia.net
Sun Jun 25 15:41:05 UTC 2006


On Sun, 2006-06-25 at 13:20 +0200, Petr Stehlik wrote:

> Now I'd like to automate the switching between the zoom modes. First, if
> the source is in 4:3 format then I'd like to enable the 14:9 Zoom by
> default. Could someone please suggest a place in the source code to
> check for the input format and to enable/disable the zoom?
There isn't a place for this. There are three distinct reasons
why people use the aspect ratio overrides.
 1/ For coping with material that misreports the aspect ratio;
    or does not report it at all and uses non-square pixels.
    This would never be a 14:9 aspect ratio BTW, as we are 
    refering to the aspect ration of the transmission including
    the black bars.
 2/ For zooming into material simply as you do ( and I do ).
    "Proper Zoom"
 3/ For filling the screen with video when the aspect ratio
    of the source material does not fit the display aspect ratio.
    This results in either lost portions of the image, or the
    improper aspect ratio; but this is the desired result.
    "Improper Zoom"

So before you do any auto-zoom work or add 14:9 zoom you would
want to separate out the proper zoom portion (#2) of the "aspect
ratio overrides" into a new setting.

> Then, I think it would be cool if it was possible to detect on-the-fly
> if there are black bars on top&bottom and if there are then enable the
> 4:3 Zoom automagically.

> Is it possible (and cheap) to detect the black bars?
Depends on where you are. In the image preview or the commercial
detector it is easy. You have an image to work with of a frame,
unlike in the frontend when you wouldn't always have access to
this. BTW the bars aren't always black, HDTV broadcasts very often
use grey to try to limit damage to plasma displays.

>  Is there a code for it yet?
Nope. But this is fairly easy. The bars are usually solid color
in my experience. One simple way to find them them would be
to pick 4 x and 4 y coordinates randomly, so that those coord are
in the middle 50% of the frame in their respective dimensions.
Then sample each pixel in that row and column from both the left
and right, and top and bottom, resp. If there is a 10% change in 
intensity between the current pixel and the average so far then
stop. At the end of this procedure you will have 16 values.
Now you take the 4 top values and if they agree within a threshold
set this to be the top of the letterbox, repeat with the other
values; if any of the values is within a few pixels of the edge
just snap back to the edge. If you have 4 values at the end of
this (and the top is not below the bottom, and the right edge is
not left of the left edge) you have your letterboxing.

BTW1 The above will fail if the frame you sample is something like
a black frame in a black letterbox, hence the check for top edges
below bottom edges. If you do this in the commercial flagger you
can perform the check on every frame that the flagger looks at
and use the most popular aspect ratio overall.

BTW2 The above will fail for when there are ads in the letterbox
bars. They do this on some HDTV sports shows that are filmed in
4:3 but broadcast in 16:9. So far these ads are static so they
would be fairly easy do detect with a simple add on to the above
function. Simply subtract two frames 30 seconds apart for before
running the above on it. This will give you some bogus values,
and a lot of failed detects, but if you run it in the commercial
flagger like in BTW1 then you will get the correct result in the end.

-- Daniel



More information about the mythtv-dev mailing list