View Single Post
Old 7th September 2016, 07:18   #24  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
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
Perhaps you'de like to post several minutes with plenty of subs (maybe max 200->300MB), cut using eg DGIndex, mark section with '[' and ']',
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.
StainlessS is offline   Reply With Quote