diff options
Diffstat (limited to 'command')
-rw-r--r-- | command/global.h | 48 | ||||
-rw-r--r-- | command/markad-standalone.cpp | 184 | ||||
-rw-r--r-- | command/markad-standalone.h | 18 | ||||
-rw-r--r-- | command/video.cpp | 15 | ||||
-rw-r--r-- | command/video.h | 2 |
5 files changed, 145 insertions, 122 deletions
diff --git a/command/global.h b/command/global.h index d55633f..540d927 100644 --- a/command/global.h +++ b/command/global.h @@ -22,36 +22,35 @@ typedef unsigned char uchar; #define MA_SP_TYPE 6 #define MA_BI_TYPE 7 -#define MT_UNCERTAIN 0 -#define MT_START 1 -#define MT_STOP 2 +#define MT_START 1 +#define MT_STOP 2 -#define MT_COMMON 0x10 -#define MT_COMMONSTART 0x11 -#define MT_COMMONSTOP 0x12 +#define MT_ASSUMED 0x10 +#define MT_ASSUMEDSTART 0x11 +#define MT_ASSUMEDSTOP 0x12 -#define MT_ASSUMED 0x20 -#define MT_ASSUMEDSTART 0x21 -#define MT_ASSUMEDSTOP 0x22 +#define MT_LOGOCHANGE 0x20 +#define MT_LOGOSTART 0x21 +#define MT_LOGOSTOP 0x22 -#define MT_LOGOCHANGE 0x30 -#define MT_LOGOSTART 0x31 -#define MT_LOGOSTOP 0x32 +#define MT_HBORDERCHANGE 0x30 +#define MT_HBORDERSTART 0x31 +#define MT_HBORDERSTOP 0x32 -#define MT_BORDERCHANGE 0x40 -#define MT_BORDERSTART 0x41 -#define MT_BORDERSTOP 0x42 +#define MT_VBORDERCHANGE 0x40 +#define MT_VBORDERSTART 0x41 +#define MT_VBORDERSTOP 0x42 -#define MT_ASPECTCHANGE 0x50 -#define MT_ASPECTSTART 0x51 -#define MT_ASPECTSTOP 0x52 +#define MT_ASPECTCHANGE 0x50 +#define MT_ASPECTSTART 0x51 +#define MT_ASPECTSTOP 0x52 -#define MT_CHANNELCHANGE 0x60 -#define MT_CHANNELSTART 0x61 -#define MT_CHANNELSTOP 0x62 +#define MT_CHANNELCHANGE 0x60 +#define MT_CHANNELSTART 0x61 +#define MT_CHANNELSTOP 0x62 -#define MT_MOVED 0xE0 -#define MT_ALL 0xFF +#define MT_MOVED 0xE0 +#define MT_ALL 0xFF typedef struct config { @@ -76,6 +75,7 @@ typedef struct config bool Before; bool GenIndex; bool AC3Always; + bool SaveInfo; } MarkAdConfig; typedef struct MarkAdPos @@ -98,8 +98,6 @@ typedef struct MarkAdMark int ChannelsAfter; MarkAdAspectRatio AspectRatioBefore; MarkAdAspectRatio AspectRatioAfter; - bool VerticalBorders; - bool Assumed; } MarkAdMark; typedef struct MarkAdMarks diff --git a/command/markad-standalone.cpp b/command/markad-standalone.cpp index f7abde9..35c2f18 100644 --- a/command/markad-standalone.cpp +++ b/command/markad-standalone.cpp @@ -180,15 +180,43 @@ int cOSDMessage::Send(const char *format, ...) return 0; } -void cMarkAdStandalone::CalculateCheckPositions(int startframe, int delta) +void cMarkAdStandalone::CalculateCheckPositions(int startframe) { if (!length) return; if (!startframe) return; if (!macontext.Video.Info.FramesPerSecond) return; + int delta=macontext.Video.Info.FramesPerSecond*MAXRANGE; + int len_in_frames=macontext.Video.Info.FramesPerSecond*length; + iStart=-startframe; - chkLEFT=startframe+delta+macontext.Video.Info.FramesPerSecond; - chkRIGHT=startframe+(length*macontext.Video.Info.FramesPerSecond); + iStop=-(startframe+len_in_frames); + chkSTART=-iStart+delta; + chkSTOP=-iStop+delta; +} + +void cMarkAdStandalone::CheckStop() +{ + dsyslog("checking stop"); + clMark *end=marks.GetAround(iStop,MT_STOP,0x0F); + + if (end) + { + marks.DelTill(end->position,false); + isyslog("using mark on position %i as stop mark",end->position); + } + else + { + //fallback, shouldn't be reached + MarkAdMark mark; + memset(&mark,0,sizeof(mark)); + mark.Position=iStart; + mark.Type=MT_ASSUMEDSTOP; + AddMark(&mark); + marks.DelTill(iStop,false); + } + iStop=0; + gotendmark=true; } void cMarkAdStandalone::CheckStart() @@ -239,7 +267,8 @@ void cMarkAdStandalone::CheckStart() { if (macontext.Info.DPid.Num) { - isyslog("broadcast with DolbyDigital2.0%s",macontext.Config->AC3Always ? + isyslog("broadcast with %i audio channels%s",macontext.Info.Channels, + macontext.Config->AC3Always ? "" : ", disabling AC3 decoding"); if (!macontext.Config->AC3Always) @@ -285,8 +314,10 @@ void cMarkAdStandalone::CheckStart() { marks.Del(MT_LOGOSTART); marks.Del(MT_LOGOSTOP); - marks.Del(MT_BORDERSTART); - marks.Del(MT_BORDERSTOP); + marks.Del(MT_HBORDERSTART); + marks.Del(MT_HBORDERSTOP); + marks.Del(MT_VBORDERSTART); + marks.Del(MT_VBORDERSTOP); } if (!begin) @@ -296,7 +327,7 @@ void cMarkAdStandalone::CheckStart() if (begin) { marks.DelTill(begin->position); - CalculateCheckPositions(begin->position,0); + CalculateCheckPositions(begin->position); isyslog("using mark on position %i as start mark",begin->position); } else @@ -308,7 +339,7 @@ void cMarkAdStandalone::CheckStart() mark.Type=MT_ASSUMEDSTART; AddMark(&mark); marks.DelTill(iStart); - CalculateCheckPositions(iStart,0); + CalculateCheckPositions(iStart); } iStart=0; return; @@ -325,20 +356,29 @@ void cMarkAdStandalone::AddMark(MarkAdMark *Mark) case MT_ASSUMEDSTART: if (asprintf(&comment,"assuming start (%i)",Mark->Position)==-1) comment=NULL; break; + case MT_ASSUMEDSTOP: + if (asprintf(&comment,"assuming stop (%i)",Mark->Position)==-1) comment=NULL; + break; case MT_LOGOSTART: if (asprintf(&comment,"detected logo start (%i)*",Mark->Position)==-1) comment=NULL; break; case MT_LOGOSTOP: if (asprintf(&comment,"detected logo stop (%i)",Mark->Position)==-1) comment=NULL; break; - case MT_BORDERSTART: - if (asprintf(&comment,"detected start of %s borders (%i)*", - Mark->VerticalBorders ? "vert." : "horiz.", + case MT_HBORDERSTART: + if (asprintf(&comment,"detected start of horiz. borders (%i)*", + Mark->Position)==-1) comment=NULL; + break; + case MT_HBORDERSTOP: + if (asprintf(&comment,"detected stop of horiz. borders (%i)", Mark->Position)==-1) comment=NULL; break; - case MT_BORDERSTOP: - if (asprintf(&comment,"detected stop of %s borders (%i)", - Mark->VerticalBorders ? "vert." : "horiz.", + case MT_VBORDERSTART: + if (asprintf(&comment,"detected start of vert. borders (%i)*", + Mark->Position)==-1) comment=NULL; + break; + case MT_VBORDERSTOP: + if (asprintf(&comment,"detected stop of vert. borders (%i)", Mark->Position)==-1) comment=NULL; break; case MT_ASPECTSTART: @@ -866,8 +906,7 @@ bool cMarkAdStandalone::ProcessFile(int Number) if (!framecnt) { - CalculateCheckPositions(tStart*macontext.Video.Info.FramesPerSecond, - macontext.Video.Info.FramesPerSecond*MAXRANGE); + CalculateCheckPositions(tStart*macontext.Video.Info.FramesPerSecond); } if (macontext.Config->GenIndex) @@ -879,13 +918,15 @@ bool cMarkAdStandalone::ProcessFile(int Number) if (macontext.Video.Info.Pict_Type==MA_I_TYPE) { lastiframe=iframe; - if (iStart<0) + if ((iStart<0) && (lastiframe>-iStart)) iStart=lastiframe; + if ((iStop<0) && (lastiframe>-iStop)) iStop=lastiframe; + if (iStart>0) { - if (lastiframe>-iStart) iStart=lastiframe; + if ((inBroadCast) && (lastiframe>chkSTART)) CheckStart(); } - if (iStart>0) + if (iStop>0) { - if ((inBroadCast) && (lastiframe>chkLEFT)) CheckStart(); + if (lastiframe>chkSTOP) CheckStop(); } iframe=framecnt-1; dRes=true; @@ -970,8 +1011,7 @@ bool cMarkAdStandalone::Reset(bool FirstPass) memset(&pkt,0,sizeof(pkt)); - chkLEFT=INT_MAX; - chkRIGHT=INT_MIN; + chkSTART=chkSTOP=INT_MAX; if (FirstPass) { @@ -1008,10 +1048,10 @@ void cMarkAdStandalone::ProcessFile() { if (lastiframe) { - if ((inBroadCast) && (!gotendmark) && (!tStart)) + if ((inBroadCast) && (!gotendmark)) { MarkAdMark tempmark; - tempmark.Type=MT_COMMONSTOP; + tempmark.Type=MT_ASSUMEDSTOP; tempmark.Position=lastiframe; AddMark(&tempmark); } @@ -1076,7 +1116,7 @@ void cMarkAdStandalone::Process() } } } - //SaveInfo(); + if (macontext.Config->SaveInfo) SaveInfo(); } else { @@ -1101,11 +1141,9 @@ bool cMarkAdStandalone::SetFileUID(char *File) return true; } -#if 0 bool cMarkAdStandalone::SaveInfo() { - if ((!setVideo43) && (!setVideo169) && (!setAudio20) && (!setAudio51) && (!setVideo43LB)) return true; - + isyslog("writing info file"); char *src,*dst; if (asprintf(&src,"%s/info%s",directory,isTS ? "" : ".vdr")==-1) return false; @@ -1117,7 +1155,6 @@ bool cMarkAdStandalone::SaveInfo() FILE *r,*w; r=fopen(src,"r"); - w=fopen(dst,"w+"); if ((!r) || (!w)) @@ -1131,12 +1168,6 @@ bool cMarkAdStandalone::SaveInfo() char *lline=NULL; size_t length=0; - bool setVideo43LB_done=false; - bool setVideo43_done=false; - bool setVideo169_done=false; - bool setAudio20_done=false; - bool setAudio51_done=false; - char lang[4]=""; int component_type_add=0; @@ -1176,27 +1207,19 @@ bool cMarkAdStandalone::SaveInfo() case 5: if (stream==stream_content) { - if ( (((type==1) || (type==5)) && (setVideo169)) || - (((type==3) || (type==7)) && ((setVideo43) || (setVideo43LB)))) + if ((macontext.Info.AspectRatio.Num==4) && (macontext.Info.AspectRatio.Den==3)) { - if (setVideo43) - { - if (fprintf(w,"X %i %02i %s 4:3\n",stream_content, - component_type_43+component_type_add,lang)<=0) err=true; - setVideo43_done=true; - } - if (setVideo43LB) - { - if (fprintf(w,"X %i %02i %s 4:3 LetterBox\n",stream_content, - component_type_43+component_type_add,lang)<=0) err=true; - setVideo43LB_done=true; - } - if (setVideo169) - { - if (fprintf(w,"X %i %02i %s 16:9\n",stream_content, - component_type_169+component_type_add,lang)<=0) err=true; - setVideo169_done=true; - } + if (fprintf(w,"X %i %02i %s 4:3\n",stream_content, + component_type_43+component_type_add,lang)<=0) err=true; + macontext.Info.AspectRatio.Num=0; + macontext.Info.AspectRatio.Den=0; + } + else if ((macontext.Info.AspectRatio.Num==16) && (macontext.Info.AspectRatio.Den==9)) + { + if (fprintf(w,"X %i %02i %s 16:9\n",stream_content, + component_type_169+component_type_add,lang)<=0) err=true; + macontext.Info.AspectRatio.Num=0; + macontext.Info.AspectRatio.Den=0; } else { @@ -1205,22 +1228,22 @@ bool cMarkAdStandalone::SaveInfo() } break; case 2: - if ((type==5) && ((setAudio51) || (setAudio20))) + if (type==5) { - if (setAudio51) + if (macontext.Info.Channels==6) { if (fprintf(w,"X 2 05 %s Dolby Digital 5.1\n",lang)<=0) err=true; - setAudio51_done=true; + macontext.Info.Channels=0; } - if (setAudio20) + else if (macontext.Info.Channels==2) { if (fprintf(w,"X 2 05 %s Dolby Digital 2.0\n",lang)<=0) err=true; - setAudio20_done=true; + macontext.Info.Channels=0; + } + else + { + if (fprintf(w,"%s",line)<=0) err=true; } - } - else - { - if (fprintf(w,"%s",line)<=0) err=true; } break; default: @@ -1255,28 +1278,23 @@ bool cMarkAdStandalone::SaveInfo() if (stream_content) { - if ((setVideo43LB) && (!setVideo43LB_done) && (!err)) - { - if (fprintf(w,"X %i %02i %s 4:3 LetterBox\n",stream_content, - component_type_43+component_type_add,lang)<=0) err=true; - } - if ((setVideo43) && (!setVideo43_done) && (!err)) + if ((macontext.Info.AspectRatio.Num==4) && (macontext.Info.AspectRatio.Den==3) && (!err)) { if (fprintf(w,"X %i %02i %s 4:3\n",stream_content, component_type_43+component_type_add,lang)<=0) err=true; } - if ((setVideo169) && (!setVideo169_done) && (!err)) + if ((macontext.Info.AspectRatio.Num==16) && (macontext.Info.AspectRatio.Den==9) && (!err)) { if (fprintf(w,"X %i %02i %s 16:9\n",stream_content, component_type_169+component_type_add,lang)<=0) err=true; } } - if ((setAudio20) && (!setAudio20_done) && (!err)) + if ((macontext.Info.Channels==2) && (!err)) { if (fprintf(w,"X 2 05 %s Dolby Digital 2.0\n",lang)<=0) err=true; } - if ((setAudio51) && (!setAudio51_done) && (!err)) + if ((macontext.Info.Channels==6) && (!err)) { if (fprintf(w,"X 2 05 %s Dolby Digital 5.1\n",lang)<=0) err=true; } @@ -1315,7 +1333,6 @@ bool cMarkAdStandalone::SaveInfo() free(dst); return (err==false); } -#endif time_t cMarkAdStandalone::GetBroadcastStart(time_t start, int fd) { @@ -1891,7 +1908,7 @@ cMarkAdStandalone::cMarkAdStandalone(const char *Directory, const MarkAdConfig * bDecodeVideo=config->DecodeVideo; bDecodeAudio=config->DecodeAudio; - tStart=iStart=0; + tStart=iStart=iStop=0; if ((config->ignoreInfo & IGNORE_VIDEOINFO)==IGNORE_VIDEOINFO) { @@ -2000,7 +2017,7 @@ cMarkAdStandalone::cMarkAdStandalone(const char *Directory, const MarkAdConfig * esyslog("failed loading info - logo %s%sdisabled", (config->logoExtraction!=-1) ? "extraction" : "detection", bIgnoreTimerInfo ? " " : " and pre-/post-timer "); - tStart=iStart=0; + tStart=iStart=iStop=0; } } @@ -2069,15 +2086,14 @@ cMarkAdStandalone::cMarkAdStandalone(const char *Directory, const MarkAdConfig * audio = new cMarkAdAudio(&macontext); streaminfo = new cMarkAdStreamInfo; if (macontext.Info.ChannelName) - dsyslog("channel %s",macontext.Info.ChannelName); + isyslog("channel %s",macontext.Info.ChannelName); } framecnt=0; framecnt2=0; lastiframe=0; iframe=0; - chkLEFT=INT_MAX; - chkRIGHT=INT_MIN; + chkSTART=chkSTOP=INT_MAX; gettimeofday(&tv1,&tz); } @@ -2181,6 +2197,8 @@ int usage(int svdrpport) " make a backup of existing marks\n" "-G --genindex\n" " regenerate broken index file\n" + "-I --saveinfo\n" + " correct information in info file\n" "-L --extractlogo=<direction>[,width[,height]]\n" " extracts logo to /tmp as pgm files (must be renamed)\n" " <direction> 0 = top left, 1 = top right\n" @@ -2296,6 +2314,7 @@ int main(int argc, char *argv[]) // set defaults config.DecodeVideo=true; config.DecodeAudio=true; + config.SaveInfo=false; config.logoExtraction=-1; config.logoWidth=-1; config.logoHeight=-1; @@ -2350,6 +2369,7 @@ int main(int argc, char *argv[]) {"backupmarks", 0, 0, 'B'}, {"scenechangedetection", 0, 0, 'C'}, {"genindex",0, 0, 'G'}, + {"saveinfo",0, 0, 'I'}, {"extractlogo", 1, 0, 'L'}, {"OSD",0,0,'O' }, {"log2rec",0,0,'R'}, @@ -2360,7 +2380,7 @@ int main(int argc, char *argv[]) {0, 0, 0, 0} }; - c = getopt_long (argc, argv, "abcd:i:jl:nop:r:s:vBCGL:ORST:V", + c = getopt_long (argc, argv, "abcd:i:jl:nop:r:s:vBCGIL:ORST:V", long_options, &option_index); if (c == -1) break; @@ -2489,6 +2509,10 @@ int main(int argc, char *argv[]) config.GenIndex=true; break; + case 'I': + config.SaveInfo=true; + break; + case 'L': // --extractlogo str=optarg; diff --git a/command/markad-standalone.h b/command/markad-standalone.h index 50e3b6a..960f7ee 100644 --- a/command/markad-standalone.h +++ b/command/markad-standalone.h @@ -24,7 +24,7 @@ #define DELTATIME 20000 /* equals to 222ms (base is 90kHz PTS) */ -#define MAXRANGE 420 /* range to search for start/stop marks in seconds */ +#define MAXRANGE 120 /* range to search for start/stop marks in seconds */ class cOSDMessage { @@ -207,7 +207,14 @@ unsigned Descriptor_Length: time_t startTime; // starttime of broadcast int length; // length of broadcast in seconds int tStart; // pretimer in seconds - int iStart; // pretimer in frames + int iStart; // pretimer in frames (negative if unset) + int iStop; // endposition in frames (negative if unset) + + void CheckStop(); + void CheckStart(); + void CalculateCheckPositions(int startframe); + int chkSTART; + int chkSTOP; int skipped; // skipped bytes in whole file bool inBroadCast; // are we in a broadcast (or ad)? @@ -219,11 +226,6 @@ unsigned Descriptor_Length: bool setVideo169; // set video to 16:9 in info #endif - void CheckStart(); - void CalculateCheckPositions(int startframe, int delta); - int chkLEFT; - int chkRIGHT; - time_t GetBroadcastStart(time_t start, int fd); void CheckIndexGrowing(); char *indexFile; @@ -242,7 +244,7 @@ unsigned Descriptor_Length: bool CheckPATPMT(off_t Offset=0); bool CheckTS(); bool LoadInfo(); - //bool SaveInfo(); + bool SaveInfo(); bool SetFileUID(char *File); bool RegenerateIndex(); bool ProcessFile2ndPass(clMark **Mark1, clMark **Mark2, int Number, off_t Offset, int Frame, int Frames); diff --git a/command/video.cpp b/command/video.cpp index 6f7081b..5c86838 100644 --- a/command/video.cpp +++ b/command/video.cpp @@ -792,7 +792,7 @@ void cMarkAdVideo::resetmarks() } bool cMarkAdVideo::addmark(int type, int position, MarkAdAspectRatio *before, - MarkAdAspectRatio *after, bool verticalborders) + MarkAdAspectRatio *after) { if (marks.Count>marks.maxCount) return false; if (before) @@ -805,7 +805,6 @@ bool cMarkAdVideo::addmark(int type, int position, MarkAdAspectRatio *before, marks.Number[marks.Count].AspectRatioAfter.Num=after->Num; marks.Number[marks.Count].AspectRatioAfter.Den=after->Den; } - marks.Number[marks.Count].VerticalBorders=verticalborders; marks.Number[marks.Count].Position=position; marks.Number[marks.Count].Type=type; marks.Count++; @@ -863,17 +862,17 @@ MarkAdMarks *cMarkAdVideo::Process(int FrameNumber, int FrameNumberNext) } } - int borderframenumber; - int hret=hborder->Process(FrameNumber,&borderframenumber); + int hborderframenumber; + int hret=hborder->Process(FrameNumber,&hborderframenumber); - if ((hret>0) && (borderframenumber)) + if ((hret>0) && (hborderframenumber)) { - addmark(MT_BORDERSTART,borderframenumber); + addmark(MT_HBORDERSTART,hborderframenumber); } - if ((hret<0) && (borderframenumber)) + if ((hret<0) && (hborderframenumber)) { - addmark(MT_BORDERSTOP,borderframenumber); + addmark(MT_HBORDERSTOP,hborderframenumber); } if (!macontext->Video.Options.IgnoreAspectRatio) diff --git a/command/video.h b/command/video.h index 447d3ec..ae39f20 100644 --- a/command/video.h +++ b/command/video.h @@ -167,7 +167,7 @@ private: void resetmarks(); bool addmark(int type, int position, MarkAdAspectRatio *before=NULL, - MarkAdAspectRatio *after=NULL, bool verticalborders=false ); + MarkAdAspectRatio *after=NULL); bool aspectratiochange(MarkAdAspectRatio &a, MarkAdAspectRatio &b, bool &start); int framelast; |