[mythtv-users] Commercial detection with silence - silence.cpp

Roger Siddons dizygotheca at ntlworld.com
Fri Aug 9 16:55:48 UTC 2013


On Fri, 09 Aug 2013 01:33:01 +0100, Mark Perkins <perkins1724 at hotmail.com>  
wrote:

>
> With reference to the Commercial detection with silence for UK  
> freeviewHD wiki page at  
> http://www.mythtv.org/wiki/>Commercial_detection_with_silence_for_UK_freeviewHD
>
>
> I’m new to MythTV so sorry if this is a dumb question or has been  
> covered elsewhere.
>
>
> I managed to get the scripts to compile and install with no problems  
> however was not able to get the silence detection to >work correctly. It  
> either detected no silences, or every frame as silent depending on the  
> threshold db set with only a very >small decimal change required to move  
> from no silences to all silences. There was nothing in between, it was  
> all or nothing.
>
>
> Long story short, after much troubleshooting I found that I was having  
> problems with the comparison between the set >threshold and the avgabs  
> variable declared in the silence.cpp code.
>
>
> I found that if I replaced line 373 of silence.cpp:
>
>
>        // determine average audio level in this frame
>
>        long avgabs = 0;
>
>
> with:
>
>
>        // determine average audio level in this frame
>
>        float avgabs = 0;
>
>
> that the threshold comparison would work correctly and silences were  
> detected correctly. In fact it works very well for me >now.
>
>
> But I am confused as to why this was causing a problem for me and not  
> for others? Have I missed something else?
>
>
> Any assistance or comments appreciated.
>
>

Hi Mark,

Welcome to Myth.

It's the first I've heard of it so thanks for taking the trouble to debug  
it & post. IMHO you've identified a real problem.

I'm away from home at the moment so can't investigate, but I'm guessing  
that frameSamples is so large that the calculation is underflowing the  
long.

It would be interesting to know your platform/compiler & the audio  
channels/samplerate of your programmes (mythffmpeg -i <sample>).

I run an older version with 2 channels @ 8k but I know Tim/Hippo has been  
optimizing the wiki version lately, so his experience will be the most  
pertinent. It would also be interesting to see if changing kUpmix_Channels  
to 2 makes any difference.

Although using float is safest, I'm sure there must be a better solution.  
If any audio/C gurus are reading, then here's the code in question. What's  
the appropriate portable C++ type to use that will cope with all audio  
formats ?

// Allocate data buffer to contain audio data from one video frame.
const size_t frameSamples = metadata.channels * metadata.samplerate / 25.0;

// determine average audio level in this frame
long avgabs = 0;
for (unsigned i = 0; i < frameSamples; i++)
      avgabs += abs(samples[i]);
avgabs = avgabs / frameSamples;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mythtv.org/pipermail/mythtv-users/attachments/20130809/d8ca264d/attachment.html>


More information about the mythtv-users mailing list