Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AviSynth DeSub - automatic hardcoded subtitles removal
#1
Star 
DeSub - automatic hardcoded subtitles removal (Avisynth script)

Is it too good to be true? Well, it needs two clips, one with subtitles (or logo), and the other without; will create a mask "on the fly", and the subtitles (logo) will be replaced with the corresponding part of the image of the clip without logo.

For best result, it's better to limit usage only to frames with subtitles; clips must be aligned perfectly, both temporally and spatially; must have the same (or very similar) colors; it's always possible to merge the result and the existing not subbed clip to improve quality.

Save it as DeSub.avsi and put into your AviSynth plugins folder.

Code:
###########################################################################################
### DeSub 1.0: removes the subtitles with no need to prepare a mask for every line!     ###
###                                                                                     ###
### Two spatially and aligned clips are needed, one with hardcoded subtitles, or logo,  ###
### and the other without; the script creates a mask "on the fly" that will be used to  ###
### cover the subtitles with the corresponding parts of the clip without them.          ###
###                                                                                     ###
### Usage:   DeSub(clipwithsubs,clipwithoutsubs,subcolor)                               ###
###                                                                                     ###
### Example: goodclip.avi has subtitles, badclip.avi has no subtitles, subs color white ###
###                                                                                     ###
###          DeSub(goodclip,badclip,$ffffff)                                            ###
###                                                                                     ###
### It is highly reccomended to use it only on frames with subtitles                    ###
### Possible update: limit the use to a certain area of the frame, perfect for logo!    ###                                                  
###                                                                                     ###
### AviSynth script made by spoRv (http://blog.sporv.com) - Created: 2016-11-29         ###
###                                                                                     ###
### Creative Commons 4,0 - Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)      ###
### Link to the licence page: https://creativecommons.org/licenses/by-sa/4.0/           ###
###########################################################################################

function DeSub (clip withsubs, clip nosubs, val "color") {

withsubs=withsubs.converttoyv24
nosubs=nosubs.converttoyv24
color=default(color,$ffffff)

subs = withsubs.converttorgb

mask = ColorKeyMask(subs, color, 20)
blk = blankclip(length=withsubs.FrameCount,width=withsubs.width,height=withsubs.height)

over=Overlay(withsubs, blk, mask=mask.ShowAlpha, mode="blend", opacity=1)

mk=over.levels(235,1,255,1,255)

w=2

a=mk.addborders(0,0,w,w).crop(w,w,0,0)
b=mk.addborders(0,0,0,w).crop(0,w,0,0)
c=mk.addborders(w,0,0,w).crop(0,w,-w,0)
d=mk.addborders(w,0,0,0).crop(0,0,-w,0)
e=mk.addborders(w,w,0,0).crop(0,0,-w,-w)
f=mk.addborders(0,w,0,0).crop(0,0,0,-w)
g=mk.addborders(0,w,w,0).crop(w,0,0,-w)
h=mk.crop(w,0,0,0).addborders(0,0,w,0)

x= overlay(b, f, mode="add")
y= overlay(d, h, mode="add")
xx=overlay(a, e, mode="add")
yy=overlay(c, g, mode="add")
z= overlay(x, y, mode="add")
zz=overlay(xx,yy,mode="add")

nu=overlay(z,zz,mode="add")

mk=nu.levels(235,1,255,1,255)

w=3

a=mk.addborders(0,0,w,w).crop(w,w,0,0)
b=mk.addborders(0,0,0,w).crop(0,w,0,0)
c=mk.addborders(w,0,0,w).crop(0,w,-w,0)
d=mk.addborders(w,0,0,0).crop(0,0,-w,0)
e=mk.addborders(w,w,0,0).crop(0,0,-w,-w)
f=mk.addborders(0,w,0,0).crop(0,0,0,-w)
g=mk.addborders(0,w,w,0).crop(w,0,0,-w)
h=mk.crop(w,0,0,0).addborders(0,0,w,0)

x= overlay(b, f, mode="add")
y= overlay(d, h, mode="add")
xx=overlay(a, e, mode="add")
yy=overlay(c, g, mode="add")
z= overlay(x, y, mode="add")
zz=overlay(xx,yy,mode="add")

nu=overlay(z,zz,mode="add")

mk=nu.levels(235,1,255,1,255)

w=4

a=mk.addborders(0,0,w,w).crop(w,w,0,0)
b=mk.addborders(0,0,0,w).crop(0,w,0,0)
c=mk.addborders(w,0,0,w).crop(0,w,-w,0)
d=mk.addborders(w,0,0,0).crop(0,0,-w,0)
e=mk.addborders(w,w,0,0).crop(0,0,-w,-w)
f=mk.addborders(0,w,0,0).crop(0,0,0,-w)
g=mk.addborders(0,w,w,0).crop(w,0,0,-w)
h=mk.crop(w,0,0,0).addborders(0,0,w,0)

x= overlay(b, f, mode="add")
y= overlay(d, h, mode="add")
xx=overlay(a, e, mode="add")
yy=overlay(c, g, mode="add")
z= overlay(x, y, mode="add")
zz=overlay(xx,yy,mode="add")

nu=overlay(z,zz,mode="add").levels(235,1,255,1,255)

numask = ColorKeyMask(nu.ConvertToRGB32, color, 30)

Overlay(nosubs, withsubs, mask=numask.ShowAlpha, mode="blend", opacity=1)

converttoyv12

}

I tested it, and seems to work well; of course, could still be improved. Waiting for your test results and impressions!

Examples - top DeSub result, bottom original:

[Image: desub2.jpg]

[Image: desub4.jpg]

[Image: desub3.jpg]

[Image: desub1.jpg]
Reply
Thanks given by:


Forum Jump:


Users browsing this thread: 1 Guest(s)