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. |
![]() |
#1 | Link |
Registered User
Join Date: Mar 2014
Location: Hungary
Posts: 108
|
Making a mask to remove hardsubs
Hi!
I have two video sources. The first source has good picture quality and hardcoded subs, the second source has low PQ but it does not contain hardsubs. I want to remove the hardsubs from the video and replacing the texts with actual video. This is my script so far: Code:
a=FFMS2("X:\DL\hardsub.mkv") b=FFMS2("X:\DL\nohardsub.mkv") mask=Subtract(a,b).Levels(0, 0.16, 255, 0, 255, coring=true) Overlay(a,b,0,0,mask) Here are some frames: video with good PQ video with bad PQ difference between them after tweaking it with levels using the mask to Overlay the text So my questions are: How can I make the mask pure black and white? Is there any script that turns the image into 1 bit? How can I expand the mask with for example 10-15 pixels? I tried to mess with mt_expand but no luck so far. |
![]() |
![]() |
![]() |
#2 | Link |
Formerly davidh*****
Join Date: Jan 2004
Posts: 2,465
|
There's such a microscopic difference between those two frames that I have to ask if it's really worth it - or if other scenes show a much bigger difference in quality. Presumably you're going to be re-encoding, so you may find out your re-encode looks just as "bad" as the one you've called bad, if the whole thing has such a small difference.
You'll need to do some more tweaking, anyway, since your "tweaked" difference frame doesn't include the drop shadow - maybe invert() and then use overlay with mode="lighten". binarize in Masktools will do the black/white thing, or you can probably achieve the same thing with careful use of levels(). But you'll also need to spread out the mask a bit, otherwise you'll get some ghostly subtitle outlines. |
![]() |
![]() |
![]() |
#3 | Link |
Registered User
Join Date: Mar 2014
Location: Hungary
Posts: 108
|
At other scenes the difference between the two sources is more visible so it's worth the effort. I'll use good settings to make it transparent to the source script.
Code:
Subtract(a,b).mt_binarize(170) ![]() ![]() |
![]() |
![]() |
![]() |
#6 | Link | ||
Registered User
Join Date: Sep 2007
Posts: 5,257
|
Quote:
Hint : It tells you in the instructions ![]() Quote:
|
||
![]() |
![]() |
![]() |
#10 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,806
|
This detects subs, but only if they have a halo, was never completed, op closed thread.
https://forum.doom9.org/showthread.p...36#post1782036 EDIT: Finds halo color and swells all instances several pixels, does the same with the text color, where both swellings overlap (halo swells into text, and text swells into halo), then you have detected subtitle. EDIT: Detector works, just never did repair script.
__________________
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; 23rd October 2018 at 22:39. |
![]() |
![]() |
![]() |
#11 | Link |
Registered User
Join Date: Mar 2014
Location: Hungary
Posts: 108
|
It turned out that
Code:
Levels(0, 0.01, 250, 0, 255).Crop(200,800,-200,-50).AddBorders(200,800,200,50).mt_binarize(180).mt_expand_multi(mode="ellipse",sw=8,sh=8,u=-128,v=-128) StainlessS, could you recommend settings to DetectSub_MI() ? ![]() |
![]() |
![]() |
![]() |
#12 | Link | ||
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,806
|
These are the important ones, but dependent upon your clip/subs.
Code:
# Subtitle coords X = 180 Y = Height-140 W = -X H = -44 # Text, Halo color 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 # Text pixel width,height 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 pixel width,height HALO_L = 5 # Left Halo width in pixels HALO_R = 5 # Right Halo width in pixels HALO_T = 5 # Top Halo height in pixels HALO_B = 5 # Bot Halo height in pixels # Mt_Hysteresis (reduce stray pixels):- http://forum.doom9.org/showthread.php?p=1780589#post1780589 THYSCNT = 5 # Text Mask Mt_Hysteresis inpand count (prior to mt_hysteresis), Dont Mt_Hysteresis if 0 HHYSCNT = 5 # Halo Mask Mt_Hysteresis inpand count (prior to mt_hysteresis), Dont Mt_Hysteresis if 0 DHYSCNT = 5 # Detect clip Mt_Hysteresis inpand count (prior to mt_hysteresis), Dont Mt_Hysteresis if 0 Code:
THRESH_W = -(Text_w+(Halo_L+Halo_R)/2) # -ve, specifies Abs(Pixel width) {Else +ve = Percent width 0.0->100.0%) {0.0=any pixel in range) THRESH_H = -(Text_h+(Halo_T+Halo_B)/2) # -ve, specifies Abs(Pixel Height) {Else +ve = Percent width 0.0->100.0%) {0.0=any pixel in range) # BAFFLE_W = Text_w+Halo_L+Halo_R-2 # Width of outermost Vertical edges. BAFFLE_H = Text_h+Halo_T+Halo_B # Height of outermost Horizontal edges. Might be an amount of playing with settings to get it to work. EDIT: Quote:
Quote:
__________________
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; 28th October 2018 at 17:43. |
||
![]() |
![]() |
![]() |
#13 | Link |
Registered User
Join Date: Mar 2014
Location: Hungary
Posts: 108
|
I tried this script:
Code:
X = 200 Y = 800 W = -X H = -50 TEXTCOL = $FEFEFE TEXTVAR = 2 # Text RGB channels can vary by as much as TEXTVAR, eg $FEFEFE with TEXTVAR=1 ranges $FDFDFD -> $FFFFFF HALOCOL = $000000 HALOVAR = 2 # Halo RGB channels can vary by as much as HALOVAR, eg $FEFEFE with HALOVAR=1 ranges $FDFDFD -> $FFFFFF 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_L = 5 # Left Halo width in pixels HALO_R = 5 # Right Halo width in pixels HALO_T = 5 # Top Halo height in pixels HALO_B = 5 # Bot Halo height in pixels THYSCNT = 5 # Text Mask Mt_Hysteresis inpand count (prior to mt_hysteresis), Dont Mt_Hysteresis if 0 HHYSCNT = 5 # Halo Mask Mt_Hysteresis inpand count (prior to mt_hysteresis), Dont Mt_Hysteresis if 0 DHYSCNT = 5 # Detect clip Mt_Hysteresis inpand count (prior to mt_hysteresis), Dont Mt_Hysteresis if 0 THRESH_W = -(Text_w+(Halo_L+Halo_R)/2) # -ve, specifies Abs(Pixel width) {Else +ve = Percent width 0.0->100.0%) {0.0=any pixel in range) THRESH_H = -(Text_h+(Halo_T+Halo_B)/2) # -ve, specifies Abs(Pixel Height) {Else +ve = Percent width 0.0->100.0%) {0.0=any pixel in range) BAFFLE_W = Text_w+Halo_L+Halo_R-2 # Width of outermost Vertical edges. BAFFLE_H = Text_h+Halo_T+Halo_B # Height of outermost Horizontal edges. RESCAN = true # Switching on might get rid of the odd stray pixel (most likely not, was already pretty good, suggest always on). SHOW = true # Show metrics. AREACOLOR = $8040FF # Subtitle area marker color SHOWAREA = true # Set True to mark subtitle scan area. (Show=False:No Effect) STACK = 2 # 0=Movie, 1=Movie + detection clip, 2=Movie detection clip + Text and Halo Mask clips. (Show=False:No Effect) SHOWINPAND = false # Show Mt_Inpand masks without doing Mt_Hysteresis, ie for THysCnt, HHysCnt, DHysCnt. (Show=False:No Effect) DB = "MyDB.DB" # If Named, then DB not deleted on exit. (Maybe DBase used by other scripts later) DEBUG = false # To DebugView (Google). RT_ v2.00 beta02 extends RT_YInRangeLocate() debug info a little. OverRide = "" # ""=Not used, "*..." multiline string of ranges, "OverRide.txt"=Text file of ranges. DetectSub_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, \ THysCnt=THYSCNT,HHysCnt=HHYSCNT,DHysCnt=DHYSCNT,ShowInPand=SHOWINPAND, \ Baffle_w=BAFFLE_W,Baffle_h=BAFFLE_H,Thresh_w=THRESH_W,Thresh_h=THRESH_H,ReScan=RESCAN, \ Show=SHOW,stack=STACK,ShowArea=SHOWAREA,AreaColor=AREACOLOR,db=DB,Debug=DEBUG) ![]() Should I modify the mt_expand lines to mt_expand_multi or change them to ConvertYV12().mt_expand? |
![]() |
![]() |
![]() |
#14 | Link |
Registered User
Join Date: Mar 2014
Location: Hungary
Posts: 108
|
And why do I see pale colors if I only use mt_binarize?
![]() https://vgy.me/9gQ2Nb.png If I use mt_expand_multi after mt_binarize it gets rid of the pale colors, but still weird. Last edited by pcroland; 28th October 2018 at 19:52. |
![]() |
![]() |
![]() |
#15 | Link | |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,806
|
Quote:
Post the same frame as source clip (avi saved with UT_Video codec "ULY0" FOURCC). EDIT: Code:
TEXTCOL = $FEFEFE TEXTVAR = 2 EDIT: I think that the original script function was to find the rectangle where the subtitle lived, rather than a mask for just the subtitle. Rectangle saved into the DBase for a second scan for fixing that rectangle.
__________________
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; 28th October 2018 at 22:14. |
|
![]() |
![]() |
![]() |
#16 | Link | |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,806
|
This detects on your first posted image.
Code:
### # DetectSub.MI_Client.avs" ### Import(".\DetectSub_MI.avsi") ImageSource("D:\jlS191.png",end=0).ConvertToYV12 X = 640 Y = 700 W = 700 H = 210 #return Overlay(Last.BlankClip(width=w,Height=h),x=x,y=y,opacity=0.3) TEXTCOL = $FAFAFA TEXTVAR = 5 # Text RGB channels can vary by as much as TEXTVAR, eg $FEFEFE with TEXTVAR=1 ranges $FDFDFD -> $FFFFFF HALOCOL = $080808 HALOVAR = 8 # Halo RGB channels can vary by as much as HALOVAR, eg $FEFEFE with HALOVAR=1 ranges $FDFDFD -> $FFFFFF TEXT_W = 5 # minimum text pixel 'thickness' Horizontal (horizontal thickness of vertical strokes) TEXT_H = 5 # 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 THYSCNT = 0 # Text Mask Mt_Hysteresis inpand count (prior to mt_hysteresis), Dont Mt_Hysteresis if 0 HHYSCNT = 0 # Halo Mask Mt_Hysteresis inpand count (prior to mt_hysteresis), Dont Mt_Hysteresis if 0 DHYSCNT = 0 # Detect clip Mt_Hysteresis inpand count (prior to mt_hysteresis), Dont Mt_Hysteresis if 0 THRESH_W = -8 # -ve, specifies Abs(Pixel width) {Else +ve = Percent width 0.0->100.0%) {0.0=any pixel in range) THRESH_H = -8 # -ve, specifies Abs(Pixel Height) {Else +ve = Percent width 0.0->100.0%) {0.0=any pixel in range) BAFFLE_W = 10 # Width of outermost Vertical edges. BAFFLE_H = 10 # Height of outermost Horizontal edges. RESCAN = true # Switching on might get rid of the odd stray pixel (most likely not, was already pretty good, suggest always on). SHOW = true # Show metrics. AREACOLOR = $8040FF # Subtitle area marker color SHOWAREA = true # Set True to mark subtitle scan area. (Show=False:No Effect) STACK = 2 # 0=Movie, 1=Movie + detection clip, 2=Movie detection clip + Text and Halo Mask clips. (Show=False:No Effect) SHOWINPAND =true # Show Mt_Inpand masks without doing Mt_Hysteresis, ie for THysCnt, HHysCnt, DHysCnt. (Show=False:No Effect) DB = "MyDB.DB" # If Named, then DB not deleted on exit. (Maybe DBase used by other scripts later) DEBUG = false # To DebugView (Google). RT_ v2.00 beta02 extends RT_YInRangeLocate() debug info a little. OverRide = "" # ""=Not used, "*..." multiline string of ranges, "OverRide.txt"=Text file of ranges. DetectSub_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, \ THysCnt=THYSCNT,HHysCnt=HHYSCNT,DHysCnt=DHYSCNT,ShowInPand=SHOWINPAND, \ Baffle_w=BAFFLE_W,Baffle_h=BAFFLE_H,Thresh_w=THRESH_W,Thresh_h=THRESH_H,ReScan=RESCAN, \ Show=SHOW,stack=STACK,ShowArea=SHOWAREA,AreaColor=AREACOLOR,db=DB,Debug=DEBUG) ![]() I got your PM''ed MKV's, one is 25FPS, other 23.976, given how close they are to each other, think I would go with what DavidHorman said, Quote:
EDIT: The detector works better with colored halo, which is what it was written for (I think, white and black are a little too common). Anyway, locates the rectangle (in purple) which is what it was intended to do. EDIT: DBase fields set for each frame/record., (purple area, X,Y,W,H), set after complete clip scan. Code:
/* Fields 0) Status, 0=Unknown (unvisited), 1=Sub, 2 Not sub, 3 User OverRide 1) X 2) Y 3) W 4) H */ Code:
AviSource("...") DB = "MyDB.DB" SSS=""" n=current_frame Stat=RT_DBaseGetField(DB,n,0) if(Stat == 1) { X=RT_DBaseGetField(DB,n,1) Y=RT_DBaseGetField(DB,n,2) W=RT_DBaseGetField(DB,n,3) H=RT_DBaseGetField(DB,n,4) RT_Subtitle("%d] X=%d Y=%d W=%d H=%d",n,x,y,w,h) } """ ScriptClip(SSS)
__________________
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; 1st November 2018 at 20:35. |
|
![]() |
![]() |
![]() |
Tags |
hardsub, mask, mt_expand, overlay, remove |
Thread Tools | Search this Thread |
Display Modes | |
|
|