[mythtv] commdetector2

Daniel Walton dwalton at cisco.com
Fri Sep 1 14:22:36 UTC 2006

On Fri, 1 Sep 2006, Steven Adeff wrote:

> On 8/18/06, Robert Tsai <mythtv at tsaiberspace.net> wrote:
> > > I tested the flagger on a 60 minute episode of Mythbusters recorded
> > > on a PVR-150.  I recorded at 720x480, bitrate 6000, max bitrate
> > > 8000.
> >
> > I am expecting parameter tuning problems with analog recordings, since
> > I myself only have digital sources.
> >
> > I also expect problems with cable channels. I myself don't get any
> > cable channels, so didn't have anything to test with.
> Rob,
>  I'd like to help you tune these parameters and was wondering what
> sort of information you need? I've got a PVR-150 connected to a
> digital cable box (along with some HD tuners, but it looks like you've
> got that area covered).

I'll pass along what I've found so far so that you don't re-invent the wheel:

- Logo detection works really well for digital recordings but not so much for
analog.  As a test I recorded the same CBS show in analog and in HD, for the HD
recording the logo is clearly identified and extracted but for analog it can't
find the logo consistently enough to get a useful template.  You can see the
extracted logo for the HD recording here:


ESPN Classic is also in analog but their logo is very easy to pickup because it
is displayed on a black background which gives it a lot of contrast.  The FX and
comedy central logos are both very faint and are tough to extract.

If I drop FRAMESGMPCTILE from 97 down to 95 I'm able to extract the FX logo.
The challenge then becomes matching this logo in each frame because the logo can
be very faint in some frames if the background is a similar color as the logo.
You end up getting a lot of frames that are marked incorrectly but the code is
pretty good about recognizing that in "50 positive matches, 1 negative match,
followed by 100 positivies" the 1 negative match was a mistake.  The lower you
have to make FRAMESGMPCTILE to extract the logo the more likely you are to get
incorrect matches when checking each frame for the logo. I haven't tried
FRAMESGMPCTILE 95 for the analog CBS or comedy central logos yet.

I've been playing with the TemplateFinder and TemplateMatcher code quite a bit
though so you may get different results than me.  I sent Rob my diffs but I'm
not sure yet if he is going to commit them.

- I had several commercials that weren't flagged because they weren't a 15 sec,
20 sec, 30 sec, or 60 sec commercial (+/- the delta for each).  One was 10
seconds, another 42 seconds, etc. I made the following changes but at this point
almost any commercial length less than 65 seconds can be flagged so not sure how
much good it does to search on commercials of specific lengths.

Index: programs/mythcommflag/BlankFrameDetector.cpp
--- programs/mythcommflag/BlankFrameDetector.cpp        (revision 11004)
+++ programs/mythcommflag/BlankFrameDetector.cpp        (working copy)
@@ -212,9 +212,12 @@
         int     delta;  /* seconds */
     } breaktype[] = {
         /* Sort by "len". */
+        { 10,   2 },
         { 15,   2 },
         { 20,   2 },
         { 30,   5 },
+        { 40,   5 },
+        { 50,   5 },
         { 60,   5 },
     static const unsigned int   nbreaktypes =

- Blank frames are marked pretty reliably for digitial recordings but for analog
where the blank frames aren't as dark (sometimes in digitial they are 100%
black) I saw a lot of misses.  Right now a MAXRANGE of 32 seems to do the trick
but I am reflagging everything to make sure I'm not getting any non-blanks
flagged as blanks with this setting.

Index: programs/mythcommflag/BorderDetector.cpp
--- programs/mythcommflag/BorderDetector.cpp    (revision 11004)
+++ programs/mythcommflag/BorderDetector.cpp    (working copy)
@@ -85,7 +85,10 @@
      * edge-detection phase where they are likely to take edge pixels away from
      * possible template edges.
-    static const unsigned char  MAXRANGE = 8;
+    // dwalton - 16 didn't work
+    // 25 was better but still didn't find all blank frames
+    // 40 got all of them but had some false positives
+    static const unsigned char  MAXRANGE = 32;

      * TUNABLE:

- ESPN Classic tends to wait longer than most stations when it comes to
displaying their logo after a commercial break.  The longest I saw was 34
seconds so I changed MAXBLANKADJUSTMENT to 35.  The only case where this hasn't
been long enough was for the "30 days" show on FX.  FX sometimes waits a few
minutes before displaying their logo after a commercial.

Index: programs/mythcommflag/TemplateMatcher.cpp
--- programs/mythcommflag/TemplateMatcher.cpp   (revision 11004)
+++ programs/mythcommflag/TemplateMatcher.cpp   (working copy)
@@ -730,7 +752,7 @@
      * to deviate by up to MAXBLANKADJUSTMENT frames before/after the break
      * actually begins/ends.
-    const int       MAXBLANKADJUSTMENT = (int)roundf(25 * fps);  /* frames */
+    const int       MAXBLANKADJUSTMENT = (int)roundf(35 * fps);  /* frames */
     const bool      skipCommBlanks = blankFrameDetector->getSKipCommBlanks();

     const FrameAnalyzer::FrameMap *blankMap = blankFrameDetector->getBlanks();

After some tweaking I think I am getting better results with commdetector2 than
I was with the standard commercial detector.  There have been several shows that
I flagged with the standard commercial detector and then reflagged with
commdetector2 and got more accurate commercial flagging results.

Hope this helps


More information about the mythtv-dev mailing list