[MPlayer-dev-eng] Enhanced cropdetect code

Roger Heflin rogerheflin at gmail.com
Sun Jul 6 22:01:48 CEST 2008


Hello,

A story explaining why first, then what I coded to work around it.

I used mencoder to transcode and cropdetect ATSC TV, a couple of the helpful 
stations around here decided to get cute and put almost static (moving slowly) 
logos around 4:3 stuff in the widescreen area, this of course is not able to be 
detected by -vf cropdetect, and results in wasting a lot of screen area.

I have currently written up some code to change cropdetect to use entropy (how 
random things are) to detect this almost static stuff.    It appears to work 
correctly, I need suggestions of how that it would need to be best integrated in 
to be accepted, right now it is integrated in through #ifdef's (very dirty, but 
easy to test), and replaces the current cropdetect code, using the entropy part 
does appear to be able to do a better job than the original code (with the 
limits changed), and also be able to do a better job on the more complicated 
stuff, but also requires a number of FP operations to do properly so is very 
likely slower than the original cropdetect.

Suggestions how to best finish are wanted.

Included is my current code diffs, using '-vf cropdetect=13' and sampling enough 
frames to get proper range perfectly eliminates the extra stuff, using lower 
numbers will duplicate the original cropdetect's results, and not cutoff almost 
anything with any content.

                           Roger

diff ./libmpcodecs/vf_cropdetect.c ./libmpcodecs/vf_cropdetect_orig.c
5d4
< #include <math.h>
15,16d13
< #define USE_ENTROPY  1
<
25,32d21
<     int div=len;
<     int i;
< #ifdef USE_ENTROPY
<     double total=0;
<     int hist0[256];
<     int hist1[256];
<     int hist2[256];
< #else
34c23
< #endif
---
 >     int div=len;
37,56d25
< #ifdef USE_ENTROPY
<       for (i=0;i<256;i++) {
<           hist0[i]=0;
<       }
<       while(--len>=0){
<           // printf("pixel: %d \n",(int)src[0]);
<           hist0[src[0]] ++;
<           src+=stride;
<       }
<         for (i=0;i<256;i++) {
<             if (hist0[i] != 0) {
<               double p;
<                 p = (double)(hist0[i])/(double)(div);
<               //printf("%lf %d %d\n",p,hist2[i],div);
<                 total -= p*(log10(p)/log10(2.0));
<           }
<         }
<       total*=3;
<       break;
< #else
61d29
< #endif
64,98d31
< #ifdef USE_ENTROPY
<       for (i=0;i<256;i++) {
<           hist0[i]=0;
<           hist1[i]=0;
<           hist2[i]=0;
<       }
<       while(--len>=0){
<           //printf("pixel: %d %d %d\n",(int)src[0],(int)src[1],(int)src[2]);
<           hist0[src[0]] ++;
<           hist1[src[1]] ++;
<           hist2[src[2]] ++;
<           src+=stride;
<       }
<         for (i=0;i<256;i++) {
<             if (hist0[i] != 0) {
<               double p;
<                 p = (double)(hist0[i])/(double)(div);
<               //printf("%lf %d %d\n",p,hist2[i],div);
<                 total -= p*(log10(p)/log10(2.0));
<           }
<           if (hist1[i] != 0) {
<               double p;
<                 p = (double)(hist1[i])/(double)(div);
<               printf("%lf %d %d\n",p,hist2[i],div);
<                 total -= p*(log10(p)/log10(2.0));
<           }
<           if (hist2[i] != 0) {
<               double p;
<                 p = (double)(hist2[i])/(double)(div);
<               printf("%lf %d %d\n",p,hist2[i],div);
<                 total -= p*(log10(p)/log10(2.0));
<             }
<         }
<       break;
< #else
104d36
< #endif
106,109d37
< #ifdef USE_ENTROPY
<     //printf("total=%d %5.2lf\n",bpp,total);
<     return (int)(total);
< #else
113d40
< #endif



More information about the MPlayer-dev-eng mailing list