[mythtv] Getting started with real-time commercial detection

Chris Pinkham cpinkham at bc2va.org
Fri Jun 16 15:54:18 UTC 2006


* On Fri Jun 16, 2006 at 09:51:18AM -0400, Robert S. Grimes wrote:
> commercials!  My first goal is to watch TV with commercial detection
> running, such that when a commercial begins, MythTV simply cranks the volume
> down; later, maybe I'll want to do something like play music, or show some

A few issues.  I don't think that the flagger currently gets run on LiveTV
recordings.  I have a note in my TODO to look into this but haven't had time
lately.  It's a matter of looking into tv_rec.cpp and scheduling a flagger
job if the user has realtime flagging turned on.  There shouldn't be a need to
check the 'transcode after flagging' setting because we shouldn't be transcoding
LiveTV programs anyway.

So, assume that you are running commercial flagging when recording a LiveTV
program.  When the flagger runs, it periodically (every 500 frames currently)
recomputes the commercial skip list and if it has changed it sends out a
COMMFLAG_UPDATE event to any frontends watching the program.  It only does
this if a frontend has requested updates via the COMMFLAG_REQUEST event so
it doesn't waste time computing the skip list and sending out events if no
one is watching the recording.  The issue is that the flagging accuracy for the
last part of the video (ie, near realtime) is not really accurate.  We don't
know how long the current segment is because we haven't seen the end of it
(because it hasn't been recorded yet) so we don't know whether it is a commercial
or not.  You may get false alerts and missed flags also.  The 500-frame
cycle could be reduced and run every 60 frames or so, but you would still have
the issue that the flagger could have thought that you were in a commercial
last time, but now has more info and realizes it is not, and vice versa.  That
means you'd have to introduce a bunch of logic in the player to analyze and
keep track of the skip list(s) to know what state the volume is in, was in,
and should be in.

Muting or lowering the volume while playing back a non-live recording is easy,
you just have to have the player (ie, NVP) change the volume when it would
normally auto-skip and revert the changed volume when the commercial is over.
This kind of defeats the purpose of flagging though, because if you can do that,
then why not just skip the commercial to begin with.

So I'm not sure if you realize the scope of what you were thinking.  If you do
want to look into it, the files you'll need to look at are tv_rec.cpp for the
recorder and where you'd need to schedule the flagger job.  You'd need tv_play.cpp
for making the player be able to change the volume and you'd need
ClassicCommDetector.cpp if you needed to change the flagger to update the list
more often.  Note that updating the list consumes a lot of cpu and isn't
regulated by the JobQueue CPU setting except for the fact that the mythcommflag
process is niced, so doing this too often will both slow down the flagger and
may affect other processes running on the same machine.

> 1. Where - where does my code go?  Am I best off creating a plug-in?

I think that would be over complicated, best to put the logic right in the player
probably.

> 2. How - how do I get started writing a plug-in (if that's the best
> approach)?  Is there an example?

N/A.  There aren't any examples though, most people just pick another simple
plugin and start hacking away after renaming the files.

--
Chris


More information about the mythtv-dev mailing list