diff options
-rw-r--r-- | logos/S19_2E-1-1107-17500-A16_9.pgm | bin | 10020 -> 10024 bytes | |||
-rw-r--r-- | logos/S19_2E-1-1107-17502-A16_9.pgm | bin | 10019 -> 10024 bytes | |||
-rw-r--r-- | markad-standalone.cpp | 79 | ||||
-rw-r--r-- | markad-standalone.h | 1 | ||||
-rw-r--r-- | marks.cpp | 22 | ||||
-rw-r--r-- | marks.h | 4 | ||||
-rw-r--r-- | queue.cpp | 2 | ||||
-rw-r--r-- | video.cpp | 52 | ||||
-rw-r--r-- | video.h | 5 |
9 files changed, 120 insertions, 45 deletions
diff --git a/logos/S19_2E-1-1107-17500-A16_9.pgm b/logos/S19_2E-1-1107-17500-A16_9.pgm Binary files differindex d547efa..26ec9bc 100644 --- a/logos/S19_2E-1-1107-17500-A16_9.pgm +++ b/logos/S19_2E-1-1107-17500-A16_9.pgm diff --git a/logos/S19_2E-1-1107-17502-A16_9.pgm b/logos/S19_2E-1-1107-17502-A16_9.pgm Binary files differindex 4df56f1..db361d9 100644 --- a/logos/S19_2E-1-1107-17502-A16_9.pgm +++ b/logos/S19_2E-1-1107-17502-A16_9.pgm diff --git a/markad-standalone.cpp b/markad-standalone.cpp index ad220d8..41d2992 100644 --- a/markad-standalone.cpp +++ b/markad-standalone.cpp @@ -45,6 +45,47 @@ void cMarkAdStandalone::AddStartMark() } } +bool cMarkAdStandalone::CheckFirstMark() +{ + if (marksAligned) return true; + + // Check the second mark + clMark *second=marks.GetNext(0); + if (!second) return false; + + if ((second->type==MT_LOGOSTART) || (second->type==MT_BORDERSTART) || + (second->type==MT_CHANNELSTART)) + { + clMark *first=marks.Get(0); + if (first) marks.Del(first); + marksAligned=true; + } + + if ((second->type==MT_LOGOSTOP) || (second->type==MT_BORDERSTOP) || + (second->type==MT_CHANNELSTOP)) + { + marksAligned=true; + } + + // If we have an aspectchange, check the next aspectchange mark + // and the difference between + if ((second->type==MT_ASPECTCHANGE) && (macontext.Video.Info.FramesPerSecond>0)) + { + clMark *next=marks.GetNext(second->position,MT_ASPECTCHANGE); + if (next) + { + int MAXPOSDIFF=(int) (macontext.Video.Info.FramesPerSecond*60*13); + if ((next->position-second->position)>MAXPOSDIFF) + { + clMark *first=marks.Get(0); + if (first) marks.Del(first); + marksAligned=true; + } + } + } + return marksAligned; +} + void cMarkAdStandalone::AddMark(MarkAdMark *Mark) { if (!Mark) return; @@ -83,34 +124,30 @@ void cMarkAdStandalone::AddMark(MarkAdMark *Mark) marks.Del(MT_BORDERSTOP); } } + CheckFirstMark(); marks.Add(Mark->Type,Mark->Position,Mark->Comment); } void cMarkAdStandalone::RateMarks() { - if (marks.Count()<=3) return; // only three marks? -> nothing to rate - - // First check if we have only aspectmarks and no logomarks/audiomarks - int logomarks=marks.Count(MT_LOGOSTART) + marks.Count(MT_LOGOSTOP); - int audiomarks=marks.Count(MT_CHANNELSTART) + marks.Count(MT_CHANNELSTOP); - - if ((logomarks) || (audiomarks)) + if (marks.Count()>3) { - // If we have logomarks get rid of all aspectmarks - marks.Del(MT_ASPECTCHANGE); - } + int logomarks=marks.Count(MT_LOGOSTART) + marks.Count(MT_LOGOSTOP); + int audiomarks=marks.Count(MT_CHANNELSTART) + marks.Count(MT_CHANNELSTOP); - // Check the third mark - clMark *second=marks.GetNext(0); - if (!second) return; // failure - clMark *third=marks.GetNext(second->position); - if (!third) return; // failure - int MAXPOSDIFF=(int) (macontext.Video.Info.FramesPerSecond*60*13); - if ((third->position-second->position)>MAXPOSDIFF) - { - clMark *first=marks.Get(0); - if (first) marks.Del(first); + // If we have logomarks or audiomarks get rid of the aspect changes, + // cause if we have a recording with (>=3) aspect changes the + // logomarks were already deleted in AddMark + if ((logomarks) || (audiomarks)) + { + marks.Del(MT_ASPECTCHANGE); + } } + + // Check the first mark again + CheckFirstMark(); + + // TODO: more checks } void cMarkAdStandalone::SaveFrame(int frame) @@ -789,6 +826,7 @@ cMarkAdStandalone::cMarkAdStandalone(const char *Directory, bool BackupMarks, in sleepcnt=0; waittime=0; duplicate=false; + marksAligned=false; memset(&macontext,0,sizeof(macontext)); macontext.LogoDir=(char *) LogoDir; @@ -954,6 +992,7 @@ cMarkAdStandalone::cMarkAdStandalone(const char *Directory, bool BackupMarks, in video = new cMarkAdVideo(&macontext); audio = new cMarkAdAudio(&macontext); streaminfo = new cMarkAdStreamInfo; + dsyslog("channel %s",macontext.General.ChannelID); } else { diff --git a/markad-standalone.h b/markad-standalone.h index a7d52f7..a5a62a4 100644 --- a/markad-standalone.h +++ b/markad-standalone.h @@ -184,6 +184,7 @@ unsigned Descriptor_Length: bool bBackupMarks; clMarks marks; char *IndexToHMSF(int Index); + bool CheckFirstMark(); void AddStartMark(); void AddMark(MarkAdMark *Mark); void RateMarks(); @@ -111,26 +111,40 @@ clMark *clMarks::Get(int Position) return mark; } -clMark *clMarks::GetPrev(int Position) +clMark *clMarks::GetPrev(int Position, int Type) { if (!first) return NULL; // no elements yet clMark *mark=first; while (mark) { - if (mark->position>=Position) break; + if (Type==0xFF) + { + if (mark->position>=Position) break; + } + else + { + if ((mark->position>=Position) && (mark->type==Type)) break; + } mark=mark->Next(); } return mark->Prev(); } -clMark *clMarks::GetNext(int Position) +clMark *clMarks::GetNext(int Position, int Type) { if (!first) return NULL; // no elements yet clMark *mark=first; while (mark) { - if (mark->position>=Position) break; + if (Type==0xFF) + { + if (mark->position>=Position) break; + } + else + { + if ((mark->position>=Position) && (mark->type==Type)) break; + } mark=mark->Next(); } return mark->Next(); @@ -101,8 +101,8 @@ public: void Del(clMark *Mark); void Del(int Type); clMark *Get(int Position); - clMark *GetPrev(int Position); - clMark *GetNext(int Position); + clMark *GetPrev(int Position,int Type=0xFF); + clMark *GetNext(int Position,int Type=0xFF); bool Backup(const char *Directory, bool isTS); bool Save(const char *Directory, double FrameRate, bool isTS); bool CheckIndex(const char *Directory, bool isTS, bool *IndexError); @@ -31,6 +31,8 @@ cMarkAdPaketQueue::~cMarkAdPaketQueue() bool cMarkAdPaketQueue::Inject(uchar *Data, int Size) { if (!buffer) return false; + isyslog("inject was called, please report this"); + if (outptr>Size) { uchar *temp=(uchar *) alloca(Size+1); @@ -62,7 +62,14 @@ int cMarkAdLogo::Load(char *file) pFile=fopen(file, "rb"); if (!pFile) return -1; - fscanf(pFile, "P5\n#C%i\n%d %d\n255\n#", &area.corner,&LOGOWIDTH,&LOGOHEIGHT); + fscanf(pFile, "P5\n#C%i %i\n%d %d\n255\n#", &area.corner,&area.mpixel,&LOGOWIDTH,&LOGOHEIGHT); + + if (LOGOHEIGHT==255) + { + LOGOHEIGHT=LOGOWIDTH; + LOGOWIDTH=area.mpixel; + area.mpixel=0; + } if ((LOGOWIDTH<=0) || (LOGOHEIGHT<=0) || (LOGOWIDTH>LOGO_MAXWIDTH) || (LOGOHEIGHT>LOGO_MAXHEIGHT) || (area.corner<TOP_LEFT) || (area.corner>BOTTOM_RIGHT)) @@ -73,9 +80,12 @@ int cMarkAdLogo::Load(char *file) fread(&area.mask,1,LOGOWIDTH*LOGOHEIGHT,pFile); - for (int i=0; i<LOGOWIDTH*LOGOHEIGHT; i++) + if (!area.mpixel) { - if (!area.mask[i]) area.mpixel++; + for (int i=0; i<LOGOWIDTH*LOGOHEIGHT; i++) + { + if (!area.mask[i]) area.mpixel++; + } } fclose(pFile); @@ -158,14 +168,14 @@ int cMarkAdLogo::Detect(int lastiframe, int *logoiframe) return 0; } - long SUMA=0; + int SUMA=0; for (int Y=ystart; Y<=yend-1; Y++) { for (int X=xstart; X<=xend-1; X++) { - area.source[(X-xstart)+(Y-ystart)*LOGOWIDTH]= - macontext->Video.Data.Plane[0][X+(Y*macontext->Video.Data.PlaneLinesize[0])]; - SUMA+=area.source[(X-xstart)+(Y-ystart)*LOGOWIDTH]; + int val=macontext->Video.Data.Plane[0][X+(Y*macontext->Video.Data.PlaneLinesize[0])]; + area.source[(X-xstart)+(Y-ystart)*LOGOWIDTH]=val; + SUMA+=val; } } @@ -255,12 +265,10 @@ int cMarkAdLogo::Detect(int lastiframe, int *logoiframe) } if (macontext->StandAlone.LogoExtraction==-1) { - //printf("%i %i %i %i\n",lastiframe,area.rpixel,area.mpixel,(area.rpixel<(area.mpixel*0.01))); - if (area.status==UNINITIALIZED) { // Initialize - if (area.rpixel>(area.mpixel*0.4)) + if (area.rpixel>(area.mpixel*LOGO_VMARK)) { area.status=LOGO; } @@ -270,11 +278,11 @@ int cMarkAdLogo::Detect(int lastiframe, int *logoiframe) } } - if (area.rpixel>=(area.mpixel*0.4)) + if (area.rpixel>=(area.mpixel*LOGO_VMARK)) { if (area.status==NOLOGO) { - if (area.counter>=LOGO_MAXCOUNT) + if (area.counter>=LOGO_VMAXCOUNT) { area.status=ret=LOGO; *logoiframe=area.lastiframe; @@ -292,11 +300,11 @@ int cMarkAdLogo::Detect(int lastiframe, int *logoiframe) } } - if (area.rpixel<(area.mpixel*0.4)) + if (area.rpixel<(area.mpixel*LOGO_IMARK)) { if (area.status==LOGO) { - if (area.counter>=LOGO_MAXCOUNT) + if (area.counter>=LOGO_IMAXCOUNT) { area.status=ret=NOLOGO; *logoiframe=area.lastiframe; @@ -313,6 +321,15 @@ int cMarkAdLogo::Detect(int lastiframe, int *logoiframe) area.counter=0; } } + + if ((area.rpixel<(area.mpixel*LOGO_VMARK)) && (area.rpixel>(area.mpixel*LOGO_IMARK))) + { + area.counter=0; + } + + //printf("%5i %3i %4i %4i %i %i %i\n",lastiframe,SUMA,area.rpixel,area.mpixel, + // (area.rpixel>=(area.mpixel*LOGO_VMARK)),(area.rpixel<(area.mpixel*LOGO_IMARK)), + // area.counter ); //Save(lastiframe,area.sobel); // TODO: JUST FOR DEBUGGING! } else @@ -423,7 +440,6 @@ int cMarkAdBlackBordersHoriz::Process(int LastIFrame, int *BorderIFrame) #define BRIGHTNESS 20 if (!macontext) return 0; if (!macontext->Video.Data.Valid) return 0; - if (macontext->Video.Data.PlaneLinesize[0]!=macontext->Video.Info.Width) return 0; *BorderIFrame=borderiframe; @@ -431,15 +447,15 @@ int cMarkAdBlackBordersHoriz::Process(int LastIFrame, int *BorderIFrame) bool ftop=true,fbottom=true; // "fast" method - for (x=(macontext->Video.Info.Height-CHECKHEIGHT)*macontext->Video.Info.Width; - x<macontext->Video.Info.Height*macontext->Video.Info.Width; x++) + for (x=(macontext->Video.Info.Height-CHECKHEIGHT)*macontext->Video.Data.PlaneLinesize[0]; + x<macontext->Video.Info.Height*macontext->Video.Data.PlaneLinesize[0]; x++) { if (macontext->Video.Data.Plane[0][x]>BRIGHTNESS) fbottom=false; } if (fbottom) { - for (x=0; x<(macontext->Video.Info.Width*CHECKHEIGHT); x++) + for (x=0; x<(macontext->Video.Data.PlaneLinesize[0]*CHECKHEIGHT); x++) { if (macontext->Video.Data.Plane[0][x]>BRIGHTNESS) ftop=false; } @@ -21,7 +21,10 @@ #define LOGO_DEFWIDTH 192 #define LOGO_DEFHDWIDTH 288 -#define LOGO_MAXCOUNT 3 +#define LOGO_VMAXCOUNT 3 // count of IFrames for detection of "logo invisible" +#define LOGO_IMAXCOUNT 5 // count of IFrames for detection of "logo invisible" +#define LOGO_VMARK 0.8 // percantage of pixels for visible +#define LOGO_IMARK 0.15 // percentage of pixels for invisible class cMarkAdLogo { |