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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 10th February 2018, 17:25   #1  |  Link
Atak_Snajpera
RipBot264 author
 
Atak_Snajpera's Avatar
 
Join Date: May 2006
Location: Poland
Posts: 6,450
[AviSynth+] Need help with rendering subtitles on YUV420P10

VSFilter does not work with 10 bit so I'm trying to overlay subtitles manually.

My code
Code:
SubtitleColor=BlankClip(video,color=$FFFF00,pixel_type="RGB32") 
SubtitleMask=BlankClip(video,color=$000000,pixel_type="RGB32") 

Loadplugin("C:\Users\Dave\Documents\Delphi_Projects\RipBot264\_Compiled\Tools\AviSynth plugins\VSFilter\VSFilter.dll")
SubtitleMask=VobSub(SubtitleMask,"C:\Temp\RipBot264temp\job1\5_subtitles_English_1080.sub")

SubtitleColor=ConvertToYUV420(SubtitleColor,matrix="Rec2020").ConvertBits(10)
SubtitleMask=ConvertToYUV420(SubtitleMask,matrix="Rec2020").ConvertBits(10)

video=Overlay(video,SubtitleColor,mask=SubtitleMask,opacity=1)
Result


Original


As you can see there is problem with mask because yellow color is not entirely removed. I reckon that it's a problem with 255 (8bit) vs 1023 scale (10bit) after conversion from RGB.
Can some expert help me to correct this issue?

Last edited by Atak_Snajpera; 10th February 2018 at 17:33.
Atak_Snajpera is online now   Reply With Quote
Old 10th February 2018, 17:59   #2  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,365
Yes, I've had this experience. Use mt_inpand.
raffriff42 is offline   Reply With Quote
Old 10th February 2018, 19:12   #3  |  Link
Yanak
Registered User
 
Join Date: Oct 2011
Posts: 199
Can't try for now but what version of VSfilter is used, r4 ?

The R5 version might help maybe, if it's not already the one used
https://github.com/sorayuki/VSFilterMod/releases
binaries here : https://www.nmm-hd.org/newbbs/viewtopic.php?f=17&t=1989

Edit : Nevermind, YUV420P10 is supported only for vapoursynth it seems , sorry.

Last edited by Yanak; 10th February 2018 at 19:15.
Yanak is offline   Reply With Quote
Old 10th February 2018, 19:32   #4  |  Link
Atak_Snajpera
RipBot264 author
 
Atak_Snajpera's Avatar
 
Join Date: May 2006
Location: Poland
Posts: 6,450
I think I figured out how to overlay subtitles correctly on YUV420P10!

Code:
#Subtitles
Loadplugin("C:\Users\Dave\Documents\Delphi_Projects\RipBot264\_Compiled\Tools\AviSynth plugins\VSFilter\VSFilter.dll")
SubtitleColor=BlankClip(video,color=$FFFF00).Tweak(sat=0.5) 
SubtitleMask=BlankClip(video,color=$000000,pixel_type="YV12") 
SubtitleMask=VobSub(SubtitleMask,"C:\Temp\RipBot264temp\job1\5_subtitles_English_1080.sub")
SubtitleMask=Grayscale(SubtitleMask).ConvertBits(10)
SubtitleMask=Levels(SubtitleMask,0, 0.25, 768, 0,1023, coring=false) 
video=Overlay(video,SubtitleColor,mask=SubtitleMask,opacity=1)
Result

Last edited by Atak_Snajpera; 11th February 2018 at 13:58.
Atak_Snajpera is online now   Reply With Quote
Old 11th February 2018, 09:51   #5  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,560
Looking at the text in the subtitles make me curious... What movie is that ?
jpsdr is offline   Reply With Quote
Old 11th February 2018, 10:26   #6  |  Link
Sparktank
47.952fps@71.928Hz
 
Sparktank's Avatar
 
Join Date: Mar 2011
Posts: 819
Quote:
Originally Posted by jpsdr View Post
Looking at the text in the subtitles make me curious... What movie is that ?
I think that's Passengers? With Chris Pratt?
__________________
Win10 (x64) | GPU Caps Viewer v1.38.2.1
Crucial M500 240GB SSD | Kingston SSDNow V300 (Marvell) 120GB | NVIDIA GeForce GTX 750 Ti 2GB | 391.01 (2-23-2018)
NTSC | DVD: R1 | BD: A
Sparktank is offline   Reply With Quote
Old 11th February 2018, 12:18   #7  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,560
Now that you said it... Indeed, it must be.
jpsdr is offline   Reply With Quote
Old 11th February 2018, 14:08   #8  |  Link
Atak_Snajpera
RipBot264 author
 
Atak_Snajpera's Avatar
 
Join Date: May 2006
Location: Poland
Posts: 6,450
Do you know guys a good and fast anti-aliasing filter? Something similar to FXAA? I would like to smooth a little bit mask without using simple blur.
zoom 200%

Last edited by Atak_Snajpera; 11th February 2018 at 14:28.
Atak_Snajpera is online now   Reply With Quote
Old 11th February 2018, 15:12   #9  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,365
> a good and fast anti-aliasing filter? Something similar to FXAA?

Don't know if it's fast enough for you, but
Quote:
Originally Posted by feisty2 View Post
Upscale with eedi3 (sclip=nnedi3()) and then scale it back
Repeat it for a few times
My implementation of feisty2's idea, called pow2Qt, here.
raffriff42 is offline   Reply With Quote
Old 11th February 2018, 15:21   #10  |  Link
Atak_Snajpera
RipBot264 author
 
Atak_Snajpera's Avatar
 
Join Date: May 2006
Location: Poland
Posts: 6,450
When I see eedi3 I know that It will be too slow. For now I'm using Sharpen(-1). To bad that after all those years we still do not have FXAA/SMAA in avisynth.
Atak_Snajpera is online now   Reply With Quote
Old 11th February 2018, 17:19   #11  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,365
Don't think FXAA can work on a bitmap, but SMAA is a post-process shader AA.
Maybe MysteryX's AviSynth Shader can help. (I'd be interested in that, myself)
raffriff42 is offline   Reply With Quote
Old 11th February 2018, 18:17   #12  |  Link
Atak_Snajpera
RipBot264 author
 
Atak_Snajpera's Avatar
 
Join Date: May 2006
Location: Poland
Posts: 6,450
Both FXAA and SMAA work as post-process AA.
Atak_Snajpera is online now   Reply With Quote
Old 15th February 2018, 16:33   #13  |  Link
nautilus7
Registered User
 
nautilus7's Avatar
 
Join Date: Jan 2006
Location: Athens, Greece
Posts: 1,506
I used to smooth my subtitles using one of the 2 methods:

1. GaussianBlur()
2. Render the subs in 2x resolution and then doing a GaussResize() at half resolution.

It worked fine, but I wouldn't say it was fast.
nautilus7 is offline   Reply With Quote
Old 16th February 2018, 08:32   #14  |  Link
`Orum
Registered User
 
Join Date: Sep 2005
Posts: 133
Quote:
Originally Posted by Atak_Snajpera View Post
Do you know guys a good and fast anti-aliasing filter? Something similar to FXAA?
While I totally agree about the need for FXAA/SMAA and friends for AviSynth (perhaps I'll port them over at some point), for what you're doing they seem unnecessary. A better approach for subtitles is to OCR them and include them in a text-based format, e.g. SRT or ASS formats. The only reasons not to do so that I can think of is laziness (you can't be bothered to OCR), or playback speed/support on devices.
__________________
My filters: DupStep | PointSize
`Orum is offline   Reply With Quote
Old 20th February 2018, 00:08   #15  |  Link
kolak
Registered User
 
Join Date: Nov 2004
Location: UK
Posts: 2,264
Quote:
Originally Posted by nautilus7 View Post
I used to smooth my subtitles using one of the 2 methods:

1. GaussianBlur()
2. Render the subs in 2x resolution and then doing a GaussResize() at half resolution.

It worked fine, but I wouldn't say it was fast.
This is quite effective way. I use to do the same.
kolak is offline   Reply With Quote
Old 23rd February 2018, 12:04   #16  |  Link
Atak_Snajpera
RipBot264 author
 
Atak_Snajpera's Avatar
 
Join Date: May 2006
Location: Poland
Posts: 6,450
In case you are interested here is my final function

Code:
function TextSubHDR(clip video, string "SubPath", int "SubColor", int "SubOutlineColor", int "SubShadowColor" )
{
SubtitleColor=BlankClip(video,color=SubColor,pixel_type="YUV420P10")
OutlineColor=BlankClip(video,color=SubOutlineColor,pixel_type="YUV420P10")
ShadowColor=BlankClip(video,color=SubShadowColor,pixel_type="YUV420P10")

SubtitleOutlineColor=BlankClip(video,color=$FFFFFF,pixel_type="YV12")
SubtitleOutlineMask=BlankClip(video,color=$000000,pixel_type="YV12")

SubtitleMask=BlankClip(video,color=$000000,pixel_type="YV12")
SubtitleMask=TextSub(SubtitleMask,SubPath,-1)
SubtitleMask=Grayscale(SubtitleMask).ConvertToYV24

OutlineMask=AddBorders(SubtitleMask,1,0,0,0).Crop(0,0,-1,0)
SubtitleOutlineMask=Overlay(SubtitleOutlineMask,SubtitleOutlineColor,mask=OutlineMask,opacity=1)

OutlineMask=AddBorders(SubtitleMask,0,1,0,0).Crop(0,0,0,-1)
SubtitleOutlineMask=Overlay(SubtitleOutlineMask,SubtitleOutlineColor,mask=OutlineMask,opacity=1)

OutlineMask=Crop(SubtitleMask,1,0,0,0).AddBorders(0,0,1,0)
SubtitleOutlineMask=Overlay(SubtitleOutlineMask,SubtitleOutlineColor,mask=OutlineMask,opacity=1)

OutlineMask=Crop(SubtitleMask,0,1,0,0).AddBorders(0,0,0,1)
SubtitleOutlineMask=Overlay(SubtitleOutlineMask,SubtitleOutlineColor,mask=OutlineMask,opacity=1)

SubtitleOutlineMask=ConvertBits(SubtitleOutlineMask,10)
SubtitleOutlineMask=Levels(SubtitleOutlineMask,128, 1, 896, 0,1023, coring=false)

SubtitleMask=ConvertToYV12(SubtitleMask).ConvertBits(10)
SubtitleMask=Levels(SubtitleMask,128, 1, 896, 0,1023, coring=false)

ShadowMask=AddBorders(SubtitleMask,2,2,0,0).Crop(0,0,-2,-2)

video=Overlay(video,ShadowColor,mask=ShadowMask,opacity=0.5)
video=Overlay(video,OutlineColor,mask=SubtitleOutlineMask,opacity=1)
video=Overlay(video,SubtitleColor,mask=SubtitleMask,opacity=1)

return video
}
usage
Code:
Loadplugin("VSFilter.dll")
Import("TextSubHDR.avs")
video=TextSubHDR(video,"Passengers.srt",$C0C0C0)
Examples (.srt)


(.ass)

Last edited by Atak_Snajpera; 23rd February 2018 at 12:17.
Atak_Snajpera is online now   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 17:59.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.