Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
![]() |
#21 | Link |
Registered User
Join Date: Jan 2016
Posts: 79
|
Thank you StainlessS for your effort. I'm still trying out GMJCZP's method and will try out your suggestions tomorrow.
An off-topic question: When I use Maa2 downloaded from here with chroma=false, it gives the following error in AvspMod - Code:
Traceback (most recent call last): File "avsp.pyo", line 9043, in OnMenuVideoRefresh File "avsp.pyo", line 13855, in ShowVideoFrame File "avisynth.pyo", line 462, in GetFrame WindowsError: exception: access violation reading 0x00000000 Traceback (most recent call last): File "avsp.pyo", line 10614, in OnMouseMotionVideoWindow File "avsp.pyo", line 13156, in SetVideoStatusText File "avsp.pyo", line 13308, in GetVideoInfoDict File "avsp.pyo", line 16436, in FormatTime TypeError: %d format: a number is required, not float |
![]() |
![]() |
![]() |
#22 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,806
|
No solutions to your AvsPMod problem here, sorry.
The Real.Finder linked script performs really very well (at least on two identical clips, but one with added subtitles). Here, another excursion into insanity Code:
Function RectMarker(clip c,int W, Int H,Bool "Hit") { Hit=Default(hit,False) InFix = (Hit) \ ? RT_string("(((x<=1|x>=%d|y<=1|y>=%d)&(x<4|x>=%d)&(y<4|y>=%d)|(x==0|x==%d|y==0|y==%d)))?255:0", W-2,H-2,W-4,H-4,W-1,H-1) \ : RT_string("((x<=1|x>=%d|y<=1|y>=%d)&(x<4|x>=%d)&(y<4|y>=%d))?255:0", W-2,H-2,W-4,H-4) c.Blankclip(width=W,height=H,Length=1,pixel_type="YV12").Killaudio return mt_lutspa(relative = false,yExpr=mt_Polish(InFix), chroma = "128") } Function ShowMarker(clip c,int x,int y,int w,int h,Int color,bool type,Float "Opacity") { Opacity=Default(Opacity,1.0) W=(W<=0) ? c.Width-X+W : W H=(H<=0) ? c.Height-Y+H : H Msk = c.RectMarker(W+2,H+2,type) Mrk=Msk.BlankClip(Color=Color) Return c.Overlay(Mrk,x=X-1,y=Y-1,Mask=Msk,Mode="Blend",Opacity=Opacity) } Function FindSub(clip c,int "X",int "Y",int "W",int "H",Int "TextCol",Int "HaloCol",Int "ChanVar",Int "Text_w",Int "Text_h",Int "Halo_w",Int "Halo_h",Bool "ShowArea") { GSCript(""" Function _FindSub_Lo(clip c,int X,int Y,int W,int H,Int TextCol,Int HaloCol,Int ChanVar,Int Text_w,Int Text_h,Int Halo_w,Int Halo_h) { c TcB=RT_BitAnd(TextCol,$FF) TextCol=TextCol/256 TcG=RT_BitAnd(TextCol,$FF) TextCol=TextCol/256 TcR=RT_BitAnd(TextCol,$FF) HcB=RT_BitAnd(HaloCol,$FF) HaloCol=HaloCol/256 HcG=RT_BitAnd(HaloCol,$FF) HaloCol=HaloCol/256 HcR=RT_BitAnd(HaloCol,$FF) TcBLo=Max(TcB-ChanVar,0) TcGLo=Max(TcG-ChanVar,0) TcRLo=Max(TcR-ChanVar,0) TcBHi=Min(TcB+ChanVar,255) TcGHi=Min(TcG+ChanVar,255) TcRHi=Min(TcR+ChanVar,255) HcBLo=Max(HcB-ChanVar,0) HcGLo=Max(HcG-ChanVar,0) HcRLo=Max(HcR-ChanVar,0) HcBHi=Min(HcB+ChanVar,255) HcGHi=Min(HcG+ChanVar,255) HcRHi=Min(HcR+ChanVar,255) Thresh=Min(Text_W*100.0/W,Text_H*100.0/H) GotText=RT_RgbInRangeLocate(x=X,y=Y,w=W,h=H,Thresh=Thresh, \ RLo=TcRLo,RHi=TcRHi,GLo=TcGLo,GHi=TcGHi,BLo=TcBLo,BHi=TcBHi,Prefix="TXT_",Baffle_w=Text_W,Baffle_h=Text_H) n=current_frame if(GotText) { KX=TXT_X-Halo_w KY=TXT_Y-Halo_h GotHalo=RT_RgbInRangeLocate(x=KX,y=KY,w=TXT_W+2*Halo_w,h=TXT_H+2*Halo_h,Thresh=Thresh, \ RLo=HcRLo,RHi=HcRHi,GLo=HcGLo,GHi=HcGHi,BLo=HcBLo,BHi=HcBHi,Prefix="HAL_",Baffle_w=Halo_W,Baffle_h=Halo_H) if(GotHalo) { TXT_X2=TXT_X+TXT_W-1 TXT_Y2=TXT_Y+TXT_H-1 HAL_X2=HAL_X+HAL_W-1 HAL_Y2=HAL_Y+HAL_H-1 GudK=(HAL_X<=TXT_X && HAL_Y<=TXT_Y && HAL_X2>=TXT_X2 && HAL_Y2>=TXT_Y2) if(GudK) { OverLay(Last.BlankClip(color=$00FF00,width=HAL_W,height=HAL_H),x=HAL_X,y=HAL_Y,opacity=0.5) # Green Halo marker ON HALO RT_Subtitle("%d] Text='YES' : x=%d y=%d w=%d h=%d",n,TXT_X,TXT_Y,TXT_W,TXT_H) RT_Subtitle("Halo='YES' : x=%d y=%d w=%d h=%d",HAL_X,HAL_Y,HAL_W,HAL_H,y=20) } Else { OverLay(Last.BlankClip(color=$FFFF00,width=TXT_W,height=TXT_H),x=TXT_X,y=TXT_Y,opacity=0.5) # Yellow Text marker OverLay(Last.BlankClip(color=$FF0000,width=HAL_W,height=HAL_H),x=HAL_X,y=HAL_Y,opacity=0.5) # Red BAD halo marker RT_Subtitle("%d] Text='YES' : x=%d y=%d w=%d h=%d",n,TXT_X,TXT_Y,TXT_W,TXT_H) RT_Subtitle("Halo='FAIL' : x=%d y=%d w=%d h=%d",HAL_X,HAL_Y,HAL_W,HAL_H,y=20) } } Else { OverLay(Last.BlankClip(color=$FFFF00,width=TXT_W,height=TXT_H),x=TXT_X,y=TXT_Y,opacity=0.5) # Yellow Text marker RT_Subtitle("%d] Text='YES' : x=%d y=%d w=%d h=%d\nHalo='NO'",n,TXT_X,TXT_Y,TXT_W,TXT_H) } } else {RT_Subtitle("%d]",n)} Return Last } """) c X=Default(X,0) Y=Default(Y,0) W=Default(W,0) H=Default(H,0) W=(W<=0) ? c.Width-X+W : W H=(H<=0) ? c.Height-Y+H : H TextCol=Default(TextCol,$FEFEFE) HaloCol=Default(HaloCol,$020202) ChanVar=Default(ChanVar,2) Halo_w=Default(Halo_w,4) Halo_h=Default(Halo_h,4) Text_w=Default(Text_w,2) Text_h=Default(Text_h,2) (SHOWAREA)?ShowMarker(Last,X,Y,W,H,$FF80FF,true,0.4):NOP args="X,Y,W,H,TextCol,HaloCol,ChanVar,Text_w,Text_h,Halo_w,Halo_h" ScriptClip("_FindSub_Lo("+args+")",args=args) return Last } #--------------------- AVISource("D:\V\Cabaret.avi") # Some Clip with appropriate Subtitle SRT file. (Cabaret, border cropped, 668x396, 25FPS, 177640 frames) ConvertToRGB24 SRT="Cabaret.srt" # Subtitle for Above Clip ### Subtitle Search area X = 100 Y = Height-120 W = -X H = -8 # TEXT_W = 2 # minimum text pixel 'thickness' Horizontal TEXT_H = 2 # minimum text pixel 'thickness' Vertical HALO_W = 4 # Halo width in pixels (horizontal minimum, Could still be more Halo outside of detected area) HALO_H = 4 # Halo height in pixels (vertical minimum, Could still be more Halo outside of detected area) TEXTCOL = $FEFEFE HALOCOL = $010101 CHANVAR = 1 # Text and Halo RGB channels can vary by as much as CHANVAR, eg $FEFEFE with CHANVAR=1 ranges $FDFDFD -> $FFFFFF SHOWAREA = True # Set True to mark subtitle scan area BLANKCOL = $808080 # Color used if DOBLANK ie Blankclip color DOBLANK = False # Use only BlankClip not video DOAUDIO = True # Use audio ### Blank=AudioDub(Last.BlankClip(Color=BLANKCOL),Last) # Same size, FPS and frames as Template clip Last=(DOBLANK)?Blank:Last !DOAUDIO?KillAudio:NOP TextSub(SRT) # Add subtitles to frame FindSub(x=X,y=Y,w=W,h=H,TextCol=TEXTCOL,HaloCol=HALOCOL,Text_W=TEXT_W,Text_h=TEXT_H,halo_w=HALO_W,halo_h=HALO_H,showarea=SHOWAREA) Return Last
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? |
![]() |
![]() |
![]() |
#23 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,806
|
Here, a bit better, shows stacked vertical
Code:
Function RectMarker(clip c,int W, Int H,Bool "Hit") { Hit=Default(hit,False) InFix = (Hit) \ ? RT_string("(((x<=1|x>=%d|y<=1|y>=%d)&(x<4|x>=%d)&(y<4|y>=%d)|(x==0|x==%d|y==0|y==%d)))?255:0", W-2,H-2,W-4,H-4,W-1,H-1) \ : RT_string("((x<=1|x>=%d|y<=1|y>=%d)&(x<4|x>=%d)&(y<4|y>=%d))?255:0", W-2,H-2,W-4,H-4) c.Blankclip(width=W,height=H,Length=1,pixel_type="YV12").Killaudio return mt_lutspa(relative = false,yExpr=mt_Polish(InFix), chroma = "128") } Function ShowMarker(clip c,int x,int y,int w,int h,Int color,bool type,Float "Opacity") { Opacity=Default(Opacity,1.0) W=(W<=0) ? c.Width-X+W : W H=(H<=0) ? c.Height-Y+H : H Msk = c.RectMarker(W+2,H+2,type) Mrk=Msk.BlankClip(Color=Color) Return c.Overlay(Mrk,x=X-1,y=Y-1,Mask=Msk,Mode="Blend",Opacity=Opacity) } Function DetClip(clip c,int x,int y,int w,int h,Int TextCol,Int HaloCol,Int ChanVar,Int Text_w,Int Text_h,Int Halo_w,Int Halo_h) { c W=(W<=0)?c.Width-X+W:W H=(H<=0)?c.Height-Y+H:H ConvertToRGB24 TB=RT_BitAnd(TextCol,$FF) TextCol=TextCol/256 TG=RT_BitAnd(TextCol,$FF) TextCol=TextCol/256 TR=RT_BitAnd(TextCol,$FF) TBLo=Max(TB-ChanVar,0) TGLo=Max(TG-ChanVar,0) TRLo=Max(TR-ChanVar,0) TBHi=Min(TB+ChanVar,255) TGHi=Min(TG+ChanVar,255) TRHi=Min(TR+ChanVar,255) HB=RT_BitAnd(HaloCol,$FF) HaloCol=HaloCol/256 HG=RT_BitAnd(HaloCol,$FF) HaloCol=HaloCol/256 HR=RT_BitAnd(HaloCol,$FF) HBLo=Max(HB-ChanVar,0) HGLo=Max(HG-ChanVar,0) HRLo=Max(HR-ChanVar,0) HBHi=Min(HB+ChanVar,255) HGHi=Min(HG+ChanVar,255) HRHi=Min(HR+ChanVar,255) LimS="((x>=%d)&(x<=%d))?255:0" TRed=ShowRed (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,TRLo,TRHi))) TGrn=ShowGreen(Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,TGLo,TGHi))) TBlu=ShowBlue (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,TBLo,TBHi))) HRed=ShowRed (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,HRLo,HRHi))) HGrn=ShowGreen(Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,HGLo,HGHi))) HBlu=ShowBlue (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,HBLo,HBHi))) TXT=Mt_Logic(TRed,TGrn,"and").Mt_Logic(TBlu,"and").Mt_Expand().Mt_Expand() HAL=Mt_Logic(HRed,HGrn,"and").Mt_Logic(HBlu,"and").Mt_Expand().Mt_Expand() Mt_Logic(TXT,HAL,"and") return last } Function FindSub(clip c,int "X",int "Y",int "W",int "H",Int "TextCol",Int "HaloCol",Int "ChanVar",Int "Text_w",Int "Text_h",Int "Halo_w",Int "Halo_h",Bool "ShowArea") { GSCript(""" Function _FindSub_Lo(clip c,int X,int Y,int W,int H,Int Text_w,Int Text_h,Int Halo_w,Int Halo_h,clip dc) { c n=current_frame Bingo = RT_YInRangeLocate(dc,x=x,y=y,w=W,h=H,Baffle_w=Text_w+Halo_W,Baffle_h=Text_h+Halo_H,lo=255,hi=255) if(Bingo) { OverLay(Last.BlankClip(color=$FF8080,width=YIRL_W,height=YIRL_H),x=YIRL_X,y=YIRL_Y,opacity=0.5) RT_Subtitle("%d] : FoundText='YES' : x=%d y=%d w=%d h=%d",n,YIRL_X,YIRL_Y,YIRL_W,YIRL_H) } else { RT_Subtitle("%d] NO",n) } Return Last } """) c X=Default(X,0) Y=Default(Y,0) W=Default(W,0) H=Default(H,0) W=(W<=0) ? c.Width-X+W : W H=(H<=0) ? c.Height-Y+H : H TextCol=Default(TextCol,$FEFEFE) HaloCol=Default(HaloCol,$010101) ChanVar=Default(ChanVar,1) Text_w=Default(Text_w,2) Text_h=Default(Text_h,2) Halo_w=Default(Halo_w,2) Halo_h=Default(Halo_h,2) dc=DetClip(x,y,w,h,TextCol,HaloCol,ChanVar,Text_w,Text_h,Halo_w,Halo_h) dc=dc.ConvertToRGB24 dc (SHOWAREA)?ShowMarker(Last,X,Y,W,H,$FF80FF,true,0.4):NOP args="X,Y,W,H,Text_w,Text_h,Halo_w,Halo_h,dc" ScriptClip("_FindSub_Lo("+args+")",args=args) return Last } #--------------------- AVISource("D:\V\Cabaret.avi") # Some Clip with appropriate Subtitle SRT file. (Cabaret, border cropped, 668x396, 25FPS, 177640 frames) ConvertToRGB24 SRT="Cabaret.srt" # Subtitle for Above Clip ### Subtitle Search area X = 100 Y = Height-120 W = -X H = -8 # TEXT_W = 2 # minimum text pixel 'thickness' Horizontal TEXT_H = 2 # minimum text pixel 'thickness' Vertical HALO_W = 4 # Halo width in pixels (horizontal minimum, Could still be more Halo outside of detected area) HALO_H = 4 # Halo height in pixels (vertical minimum, Could still be more Halo outside of detected area) TEXTCOL = $FEFEFE HALOCOL = $010101 CHANVAR = 1 # Text and Halo RGB channels can vary by as much as CHANVAR, eg $FEFEFE with CHANVAR=1 ranges $FDFDFD -> $FFFFFF SHOWAREA = True # Set True to mark subtitle scan area BLANKCOL = $808080 # Color used if DOBLANK ie Blankclip color DOBLANK = False # Use only BlankClip not video DOAUDIO = True # Use audio ### ORG=Last Blank=AudioDub(Last.BlankClip(Color=BLANKCOL),Last) # Same size, FPS and frames as Template clip Last=(DOBLANK)?Blank:Last !DOAUDIO?KillAudio:NOP TextSub(SRT) # Add subtitles to frame ORG=Last FindSub(x=X,y=Y,w=W,h=H,TextCol=TEXTCOL,HaloCol=HALOCOL,Text_W=TEXT_W,Text_h=TEXT_H,halo_w=HALO_W,halo_h=HALO_H,showarea=SHOWAREA) StackVertical(Org,Last) Return Last
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 6th September 2016 at 23:03. |
![]() |
![]() |
![]() |
#24 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,806
|
Bit of a hack version, shows 4 window result, maybe a bit better.
I'm working on assumption that subs have a halo. This is of course just requiring single clip (not 2nd clip with clean source) and so possibly having more uses that in your case. Perhaps RaffRiff42 could do better, I'm somewhat limited in experience handling masks and the like. Anyways, here tis:- Code:
Function RectMarker(clip c,int W, Int H,Bool "Hit") { Hit=Default(hit,False) InFix = (Hit) \ ? RT_string("(((x<=1|x>=%d|y<=1|y>=%d)&(x<4|x>=%d)&(y<4|y>=%d)|(x==0|x==%d|y==0|y==%d)))?255:0", W-2,H-2,W-4,H-4,W-1,H-1) \ : RT_string("((x<=1|x>=%d|y<=1|y>=%d)&(x<4|x>=%d)&(y<4|y>=%d))?255:0", W-2,H-2,W-4,H-4) c.Blankclip(width=W,height=H,Length=1,pixel_type="YV12").Killaudio return mt_lutspa(relative = false,yExpr=mt_Polish(InFix), chroma = "128") } Function ShowMarker(clip c,int x,int y,int w,int h,Int color,bool type,Float "Opacity") { Opacity=Default(Opacity,1.0) W=(W<=0) ? c.Width-X+W : W H=(H<=0) ? c.Height-Y+H : H Msk = c.RectMarker(W+2,H+2,type) Mrk=Msk.BlankClip(Color=Color) Return c.Overlay(Mrk,x=X-1,y=Y-1,Mask=Msk,Mode="Blend",Opacity=Opacity) } GSCript(""" Function FindSub(clip c,int X,int Y,int W,int H,Int Text_w,Int Text_h,Int Halo_w,Int Halo_h,clip dc) { c n=current_frame Thresh=Min((Text_w+Halo_w*2)*100.0/W,(Text_h+Halo_h*2)*100.0/H) Bingo = dc.RT_YInRangeLocate(x=x,y=y,w=W,h=H,Baffle_w=Text_w+Halo_w,Baffle_h=Text_h+Halo_H,lo=255,hi=255,Thresh=Thresh) if(Bingo) { OverLay(Last.BlankClip(color=$FFFFFF,width=YIRL_W,height=YIRL_H),x=YIRL_X,y=YIRL_Y,opacity=0.2) RT_Subtitle("%d] Text @ x=%d y=%d w=%d h=%d",n,YIRL_X,YIRL_Y,YIRL_W,YIRL_H) } Return Last } """) AVISource("D:\V\Cabaret.avi") # Some Clip with appropriate Subtitle SRT file. (Cabaret, border cropped, 668x396, 25FPS, 177640 frames) ConvertToRGB24 SRT="Cabaret.srt" # Subtitle for Above Clip ### Subtitle Search area X = 100 Y = Height-120 W = -X H = -8 # TEXT_W = 4 # minimum text pixel 'thickness' Horizontal (horizontal thickness of vertical strokes) TEXT_H = 4 # minimum text pixel 'thickness' Vertical (vertical thickness of horizontal strokes) HALO_W = 6 # Halo width in pixels (horizontal minimum, Could still be more Halo outside of detected area) HALO_H = 6 # Halo height in pixels (vertical minimum, Could still be more Halo outside of detected area) TEXTCOL = $FEFEFE HALOCOL = $010101 CHANVAR = 1 # Text and Halo RGB channels can vary by as much as CHANVAR, eg $FEFEFE with CHANVAR=1 ranges $FDFDFD -> $FFFFFF SHOWAREA = True # Set True to mark subtitle scan area BLANKCOL = $808080 # Color used if DOBLANK ie Blankclip color DOBLANK = False # Use only BlankClip not video DOAUDIO = True # Use audio ### ORG=Last Blank=AudioDub(Last.BlankClip(Color=BLANKCOL),Last) # Same size, FPS and frames as Template clip Last=(DOBLANK)?Blank:Last !DOAUDIO?KillAudio:NOP TextSub(SRT) # Add subtitles to frame ORG=Last W=(W<=0)?Width-X+W:W H=(H<=0)?Height-Y+H:H TB=RT_BitAnd(TextCol,$FF) TextCol=TextCol/256 TG=RT_BitAnd(TextCol,$FF) TextCol=TextCol/256 TR=RT_BitAnd(TextCol,$FF) TBLo=Max(TB-ChanVar,0) TGLo=Max(TG-ChanVar,0) TRLo=Max(TR-ChanVar,0) TBHi=Min(TB+ChanVar,255) TGHi=Min(TG+ChanVar,255) TRHi=Min(TR+ChanVar,255) HB=RT_BitAnd(HaloCol,$FF) HaloCol=HaloCol/256 HG=RT_BitAnd(HaloCol,$FF) HaloCol=HaloCol/256 HR=RT_BitAnd(HaloCol,$FF) HBLo=Max(HB-ChanVar,0) HGLo=Max(HG-ChanVar,0) HRLo=Max(HR-ChanVar,0) HBHi=Min(HB+ChanVar,255) HGHi=Min(HG+ChanVar,255) HRHi=Min(HR+ChanVar,255) LimS="((x>=%d)&(x<=%d))?255:0" TRed=ShowRed (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,TRLo,TRHi))) TGrn=ShowGreen(Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,TGLo,TGHi))) TBlu=ShowBlue (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,TBLo,TBHi))) HRed=ShowRed (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,HRLo,HRHi))) HGrn=ShowGreen(Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,HGLo,HGHi))) HBlu=ShowBlue (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,HBLo,HBHi))) TXT=Mt_Logic(TRed,TGrn,"and").Mt_Logic(TBlu,"and") HAL=Mt_Logic(HRed,HGrn,"and").Mt_Logic(HBlu,"and") GSCript(""" for(i=1,HALO_H) {TXT=TXT.Mt_Expand(mode="vertical")} for(i=1,HALO_W) {TXT=TXT.Mt_Expand(mode="horizontal")} for(i=1,TEXT_H) {HAL=HAL.Mt_Expand(mode="vertical")} for(i=1,TEXT_W) {HAL=HAL.Mt_Expand(mode="horizontal")} Res=Mt_Logic(TXT,HAL,"and") """) args="X,Y,W,H,Text_w,Text_h,Halo_w,Halo_h,res" ORG=ORG.ScriptClip("FindSub("+args+")",args=args) ORG=(SHOWAREA)?ORG.ShowMarker(X,Y,W,H,$FFFFFF,true,0.25):ORG TXT=TXT.ConvertToRGB24 HAL=HAL.ConvertToRGB24 res=res.ConvertToRGB24 LFT=StackVertical(ORG,TXT.RT_Subtitle("\a!TEXT COLOR")) RGT=StackVertical(HAL.RT_Subtitle("\a!HALO COLOR"),Res.RT_Subtitle("\a!DETECT")) StackHorizontal(Lft,Rgt) ConvertToRGB24 then "Save Project & Demux Video". OverDiff5(), is probably as good as you will get but above routines could prove of use in other cases, and/or identify sections where you need to dissolve in the overlays. I could also add in some kind of OverRide to mark sections containing credits (which play havoc with detection). Above can be used with clean source and adding in subtitles using TextSub(), never tried with real hardcoded subs (dont think I've got any such footage). Can also just load in hardsubbed clip and comment out the TextSub() line. If anybody tries with hard subs, might want to tell of experience here. EDIT: Changed TEXT_W/H to 4, HALO_W/H to 6.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 7th September 2016 at 08:27. |
![]() |
![]() |
![]() |
#25 | Link |
Retried Guesser
Join Date: Jun 2012
Posts: 1,373
|
Not likely! Your script above seems to detect subtitles fine (the ones I tested).
So does OverDiff5, as far as I can see. Have not looked at fades credits etc. To make it easier for people to try your script, here it is with some small changes: Code:
## Dependencies: LoadPlugin(p + "MaskTools2\tp7masktools\masktools2.dll") LoadPlugin(p + "GRunT\GRunT.dll") LoadPlugin(p + "GScript\GScript.dll") LoadPlugin(p + "RT_Stats\RT_Stats26.dll") LoadPlugin(p + "VSFilter\VSFilter.dll") Function RectMarker(clip c,int W, Int H,Bool "Hit") { Hit=Default(hit,False) InFix = (Hit) \ ? RT_string("(((x<=1|x>=%d|y<=1|y>=%d)&(x<4|x>=%d)&(y<4|y>=%d)|(x==0|x==%d|y==0|y==%d)))?255:0", W-2,H-2,W-4,H-4,W-1,H-1) \ : RT_string("((x<=1|x>=%d|y<=1|y>=%d)&(x<4|x>=%d)&(y<4|y>=%d))?255:0", W-2,H-2,W-4,H-4) c.Blankclip(width=W,height=H,Length=1,pixel_type="YV12").Killaudio return mt_lutspa(relative = false,yExpr=mt_Polish(InFix), chroma = "128") } Function ShowMarker(clip c,int x,int y,int w,int h,Int color,bool type,Float "Opacity") { Opacity=Default(Opacity,1.0) W=(W<=0) ? c.Width-X+W : W H=(H<=0) ? c.Height-Y+H : H Msk = c.RectMarker(W+2,H+2,type) Mrk=Msk.BlankClip(Color=Color) Return c.Overlay(Mrk,x=X-1,y=Y-1,Mask=Msk,Mode="Blend",Opacity=Opacity) } GSCript(""" Function FindSub(clip c,int X,int Y,int W,int H,Int Text_w,Int Text_h,Int Halo_w,Int Halo_h,clip dc) { c n=current_frame Thresh=Min((Text_w+Halo_w*2)*100.0/W,(Text_h+Halo_h*2)*100.0/H) Bingo = dc.RT_YInRangeLocate(x=x,y=y,w=W,h=H,Baffle_w=Text_w+Halo_w,Baffle_h=Text_h+Halo_H,lo=255,hi=255,Thresh=Thresh) if(Bingo) { OverLay(Last.BlankClip(color=$FFFFFF,width=YIRL_W,height=YIRL_H),x=YIRL_X,y=YIRL_Y,opacity=0.2) RT_Subtitle("%d] Text @ x=%d y=%d w=%d h=%d",n,YIRL_X,YIRL_Y,YIRL_W,YIRL_H) } Return Last } """) AVISource("D:\V\Cabaret.avi") ConvertToRGB24 NOS=Last ## <<no-subtitle source>> #[[ TEST SRT="Cabaret.srt" # subtitles for above clip TextSub(SRT) ## add subtitles #][ PRODUCTION #AVISource("D:\V\Cabaret-hardsubbed.avi") #]] SUB=Last ## <<subtitle source>> ### Subtitle Search area X = 100 Y = Height-120 W = -X H = -8 # TEXT_W = 4 # minimum text pixel 'thickness' Horizontal (horizontal thickness of vertical strokes) TEXT_H = 4 # minimum text pixel 'thickness' Vertical (vertical thickness of horizontal strokes) HALO_W = 6 # Halo width in pixels (horizontal minimum, Could still be more Halo outside of detected area) HALO_H = 6 # Halo height in pixels (vertical minimum, Could still be more Halo outside of detected area) TEXTCOL = $FEFEFE HALOCOL = $010101 CHANVAR = 1 # Text and Halo RGB channels can vary by as much as CHANVAR, eg $FEFEFE with CHANVAR=1 ranges $FDFDFD -> $FFFFFF SHOWAREA = True # Set True to mark subtitle scan area BLANKCOL = $808080 # Color used if DOBLANK ie Blankclip color DOBLANK = False # Use only BlankClip not video DOAUDIO = True # Use audio ### Blank=AudioDub(Last.BlankClip(Color=BLANKCOL),Last) # Same size, FPS and frames as Template clip Last=(DOBLANK)?Blank:Last !DOAUDIO?KillAudio:NOP # #TextSub(SRT) (this line commented out & moved to top of script) # ORG=Last W=(W<=0)?Width-X+W:W H=(H<=0)?Height-Y+H:H TB=RT_BitAnd(TextCol,$FF) TextCol=TextCol/256 TG=RT_BitAnd(TextCol,$FF) TextCol=TextCol/256 TR=RT_BitAnd(TextCol,$FF) TBLo=Max(TB-ChanVar,0) TGLo=Max(TG-ChanVar,0) TRLo=Max(TR-ChanVar,0) TBHi=Min(TB+ChanVar,255) TGHi=Min(TG+ChanVar,255) TRHi=Min(TR+ChanVar,255) HB=RT_BitAnd(HaloCol,$FF) HaloCol=HaloCol/256 HG=RT_BitAnd(HaloCol,$FF) HaloCol=HaloCol/256 HR=RT_BitAnd(HaloCol,$FF) HBLo=Max(HB-ChanVar,0) HGLo=Max(HG-ChanVar,0) HRLo=Max(HR-ChanVar,0) HBHi=Min(HB+ChanVar,255) HGHi=Min(HG+ChanVar,255) HRHi=Min(HR+ChanVar,255) LimS="((x>=%d)&(x<=%d))?255:0" TRed=ShowRed (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,TRLo,TRHi))) TGrn=ShowGreen(Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,TGLo,TGHi))) TBlu=ShowBlue (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,TBLo,TBHi))) HRed=ShowRed (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,HRLo,HRHi))) HGrn=ShowGreen(Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,HGLo,HGHi))) HBlu=ShowBlue (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,HBLo,HBHi))) TXT=Mt_Logic(TRed,TGrn,"and").Mt_Logic(TBlu,"and") HAL=Mt_Logic(HRed,HGrn,"and").Mt_Logic(HBlu,"and") GSCript(""" for(i=1,HALO_H) {TXT=TXT.Mt_Expand(mode="vertical")} for(i=1,HALO_W) {TXT=TXT.Mt_Expand(mode="horizontal")} for(i=1,TEXT_H) {HAL=HAL.Mt_Expand(mode="vertical")} for(i=1,TEXT_W) {HAL=HAL.Mt_Expand(mode="horizontal")} Res=Mt_Logic(TXT,HAL,"and") """) args="X,Y,W,H,Text_w,Text_h,Halo_w,Halo_h,res" ORG=ORG.ScriptClip("FindSub("+args+")",args=args) ORG=(SHOWAREA)?ORG.ShowMarker(X,Y,W,H,$FFFFFF,true,0.25):ORG TXT=TXT.ConvertToRGB24 HAL=HAL.ConvertToRGB24 res=res.ConvertToRGB24 LFT=StackVertical(ORG,TXT.RT_Subtitle("\a!TEXT COLOR")) RGT=StackVertical(HAL.RT_Subtitle("\a!HALO COLOR"),Res.RT_Subtitle("\a!DETECT")) StackHorizontal(Lft,Rgt) ConvertToRGB24 ##[[ OUTPUT - pick one; comment out the others #return Last ## diagnostic, 4-way split return Overlay(SUB, NOS, mask=res, opacity=0.9) ## test, subtitles show faintly #return Overlay(SUB, NOS, mask=res) ## final run, subtitles removed completely #]] |
![]() |
![]() |
![]() |
#26 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,806
|
Thank you Raff, I'll have a try with mods later on.
I was not so much worried about the actual removal yet, just identification, will undoubtedly be made into a mutli-instance function when more final, perhaps with OverrDiff5() re-worked into it (if I can figure out how that works ![]() Guess I should have made it easier to use, LoadPlugin etc, but you came to rescue, cheers. ![]() EDIT: OT. I might steal some of your audio matching code (posted in another thread) in my matching script, I only really bother with conversion to 0, 1 or two channel (using FavC.avsi, from somewhere on-site) [I only bother really with stereo, the only multi speaker setup I ever had, I gave away because I could not be bothered to set it up, nor wanted to feel like there were people creeping all around me whilst playing a movie as a background noise maker, and working at same time]..
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 7th September 2016 at 15:42. |
![]() |
![]() |
![]() |
#27 | Link | |
Registered User
Join Date: Jan 2016
Posts: 79
|
OverDiff5 works great on all scenes that are identical like you said. I tried out your script (the version posted by raffriff), StainlessS and the detection works well. The script is pretty complex for me so I cannot understand how most of the script functions but can make out some of the things. When I ran it, these lines gave the error:
Code:
#LINES: TRed=ShowRed (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,TRLo,TRHi))) TGrn=ShowGreen(Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,TGLo,TGHi))) TBlu=ShowBlue (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,TBLo,TBHi))) HRed=ShowRed (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,HRLo,HRHi))) HGrn=ShowGreen(Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,HGLo,HGHi))) HBlu=ShowBlue (Pixel_Type="Y8").mt_lut(mt_Polish(RT_string(LimS,HBLo,HBHi))) Code:
ERROR: mt_lut: unsupported colorspace. masktools only supports planar YUV colorspaces (YV12, YV16, YV24) Also, I could not check the actual subtitle removal because for some reason, the last line returned the same hardsubbed clip. Code:
return Overlay(SUB, NOS, mask=res) ![]() The hardsub removal did actually work once however, upon refreshing the preview, I got the problem. Restarted everything but still nothing. This is the script I used: Code:
Function RectMarker(clip c,int W, Int H,Bool "Hit") { Hit=Default(hit,False) InFix = (Hit) \ ? RT_string("(((x<=1|x>=%d|y<=1|y>=%d)&(x<4|x>=%d)&(y<4|y>=%d)|(x==0|x==%d|y==0|y==%d)))?255:0", W-2,H-2,W-4,H-4,W-1,H-1) \ : RT_string("((x<=1|x>=%d|y<=1|y>=%d)&(x<4|x>=%d)&(y<4|y>=%d))?255:0", W-2,H-2,W-4,H-4) c.Blankclip(width=W,height=H,Length=1,pixel_type="YV12").Killaudio return mt_lutspa(relative = false,yExpr=mt_Polish(InFix), chroma = "128") } Function ShowMarker(clip c,int x,int y,int w,int h,Int color,bool type,Float "Opacity") { Opacity=Default(Opacity,1.0) W=(W<=0) ? c.Width-X+W : W H=(H<=0) ? c.Height-Y+H : H Msk = c.RectMarker(W+2,H+2,type) Mrk=Msk.BlankClip(Color=Color) Return c.Overlay(Mrk,x=X-1,y=Y-1,Mask=Msk,Mode="Blend",Opacity=Opacity) } GSCript(""" Function FindSub(clip c,int X,int Y,int W,int H,Int Text_w,Int Text_h,Int Halo_w,Int Halo_h,clip dc) { c n=current_frame Thresh=Min((Text_w+Halo_w*2)*100.0/W,(Text_h+Halo_h*2)*100.0/H) Bingo = dc.RT_YInRangeLocate(x=x,y=y,w=W,h=H,Baffle_w=Text_w+Halo_w,Baffle_h=Text_h+Halo_H,lo=255,hi=255,Thresh=Thresh) if(Bingo) { OverLay(Last.BlankClip(color=$FFFFFF,width=YIRL_W,height=YIRL_H),x=YIRL_X,y=YIRL_Y,opacity=0.2) RT_Subtitle("%d] Text @ x=%d y=%d w=%d h=%d",n,YIRL_X,YIRL_Y,YIRL_W,YIRL_H) } Return Last } """) MPEG2Source("C:\Anime Encoding\Hardsub Removal\NoSub.d2v") TFM().TDecimate() Crop(2, 0, -2, 1080, align=False) Trim(696, 4675)++Trim(6354,16279)++Trim(18438,38456)++Trim(39896,40254) Spline36Resize(1280,720) Trim(0,13897)++Trim(13906,0) Trim(0,25924) ++ Trim(25926,33915) ++ Trim(33904,33915) ++ Trim(33916, 0) #Trims made to match the hardsubbed clip FreezeFrame(33916, 33927, 33915) ConvertToRGB24 NOS=Last ## <<no-subtitle source>> FFVideoSource("C:\Anime Encoding\Hardsub Removal\HardSubbed.mkv") Trim(82, 0) Trim(0,25763)++Trim(25765,0) #Trims made to match other clip ConvertToRGB24 SUB=Last ## <<subtitle source>> ### Subtitle Search area X = 100 Y = Height-180 W = -X H = -8 # TEXT_W = 4 # minimum text pixel 'thickness' Horizontal (horizontal thickness of vertical strokes) TEXT_H = 4 # minimum text pixel 'thickness' Vertical (vertical thickness of horizontal strokes) HALO_W = 6 # Halo width in pixels (horizontal minimum, Could still be more Halo outside of detected area) HALO_H = 6 # Halo height in pixels (vertical minimum, Could still be more Halo outside of detected area) TEXTCOL = $FEFEFE HALOCOL = $010101 CHANVAR = 1 # Text and Halo RGB channels can vary by as much as CHANVAR, eg $FEFEFE with CHANVAR=1 ranges $FDFDFD -> $FFFFFF SHOWAREA = True # Set True to mark subtitle scan area BLANKCOL = $808080 # Color used if DOBLANK ie Blankclip color DOBLANK = False # Use only BlankClip not video DOAUDIO = False # Use audio ### #Blank=AudioDub(Last.BlankClip(Color=BLANKCOL),Last) # Same size, FPS and frames as Template clip Last=(DOBLANK)?Blank:Last !DOAUDIO?KillAudio:NOP # #TextSub(SRT) (this line commented out & moved to top of script) # ORG=Last W=(W<=0)?Width-X+W:W H=(H<=0)?Height-Y+H:H TB=RT_BitAnd(TextCol,$FF) TextCol=TextCol/256 TG=RT_BitAnd(TextCol,$FF) TextCol=TextCol/256 TR=RT_BitAnd(TextCol,$FF) TBLo=Max(TB-ChanVar,0) TGLo=Max(TG-ChanVar,0) TRLo=Max(TR-ChanVar,0) TBHi=Min(TB+ChanVar,255) TGHi=Min(TG+ChanVar,255) TRHi=Min(TR+ChanVar,255) HB=RT_BitAnd(HaloCol,$FF) HaloCol=HaloCol/256 HG=RT_BitAnd(HaloCol,$FF) HaloCol=HaloCol/256 HR=RT_BitAnd(HaloCol,$FF) HBLo=Max(HB-ChanVar,0) HGLo=Max(HG-ChanVar,0) HRLo=Max(HR-ChanVar,0) HBHi=Min(HB+ChanVar,255) HGHi=Min(HG+ChanVar,255) HRHi=Min(HR+ChanVar,255) LimS="((x>=%d)&(x<=%d))?255:0" TRed=ShowRed (Pixel_Type="YV12").mt_lut(mt_Polish(RT_string(LimS,TRLo,TRHi))) TGrn=ShowGreen(Pixel_Type="YV12").mt_lut(mt_Polish(RT_string(LimS,TGLo,TGHi))) TBlu=ShowBlue (Pixel_Type="YV12").mt_lut(mt_Polish(RT_string(LimS,TBLo,TBHi))) HRed=ShowRed (Pixel_Type="YV12").mt_lut(mt_Polish(RT_string(LimS,HRLo,HRHi))) HGrn=ShowGreen(Pixel_Type="YV12").mt_lut(mt_Polish(RT_string(LimS,HGLo,HGHi))) HBlu=ShowBlue (Pixel_Type="YV12").mt_lut(mt_Polish(RT_string(LimS,HBLo,HBHi))) TXT=Mt_Logic(TRed,TGrn,"and").Mt_Logic(TBlu,"and") HAL=Mt_Logic(HRed,HGrn,"and").Mt_Logic(HBlu,"and") GSCript(""" for(i=1,HALO_H) {TXT=TXT.Mt_Expand(mode="vertical")} for(i=1,HALO_W) {TXT=TXT.Mt_Expand(mode="horizontal")} for(i=1,TEXT_H) {HAL=HAL.Mt_Expand(mode="vertical")} for(i=1,TEXT_W) {HAL=HAL.Mt_Expand(mode="horizontal")} Res=Mt_Logic(TXT,HAL,"and") """) args="X,Y,W,H,Text_w,Text_h,Halo_w,Halo_h,res" ORG=ORG.ScriptClip("FindSub("+args+")",args=args) ORG=(SHOWAREA)?ORG.ShowMarker(X,Y,W,H,$FFFFFF,true,0.25):ORG TXT=TXT.ConvertToRGB24 HAL=HAL.ConvertToRGB24 res=res.ConvertToRGB24 LFT=StackVertical(ORG,TXT.RT_Subtitle("\a!TEXT COLOR")) RGT=StackVertical(HAL.RT_Subtitle("\a!HALO COLOR"),Res.RT_Subtitle("\a!DETECT")) StackHorizontal(Lft,Rgt) ##[[ OUTPUT - pick one; comment out the others #return Last ## diagnostic, 4-way split #return Overlay(SUB, NOS, mask=res, opacity=0.9) ## test, subtitles show faintly return Overlay(SUB, NOS, mask=res) ## final run, subtitles removed completely #]] Quote:
![]() |
|
![]() |
![]() |
![]() |
#28 | Link |
Retried Guesser
Join Date: Jun 2012
Posts: 1,373
|
making the change below
Code:
... GSCript(""" for(i=1,HALO_H) {TXT=TXT.Mt_Expand(mode="vertical")} for(i=1,HALO_W) {TXT=TXT.Mt_Expand(mode="horizontal")} for(i=1,TEXT_H) {HAL=HAL.Mt_Expand(mode="vertical")} for(i=1,TEXT_W) {HAL=HAL.Mt_Expand(mode="horizontal")} Res=Mt_Logic(TXT,HAL,"and", u=-128, v=-128) """) ... EDIT I've run into this kind of problem a lot with MaskTools, and forcing the mask clip to gray is always the solution. EDIT 2 @StainlessS, use u=-128, v=-128 as above, chroma="128" or chroma="copy" on all MaskTools functions (especially mt_logic & mt_expand) where you are processing a grayscale clip, or you can get invalid U & V data (the clip goes "green"). PS @blaze077, thanks for posting your complete script without having to be asked!! Last edited by raffriff42; 14th September 2016 at 01:54. Reason: chroma="128", not "-128" |
![]() |
![]() |
![]() |
#29 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,806
|
OK, I'll switch to YV12, The Mt_Tools v2.1.0.0 version I was using is 839KB (859,648 bytes) in size, not sure where I got it (but fairly recent).
blaze077, looking forward to the samples, thanx. The script basically extracts from RGB color value eg $FEFEFE, the individual R,G,B components of both Text and Halo, then calculates the range limits for each channel using CHANVAR (just saves user from specifying min and max for each color channel individually for both text and halo). The ShowRed, etc lines isolate pixels that fall within the acceptable ranges for all 3 channels for text, and then AND's them together so result is pixels where all 3 channels are in acceptable range. Same is then done for HALO. The for next loop, Expands (swells) the text [edit: by halo HALO_W,HALO_H] so as to swell into the halo region (both horizontally and vertically), and then expands the halo to swell into the text region [edit: by TEXT_W,TEXT_H]. (These are two swelled frames shown in diagnostic as TEXT and HALO frames). Finally, the expanded/swelled frames are AND'ed together for the diagnostic shown DETECT frame. This detect frame therefore contains white pixels where text/halo were valid colors, and because of the AND'ed swellings, it also shows where both text and halo swelled 'into' each other ie where they were adjacent to each other (allows to ignore randomly positioned pixels which just happen to be the sort after colors). The FindSub routine just checks the scan area using RT_YInRangeLocate() to see if there is a suspect area of white(good) pixels of sufficient 'bulk'. EDIT: The plugin I'm using seems to be this one in Downloads v2.0b1 masktools2-x86.zip, here on Wiki:- http://avisynth.nl/index.php/MaskTools2 Seems to works flawlessly for me, Y8. EDIT: Hit a small problem, TextSub() seems to produce drop shadow halos, and so more black halo below text [EDIT: and to the right] rather than above, we could improve things here if we could expand in only single direction (ie downwards, or upwards), but we dont know how ![]() It still works without this, but a little more error prone and would need to set HALO_H to maximum drop shadow size.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 8th September 2016 at 15:37. |
![]() |
![]() |
![]() |
#30 | Link |
Registered User
Join Date: Jan 2016
Posts: 79
|
Thank you, raffriff. It works now. I have the same version of masktools as you, StainlessS. I even added the plugins again but it doesn't work. It isn't a problem though because the script works now.
The subtitle removal works great for the most part but leaves out certain parts of the subtitle (mostly around the edges). In my clips, the source without the subtitles is actually better quality and is just for testing purposes for now. The subtitles are surrounded by uniform black borders all around. Also, thank you for the concise explanation of your script. Lining up clips is a pain though. DGIndex doesn't allow me to do precise frame cutting so I can only offer the best I could to trim to match the hardsubbed video without reencoding. It has a few mismatches in scenes but you can find many scenes with subs that are matching. Clips here. The hardsubbed video is pretty small in size however, the non-subbed version is a little too big. I really wish I could assist you but I am not capable of doing so. ![]() Last edited by blaze077; 16th September 2016 at 03:39. Reason: Rule 6 Violation |
![]() |
![]() |
![]() |
#31 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,806
|
Thanx, I'll grab a copy later today.
DGIndex precise lineup dont matter, easy to do that here. Raff, how does one feather, a binary mask ? EDIT: blaze077, you seem to have a bit of a God complex (profile), why dont you just magic the subtitles away ?
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 9th September 2016 at 12:57. |
![]() |
![]() |
![]() |
#32 | Link |
Retried Guesser
Join Date: Jun 2012
Posts: 1,373
|
The mask may have been created with mt_binary, but it is grayscale. You can Blur it as much as you please.
Even more mt_expand-ing* will be needed, or the subtitles will leak through around the edges. To expand & blur more easily, I would downscale, expand, blur, upscale. * edit - see here for some mt_expand tricks. Last edited by raffriff42; 11th September 2016 at 00:07. |
![]() |
![]() |
![]() |
#33 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,806
|
Thanx Raff, easy when you know how
![]()
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? |
![]() |
![]() |
![]() |
#35 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,806
|
Well about to get some shut eye, so here, something to play with (it aint blisteringly fast, still only detecting).
Code:
Function RemoveSubs_MI(clip c,string "Override", \ Int "X",Int "Y",Int "W",Int "H", \ Int "Text_w",Int "Text_h",Int "TextCol",Int "TextVar", \ Int "Halo_L",Int "Halo_T",Int "Halo_R",Int "Halo_B",Int "HaloCol",Int "HaloVar", \ Bool "Show",Int "stack",Bool "ShowArea",Int "AreaColor") { c myName="RemoveSubs_MI: " Assert(RT_FunctionExist("GScriptClip"),myName+"Essential GRunT plugin installed, http://forum.doom9.org/showthread.php?t=139337") Assert(RT_FunctionExist("GScript"),myName+"Essential GScript plugin installed, http://forum.doom9.org/showthread.php?t=147846") Assert(RT_FunctionExist("CallCmd"),myName+"Essential CallCmd plugin installed, http://forum.doom9.org/showthread.php?t=166063") Assert(RT_FunctionExist("mt_expand"),myName+"Essential MaskTools v2 plugin installed, http://forum.doom9.org/showthread.php?t=98985") c Override=Default(OverRide,"") X=Default(X,0) Y=Default(Y,Height-120) W=Default(W,0) H=Default(H,-8) W=(W<=0)?Width-X+W:W H=(H<=0)?Height-Y+H:H Text_w=Default(Text_w,3) Text_h=Default(Text_h,3) TextCol=Default(TextCol,$FCFCFC) TextVar=Default(TextVar,3) Halo_L=Default(Halo_L,3) Halo_T=Default(Halo_T,4) Halo_R=Default(Halo_R,5) Halo_B=Default(Halo_B,6) HaloCol=Default(HaloCol,$030303) HaloVar=Default(HaloVar,3) Show=Default(Show,False) Stack=(Show)?default(Stack,0):0 ShowArea=(Show)?Default(ShowArea,True):False AreaColor=Default(AreaColor,$FF00FF) Function CnvStr(clip c) { Return c.IsRGB24?"ConvertToRGB24":c.IsRGB32?"ConvertToRGB32":c.IsYUY2?"ConvertToYUY2":c.IsYV12?"ConvertToYV12" \ :c.IsYV16?"c.ConvertToYV16":c.IsYV24?"c.ConvertToYV24":c.IsY8?"c.ConvertToY8":"" } CNVS=CnvStr(c) Assert(CNVS!="",RT_String("%sRGB24, RGB32, YUY2, YV12, YV16, YV24,and Y8 Only",myName)) DB=RT_GetFullPathName("~"+RT_LocalTimeString+".DB") /* Fields 0) Status, 0=Unknown (unvisited), 1=Sub, 2 Not sub, 3 User OverRide 1) X 2) Y 3) W 4) H */ RT_DBaseAlloc(DB,FrameCount,"iiiii") FuncS=""" Function ChrIsStar(String S) {return RT_Ord(S)==42} Function ChrIsNul(String S) {return RT_Ord(S)== 0} # End of String Function ChrIsHash(String S) {return RT_Ord(S)==35} # # Function ChrIsDigit(String S) {C=RT_Ord(S) return C>=48&&C<=57} Function ChrEatWhite(String S) {i=1 C=RT_Ord(S,i) While(C==32||C>=8&&C<=13) {i=i+1 C=RT_Ord(S,i)} return i>1?MidStr(S,i):S} Function ChrEatDigits(String S) {i=1 C=RT_Ord(S,i) While(C>=48&&C<=57) {i=i+1 C=RT_Ord(S,i)} return i>1?MidStr(S,i):S} Function Fn@@@(clip c,String DB, \ int X,int Y,int W,int H,Int Text_w,Int Text_h,Int Halo_L,Int Halo_T,Int Halo_R,Int Halo_B, \ Float Thresh_w,Float Thresh_h, \ clip dc,bool Show,int Stack,bool ShowArea,Int AreaColor) { c n = current_frame Status = RT_DBaseGetField(DB,n,0) if(Show || Status <= 1) { # In here if Show or Status 0 or 1 (ie unvisited or Sub) if(Status==0) { # Unknown Status if(RT_Version >= 1.99902) { # RT_Stats version 2.00Beta2 Bingo = dc.RT_YInRangeLocate(x=x,y=y,w=W,h=H,Baffle_w=Text_w+(Halo_L+Halo_R)*9/10,Baffle_h=Text_h+(Halo_T+Halo_B)*9/10, \ lo=255,hi=255,Thresh_w=Thresh_w,Thresh_h=Thresh_h) } else { Thresh=min(Thresh_w,Thresh_h) Bingo = dc.RT_YInRangeLocate(x=x,y=y,w=W,h=H,Baffle_w=Text_w+(Halo_L+Halo_R)*9/10,Baffle_h=Text_h+(Halo_T+Halo_B)*9/10, \ lo=255,hi=255,Thresh=Thresh) } Status=(Bingo)?1:2 (Status==1) ? RT_DBaseSet(DB,n,Status,YIRL_X,YIRL_Y,YIRL_W,YIRL_H) : RT_DBaseSetField(DB,n,0,Status) } if(Show) { if(Status==1) { SUB_X = RT_DBaseGetField(DB,n,1) SUB_Y = RT_DBaseGetField(DB,n,2) SUB_W = RT_DBaseGetField(DB,n,3) SUB_H = RT_DBaseGetField(DB,n,4) SUB_W=(SUB_W+1)/2*2 SUB_H=(SUB_H+1)/2*2 OverLay(Last.BlankClip(color=AreaColor,width=SUB_W,height=SUB_H),x=SUB_X,y=SUB_Y,opacity=0.25) RT_Subtitle("%d] Text @ x=%d y=%d w=%d h=%d",n,SUB_X,SUB_Y,SUB_W,SUB_H) } else if(Status==3) { RT_Subtitle("%d] User OverRide",n) } } } # End (Show || Status) Return Last } ####################################### # Unique Global Variables Initialization ####################################### if(OverRide!="") { if(ChrIsStar(Override)) {OverRide=MidStr(OverRide,2) } else { Assert(Exist(OverRide),RT_String("%sOverRide File does not exist",myName)) OverRide=RT_ReadTxtFromFile(Override) } LINES=RT_TxtQueryLines(OverRide) for(i=0,LINES-1) { SS=ChrEatWhite(RT_TxtGetLine(Override,i)) S=SS if(!ChrIsNul(S) && !ChrIsHash(S)) { if(ChrIsDigit(S)) { StartF = RT_NumberValue(S) EndF=StartF S=ChrEatWhite(ChrEatDigits(S)) if(ChrIsComma(S)){S=MidStr(S,2) S=ChrEatWhite(S)} if(ChrIsDigit(S)) { EndF=RT_NumberValue(S) S=ChrEatDigits(S) if(EndF==0) { EndF=FrameCount-1} Assert(StartF<=EndF,RT_String("%sError StartFrame(%d) > EndFrame(%d)",myName,StartF,EndF)) } RT_DebugF("OverRiding Range %d,%d",StartF,EndF,name=myName) for(n=StartF,EndF) {RT_DBaseSetField(DB,n,0,3)} } S=ChrEatWhite(S) if(ChrIsHash(S)) {S=""} Assert(ChrIsNul(S),RT_String("%s *** NON-PARSE *** Error in Override Line %d\n'%s'",myName,i+1,SS)) } } } rgb=ConvertToRGB32.ResetMask # Reset Alpha to White Txt=rgb.ColorKeyMask(TextCol,TextVar+1,TextVar+1,TextVar+1).ShowAlpha(Pixel_Type="Y8") # Set in range pixels to black Hal=rgb.ColorKeyMask(HaloCol,HaloVar+1,HaloVar+1,HaloVar+1).ShowAlpha(Pixel_Type="Y8") Txt=Txt.Invert # In range pixels white, else black Hal=Hal.Invert HALO_W_MIN=Min(HALO_L,HALO_R) HALO_W_MAX=Max(HALO_L,HALO_R) HALO_H_MIN=Min(HALO_T,HALO_B) HALO_H_MAX=Max(HALO_T,HALO_B) HALO_MIN=Min(HALO_W_MIN,HALO_H_MIN) HALO_MAX=Max(HALO_W_MAX,HALO_H_MAX) for(i=0,HALO_MIN-1) { RT_DebugF("HALO Square") TXT=TXT.mt_expand(mode="square", chroma="1") } ## expand square if(HALO_W_MAX>HALO_MIN) { for(i=HALO_MIN,HALO_W_MIN-1) { RT_DebugF("HALO Horizontal") TXT=TXT.mt_expand(mode="horizontal", chroma="1") } ## expand horizontal if(HALO_W_MAX>HALO_W_MIN) { mode=HALO_R>HALO_L ? "-1 0 0 0" : " 1 0 0 0" for(i=HALO_W_MIN,HALO_W_MAX-1) { RT_DebugF(HALO_R>HALO_L?"HALO right":"HALO left") TXT=TXT.mt_expand(mode=mode, chroma="1") } ## expand left or right } } if(HALO_H_MAX>HALO_MIN) { for(i=HALO_MIN,HALO_H_MIN-1) { RT_DebugF("HALO Vertical") TXT=TXT.mt_expand(mode="vertical", chroma="1") } ## expand vertical if(HALO_H_MAX>HALO_H_MIN) { mode=HALO_B>HALO_T ? " 0 -1 0 0" : " 0 1 0 0" for(i=HALO_H_MIN,HALO_H_MAX-1) { RT_DebugF(HALO_B>HALO_T?"HALO down":"HALO up") TXT=TXT.mt_expand(mode=mode, chroma="1") } ## expand up or down } } TEXT_MIN=Min(TEXT_W,TEXT_H) for(i=0,TEXT_MIN-1) { RT_DebugF("TEXT square") HAL=HAL.Mt_Expand(mode="square", chroma="1") } if(TEXT_W>TEXT_MIN) { for(i=TEXT_MIN,TEXT_W-1) { RT_DebugF("TEXT horizontal") HAL=HAL.Mt_Expand(mode="horizontal", chroma="1") } } else if(TEXT_H>TEXT_MIN) { for(i=TEXT_MIN,TEXT_H-1) { RT_DebugF("TEXT vertical") HAL=HAL.Mt_Expand(mode="vertical", chroma="1") } } dc=Mt_Logic(TXT,HAL,"and", chroma="-128") if(Show && (Stack>=1 && Stack<=2)) { dc2=dc.Eval(CnvS) dc2=dc2.Subtitle("DETECT") if(Stack==2) { TXT = TXT.Eval(CnvS) TXT=TXT.Subtitle("TEXT") HAL = HAL.Eval(CnvS) HAL = HAL.Subtitle("HALO") c=StackHorizontal(StackVertical(Last,dc2),StackVertical(TXT,HAL)) } else { c=StackVertical(Last,dc2) } } else {c=Last} if(Show&&ShowArea) { WW=(W+1)/2*2 HH=(H+1)/2*2 # YV12 Legal Msk=c.Blankclip(width=WW+2,height=HH+2,Length=1,pixel_type="YV12").Killaudio Infix=RT_string("(((x<=1|x>=%d|y<=1|y>=%d)&(x<4|x>=%d)&(y<4|y>=%d)|(x==0|x==%d|y==0|y==%d)))?255:0", W-2,H-2,W-4,H-4,W-1,H-1) Msk=Msk.mt_lutspa(relative = false,yExpr=mt_Polish(InFix), chroma = "128") Mrk=Msk.BlankClip(Color=AreaColor) Msk=Msk.Loop(FrameCount,0,0) Mrk=Mrk.Loop(FrameCount,0,0) c=c.Overlay(Mrk,x=X-1,y=Y-1,Mask=Msk,Mode="Blend",Opacity=0.4) } Thresh_w=(Text_w+(Halo_L+Halo_R)*9/10)*100.0/W Thresh_h=(Text_h+(Halo_T+Halo_B)*9/10)*100.0/H ####################################### # Unique Runtime Call, GScriptClip must be a one-liner: ####################################### ARGS="DB,X,Y,W,H,Text_w,Text_h,Halo_L,Halo_T,Halo_R,Halo_B,Thresh_w,Thresh_h,dc,Show,Stack,Showarea,AreaColor" c.GScriptClip("Fn@@@(last, "+ARGS+")", local=true, args=ARGS) return Last """ ####################################### # Unique Identifier Definition ####################################### GIFunc="RemoveSubs_MI" # Function Name, Supply unique name for your multi-instance function. GIName=GIFunc+"_InstanceNumber" # Name of the Instance number Global RT_IncrGlobal(GIName) # Increment Instance Global (init to 1 if not already exists) GID = GIFunc + "_" + String(Eval(GIName)) InstS = RT_StrReplace(FuncS,"@@@","_"+GID) # RT_WriteFile("DEBUG_"+GID+".TXT","%s",InstS) GScript(InstS) CallCmd(close=RT_String("""CMD /C chcp 1252 && del "%s" """,DB), hide=true, Synchronous=7) # Auto delete DB file on clip closure. Return Last } AVISource("Hardsubbed.mkv.AVI") X = 100 Y = Height-144 W = -X H = -44 # TEXT_W = 3 # minimum text pixel 'thickness' Horizontal (horizontal thickness of vertical strokes) TEXT_H = 3 # minimum text pixel 'thickness' Vertical (vertical thickness of horizontal strokes) HALO_L = 4 # Left Halo width in pixels HALO_R = 4 # Right Halo width in pixels HALO_T = 4 # Top Halo height in pixels HALO_B = 4 # Bot Halo height in pixels TEXTCOL = $FDFDFD TEXTVAR = 2 # Text RGB channels can vary by as much as TEXTVAR, eg $FEFEFE with TEXTVAR=1 ranges $FDFDFD -> $FFFFFF HALOCOL = $020202 HALOVAR = 2 # Halo RGB channels can vary by as much as HALOVAR, eg $FEFEFE with HALOVAR=1 ranges $FDFDFD -> $FFFFFF AREACOLOR= $FF00FF SHOWAREA = True # Set True to mark subtitle scan area STACK = 0 # 0=Off, 1=2 Window Stack, 2=4 window stack OverRide = "" # ""=Not used, "*..." multiline string of ranges, "OverRide.txt"=Text file string of ranges. SHOW =true #OverRide="OverRide.txt" /* # Example String OverRide (1st char is '*'). Ranges OverRidden to NO SUBTITLE OverRide="""* 10 100 # A comment, SPACE or COMMA Separator 200,300 3000,0 """ */ RemoveSubs_MI(Last,Override=Override, \ x=X,y=Y,w=W,h=H, \ Text_w=TEXT_W,Text_h=TEXT_H,TextCol=TEXTCOL,TextVar=TEXTVAR, \ Halo_L=HALO_L,Halo_T=HALO_T,Halo_R=HALO_R,Halo_B=HALO_B,HaloCol=HALOCOL,HaloVar=HALOVAR, \ Show=SHOW,stack=STACK,ShowArea=SHOWAREA,AreaColor=AREACOLOR) Return Last
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 11th September 2016 at 17:42. Reason: Update |
![]() |
![]() |
![]() |
#36 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,806
|
Blaze, finally gotten around to looking at the nonsubbed clip.
The hardsubs clip is 1280x720@23.976 and the nonsubbed at 1920x1080@29.97, are you aware that they are different frame size and frameRate ? I'll still continue with current script a bit but no way will it be able to perform the required magic on those clips. I think you said somewhere that thread was just experimentation, if so then need compatible clips. Dont know if JohnMeyer mentioned Vegas can deal with varying clip characteristics.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? |
![]() |
![]() |
![]() |
#37 | Link | |
Registered User
Join Date: Jan 2016
Posts: 79
|
Quote:
Code:
TFM().TDecimate() Crop(2, 0, -2, 1080, align=False) Spline64Resize(1280,720) |
|
![]() |
![]() |
![]() |
#38 | Link |
Registered User
Join Date: Mar 2014
Posts: 308
|
I'm just going to give some generic advice here.
Firstly, this is obviously a rule 6 violation, though I guess this stopped mattering when neuron2 became Guest. Secondly, if you're looking for help with encoding for fansubs, ask other fansubbers. I hear this is a problem that they have researched reasonably well and have existing solutions for. Thirdly, anime series licensed from TV Tokyo on Crunchyroll and Funimation tend to have IVTC-related issues, and these issues are usually inconsistent between episodes. A majority of Funimation's streams are fine, but this particular series you're using as an example is not. Fourthly, you should ensure that the clips align as well as possible, both spatially and temporally. The aforementioned IVTC issues essentially guarantee that temporal alignment will require duplicating and deleting frames at random places (use a script, obviously; doing this manually is insane and a complete waste of time). As for spatial alignment, cropping the subtitle-free source by two pixels on the left and right sides is obviously not the right thing to do, as a frame comparison would tell you; all you have to do is to resize to 720p and you're done.
__________________
Say no to AviSynth 2.5.8 and DirectShowSource! |
![]() |
![]() |
![]() |
#39 | Link | |
Registered User
Join Date: Jan 2016
Posts: 79
|
Quote:
2. That did occur to me but I did not know where to ask and hence, arrived here. 4. I have PMed you. Thanks you, everyone for your help. ![]() |
|
![]() |
![]() |
![]() |
#40 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,806
|
post #1 of 2
I had done this script update anyway, but requires RT_Stats v2.0 Beta2 Code:
### # DetectSub.MI.avsi":- https://forum.doom9.org/showthread.php?p=1782036#post1782036 ### # DetectSub, MultiInstance script, MultiInstance not necessary here but easy convenient way to use Scriptclip, GScript and double quoted # strings in same script. Would have been nice if Avisynth also recognised groups of 5 sets of double quotes as well as groups of 3 and # single double quotes. # # req RT_Stats v2.00 Beta 02, GScript, Grunt, CallCmd, MaskTools v2.0. # RT_Stats v2.00 Beta2 first posted here:- http://forum.doom9.org/showthread.php?p=1782028#post1782028 # ### Function DetectSub_MI(clip c,string "Override", \ Int "X",Int "Y",Int "W",Int "H", \ Int "Text_w",Int "Text_h",Int "TextCol",Int "TextVar", \ Int "Halo_L",Int "Halo_T",Int "Halo_R",Int "Halo_B",Int "HaloCol",Int "HaloVar", \ Int "THysCNT",Int "HHysCNT",Int "DHysCNT",Bool "ShowInPand", \ Int "Baffle_w",Int "Baffle_h",Float "Thresh_w",Float "Thresh_h",Bool "ReScan", \ Bool "Show",Int "stack",Bool "ShowArea",Int "AreaColor",String "DB",Bool "Debug") { myName="DetectSub_MI: " c IsPlus=FindStr(VersionString,"AviSynth+")!=0 Assert(RT_FunctionExist("GScriptClip"),myName+"Essential GRunT plugin installed, http://forum.doom9.org/showthread.php?t=139337") Assert(IsPlus||RT_FunctionExist("GScript"),myName+"Essential GScript plugin installed, http://forum.doom9.org/showthread.php?t=147846") Assert(RT_FunctionExist("CallCmd"),myName+"Essential CallCmd plugin installed, http://forum.doom9.org/showthread.php?t=166063") Assert(RT_FunctionExist("mt_expand"),myName+"Essential MaskTools v2 plugin installed, http://forum.doom9.org/showthread.php?t=98985") Override=Default(OverRide,"") X=Default(X,0) Y=Default(Y,Height-120) W=Default(W,0) H=Default(H,-8) W=(W<=0)?Width-X+W:W H=(H<=0)?Height-Y+H:H Text_w=Default(Text_w,3) Text_h=Default(Text_h,3) TextCol=Default(TextCol,$FCFCFC) TextVar=Default(TextVar,3) Halo_L=Default(Halo_L,3) Halo_T=Default(Halo_T,4) Halo_R=Default(Halo_R,5) Halo_B=Default(Halo_B,6) HaloCol=Default(HaloCol,$030303) HaloVar=Default(HaloVar,3) THysCNT=Default(THysCNT,0) HHysCNT=Default(HHysCNT,0) DHysCNT=Default(DHysCNT,0) ShowInpand=(Show)?Default(ShowInpand,False):False Baffle_w=Default(Baffle_w,0) Baffle_h=Default(Baffle_h,0) Thresh_w=Default(Thresh_w,0.0) Thresh_h=Default(Thresh_h,0.0) ReScan=Default(ReScan,False) Show=Default(Show,False) Stack=(Show)?default(Stack,0):0 ShowArea=(Show)?Default(ShowArea,True):False AreaColor=Default(AreaColor,$FF00FF) DB=Default(DB,"") UserDB=(DB!="") DB=(!UserDB) ? "~"+RT_LocalTimeString+".DB" : DB DB=RT_GetFullPathName(DB) Debug=Default(Debug,False) VW=Width VH=Height /* Fields 0) Status, 0=Unknown (unvisited), 1=Sub, 2 Not sub, 3 User OverRide 1) X 2) Y 3) W 4) H */ RT_DBaseAlloc(DB,FrameCount,"iiiii") Function CnvStr(clip c) { Return c.IsRGB24?"ConvertToRGB24":c.IsRGB32?"ConvertToRGB32":c.IsYUY2?"ConvertToYUY2":c.IsYV12?"ConvertToYV12" \ :c.IsYV16?"c.ConvertToYV16":c.IsYV24?"c.ConvertToYV24":c.IsY8?"c.ConvertToY8":"" } CNVS=CnvStr(c) Assert(CNVS!="",RT_String("%sRGB24, RGB32, YUY2, YV12, YV16, YV24,and Y8 Only",myName)) Function ChrIsStar(String S) {return RT_Ord(S)==42} Function ChrIsNul(String S) {return RT_Ord(S)== 0} # End of String Function ChrIsHash(String S) {return RT_Ord(S)==35} # # Function ChrIsDigit(String S) {C=RT_Ord(S) return C>=48&&C<=57} FuncS=""" Function ChrEatWhite(String S) {i=1 C=RT_Ord(S,i) While(C==32||C>=8&&C<=13) {i=i+1 C=RT_Ord(S,i)} return i>1?MidStr(S,i):S} Function ChrEatDigits(String S) {i=1 C=RT_Ord(S,i) While(C>=48&&C<=57) {i=i+1 C=RT_Ord(S,i)} return i>1?MidStr(S,i):S} Function Fn@@@(clip c,String DB,Int VW,Int VH, \ int X,int Y,int W,int H,Int Text_w,Int Text_h,Int Halo_L,Int Halo_T,Int Halo_R,Int Halo_B, \ Int Baffle_w,Int Baffle_h,Float Thresh_w,Float Thresh_h,Bool ReScan, \ clip dc,bool Show,int Stack,bool ShowArea,Int AreaColor,bool Debug) { c n = current_frame Status = RT_DBaseGetField(DB,n,0) if(Show || Status <= 1) { # In here if Show or Status 0 or 1 (ie unvisited or Sub) if(Status==0) { # Unknown Status Bingo = dc.RT_YInRangeLocate(Baffle_w=Baffle_w,Baffle_h=Baffle_h, \ lo=255,hi=255,debug=Debug,Thresh_w=Thresh_w,Thresh_h=Thresh_h,ReScan=ReScan) Status=(Bingo)?1:2 if(Status==1) { RT_DBaseSet(DB,n,Status,X+YIRL_X,Y+YIRL_Y,YIRL_W,YIRL_H) } else { RT_DBaseSetField(DB,n,0,Status) } } if(Show) { if(Status==1) { SUB_X = RT_DBaseGetField(DB,n,1) SUB_Y = RT_DBaseGetField(DB,n,2) SUB_W = RT_DBaseGetField(DB,n,3) SUB_H = RT_DBaseGetField(DB,n,4) SUB_W=(SUB_W+1)/2*2 SUB_H=(SUB_H+1)/2*2 OverLay(Last.BlankClip(color=AreaColor,width=SUB_W,height=SUB_H),x=SUB_X,y=SUB_Y,opacity=0.25) RT_Subtitle("%d] Text @ x=%d y=%d w=%d h=%d",n,SUB_X,SUB_Y,SUB_W,SUB_H) } else if(Status==3) { RT_Subtitle("%d] User OverRide",n) } } } # End (Show || Status) Return Last } ####################################### # Unique Global Variables Initialization ####################################### if(OverRide!="") { if(ChrIsStar(Override)) {OverRide=MidStr(OverRide,2) } else { Assert(Exist(OverRide),RT_String("%sOverRide File does not exist",myName)) OverRide=RT_ReadTxtFromFile(Override) } LINES=RT_TxtQueryLines(OverRide) for(i=0,LINES-1) { SS=ChrEatWhite(RT_TxtGetLine(Override,i)) S=SS if(!ChrIsNul(S) && !ChrIsHash(S)) { if(ChrIsDigit(S)) { StartF = RT_NumberValue(S) EndF=StartF S=ChrEatWhite(ChrEatDigits(S)) if(ChrIsComma(S)){S=MidStr(S,2) S=ChrEatWhite(S)} if(ChrIsDigit(S)) { EndF=RT_NumberValue(S) S=ChrEatDigits(S) if(EndF==0) { EndF=FrameCount-1} Assert(StartF<=EndF,RT_String("%sError StartFrame(%d) > EndFrame(%d)",myName,StartF,EndF)) } (Debug)?RT_DebugF("OverRiding Range %d,%d to not detected",StartF,EndF,name=myName):NOP for(n=StartF,EndF) {RT_DBaseSetField(DB,n,0,3)} } S=ChrEatWhite(S) if(ChrIsHash(S)) {S=""} Assert(ChrIsNul(S),RT_String("%s *** NON-PARSE *** Error in Override Line %d\n'%s'",myName,i+1,SS)) } } } rgb=ConvertToRGB32.Crop(X,Y,W,H).ResetMask # Reset Alpha to White Txt=rgb.ColorKeyMask(TextCol,TextVar+1,TextVar+1,TextVar+1).ShowAlpha(Pixel_Type="Y8") # Set in range pixels to black Hal=rgb.ColorKeyMask(HaloCol,HaloVar+1,HaloVar+1,HaloVar+1).ShowAlpha(Pixel_Type="Y8") Txt=Txt.Invert # In range pixels white, else black Hal=Hal.Invert CHROMAPROC = "-128" HALO_MAX=Max(HALO_L,HALO_T,HALO_R,HALO_B) for(i=1,HALO_MAX) { HorFlg=(i<=HALO_L?1:0)+(i<=HALO_R?2:0) VerFlg=(i<=HALO_T?1:0)+(i<=HALO_B?2:0) if(HorFlg+VerFlg==6) {TXT=TXT.Mt_Expand(mode="square", chroma=CHROMAPROC) } else { if(HorFlg==3) {TXT=TXT.Mt_Expand(mode="horizontal", chroma=CHROMAPROC) HorFlg=0} if(VerFlg==3) {TXT=TXT.Mt_Expand(mode="vertical", chroma=CHROMAPROC) VerFlg=0} if(HorFlg!=0) {TXT=TXT.Mt_Expand(mode=HorFlg==1? " 1 0 0 0" : " -1 0 0 0", chroma=CHROMAPROC) } if(VerFlg!=0) {TXT=TXT.Mt_Expand(mode=VerFlg==1? " 0 1 0 0" : " 0 -1 0 0" , chroma=CHROMAPROC) } } } TEXT_MAX=Max(TEXT_W,TEXT_H) for(i=1,TEXT_MAX) { HorFlg=(i<=TEXT_W?1:0) VerFlg=(i<=TEXT_H?1:0) if(HorFlg+VerFlg==2) {HAL=HAL.Mt_Expand(mode="square", chroma=CHROMAPROC) } else { if(HorFlg!=0) {HAL=HAL.Mt_Expand(mode="horizontal", chroma=CHROMAPROC) } if(VerFlg!=0) {HAL=HAL.Mt_Expand(mode="vertical", chroma=CHROMAPROC) } } } # reduce strays a little WeeTxt=Txt WeeHal=Hal if(THysCNT>0) { For(i=1,THysCNT) {WeeTxt=WeeTxt.MT_Inpand(mode="both",chroma=CHROMAPROC)} Txt=WeeTxt.MT_Hysteresis(Txt,chroma=CHROMAPROC) } if(HHysCNT>0) { For(i=1,HHysCNT) {WeeHal=WeeHal.MT_Inpand(mode="both",chroma=CHROMAPROC)} Hal=WeeHal.MT_Hysteresis(Hal,chroma=CHROMAPROC) } dc=Mt_Logic(Txt,Hal,"and", chroma=CHROMAPROC) dc2=dc if(DHysCNT>0) { For(i=1,DHysCNT) {dc2=dc2.MT_Inpand(mode="both",chroma=CHROMAPROC)} dc=dc2.MT_Hysteresis(dc,chroma=CHROMAPROC) dc2 = (ShowInPand) ? dc2 : dc } if(Show && (Stack>=1 && Stack<=2)) { If(ShowInPand) {Txt=WeeTxt Hal=WeeHal} dc2=dc2.Eval(CnvS).AddBorders(X,0,Width-X-W,0).AddBorders(0,22,0,0,$C0C0C0).Subtitle("DETECT",y=2) if(Stack==2) { TXT = TXT.Eval(CnvS).AddBorders(X,0,Width-X-W,0).AddBorders(0,22,0,0,$C0C0C0).Subtitle("TEXT",y=2) HAL = HAL.Eval(CnvS).AddBorders(X,0,Width-X-W,0).AddBorders(0,22,0,0,$C0C0C0).Subtitle("HALO",y=2) c=StackVertical(Last,dc2,TXT,HAL) } else { c=StackVertical(Last,dc2) } } else {c=Last} if(Show&&ShowArea) { WW=(W+1)/2*2 HH=(H+1)/2*2 # YV12 Legal Msk=c.Blankclip(width=WW+2,height=HH+2,Length=1,pixel_type="YV12").Killaudio Infix=RT_string("(((x<=1|x>=%d|y<=1|y>=%d)&(x<4|x>=%d)&(y<4|y>=%d)|(x==0|x==%d|y==0|y==%d)))?255:0", W-2,H-2,W-4,H-4,W-1,H-1) Msk=Msk.mt_lutspa(relative = false,yExpr=mt_Polish(InFix), chroma = CHROMAPROC) Mrk=Msk.BlankClip(Color=AreaColor) Msk=Msk.Loop(FrameCount,0,0) Mrk=Mrk.Loop(FrameCount,0,0) c=c.Overlay(Mrk,x=X-1,y=Y-1,Mask=Msk,Mode="Blend",Opacity=0.5) } RT_DBaseSetID(DB,0,c.FrameCount,c.FrameRate,VW,VH,X,Y,W,H) ####################################### # Unique Runtime Call, GScriptClip must be a one-liner: ####################################### ARGS="DB,VW,VH,X,Y,W,H,Text_w,Text_h,Halo_L,Halo_T,Halo_R,Halo_B,Baffle_w,Baffle_h,Thresh_w,Thresh_h,ReScan,dc,Show,Stack,Showarea,AreaColor,debug" c.GScriptClip("Fn@@@(last, "+ARGS+")", local=true, args=ARGS) return Last """ ####################################### # Unique Identifier Definition ####################################### GIFunc="DetectSub_MI" # Function Name, Supply unique name for your multi-instance function. GIName=GIFunc+"_InstanceNumber" # Name of the Instance number Global RT_IncrGlobal(GIName) # Increment Instance Global (init to 1 if not already exists) GID = GIFunc + "_" + String(Eval(GIName)) InstS = RT_StrReplace(FuncS,"@@@","_"+GID) # RT_WriteFile("DEBUG_"+GID+".TXT","%s",InstS) (!IsPlus) ? GEval(InstS) : Eval(InstS) (!UserDB)?CallCmd(close=RT_String("""CMD /C chcp 1252 && del "%s" """,DB), hide=true, Synchronous=7):NOP # Auto delete non-User DB file on clip closure. Return Last }
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 14th August 2021 at 02:56. Reason: error setting chroma to "1", changed to "-128" |
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
Display Modes | |
|
|