Log in

View Full Version : alternative to, or better use of, core.text.Text ?


hydra3333
25th August 2016, 12:40
Hello. Dummy seeking more advice, this time about core.text.Text

I converted hacked a few home-grown debug type functions from avisynth to what I hoped were equivalent vapoursynth ones (attached).
The avisynth versions of the functions use subtitle to "overlay" the text nicely so nothing is obscured too much.
The vapoursynth versions use core.text.Text which puts rather obscuring black boxes around the text, which isn't very handy for the purpose of those debug functions.
Suggestions would be welcomed on how to make the text appearance more "friendly".

eg
def xBox4(clipa=None, aSub='clip a', clipb=None, bSub='clip b'):
icore = vs.get_core()
if not isinstance(clipa, vs.VideoNode):
raise TypeError('xBox4: clip a is not a clip')
if not isinstance(clipb, vs.VideoNode):
raise TypeError('xBox4: clip b is not a clip')
hClip = clipa.height
wClip = clipa.width
aa1 = icore.std.CropRel(clipa,left=0*wClip//4,top=0*hClip//4,right=3*wClip//4,bottom=3*hClip//4)
aa2 = icore.std.CropRel(clipb,left=1*wClip//4,top=0*hClip//4,right=2*wClip//4,bottom=3*hClip//4)
aa3 = icore.std.CropRel(clipa,left=2*wClip//4,top=0*hClip//4,right=1*wClip//4,bottom=3*hClip//4)
aa4 = icore.std.CropRel(clipb,left=3*wClip//4,top=0*hClip//4,right=0*wClip//4,bottom=3*hClip//4)
aa1 = icore.text.Text(aa1, aSub, alignment=7) ; aa1 = icore.text.FrameNum(aa1, alignment=3)
aa2 = icore.text.Text(aa2, bSub, alignment=7) ; aa2 = icore.text.FrameNum(aa2, alignment=3)
aa3 = icore.text.Text(aa3, aSub, alignment=7) ; aa3 = icore.text.FrameNum(aa3, alignment=3)
aa4 = icore.text.Text(aa4, bSub, alignment=7) ; aa4 = icore.text.FrameNum(aa4, alignment=3)
bb1 = icore.std.CropRel(clipb,left=0*wClip//4,top=1*hClip//4,right=3*wClip//4,bottom=2*hClip//4)
bb2 = icore.std.CropRel(clipa,left=1*wClip//4,top=1*hClip//4,right=2*wClip//4,bottom=2*hClip//4)
bb3 = icore.std.CropRel(clipb,left=2*wClip//4,top=1*hClip//4,right=1*wClip//4,bottom=2*hClip//4)
bb4 = icore.std.CropRel(clipa,left=3*wClip//4,top=1*hClip//4,right=0*wClip//4,bottom=2*hClip//4)
bb1 = icore.text.Text(bb1, bSub, alignment=7) ; bb1 = icore.text.FrameNum(bb1, alignment=3)
bb2 = icore.text.Text(bb2, aSub, alignment=7) ; bb2 = icore.text.FrameNum(bb2, alignment=3)
bb3 = icore.text.Text(bb3, bSub, alignment=7) ; bb3 = icore.text.FrameNum(bb3, alignment=3)
bb4 = icore.text.Text(bb4, aSub, alignment=7) ; bb4 = icore.text.FrameNum(bb4, alignment=3)
cc1 = icore.std.CropRel(clipa,left=0*wClip//4,top=2*hClip//4,right=3*wClip//4,bottom=1*hClip//4)
cc2 = icore.std.CropRel(clipb,left=1*wClip//4,top=2*hClip//4,right=2*wClip//4,bottom=1*hClip//4)
cc3 = icore.std.CropRel(clipa,left=2*wClip//4,top=2*hClip//4,right=1*wClip//4,bottom=1*hClip//4)
cc4 = icore.std.CropRel(clipb,left=3*wClip//4,top=2*hClip//4,right=0*wClip//4,bottom=1*hClip//4)
cc1 = icore.text.Text(cc1, aSub, alignment=7) ; cc1 = icore.text.FrameNum(cc1, alignment=3)
cc2 = icore.text.Text(cc2, bSub, alignment=7) ; cc2 = icore.text.FrameNum(cc2, alignment=3)
cc3 = icore.text.Text(cc3, aSub, alignment=7) ; cc3 = icore.text.FrameNum(cc3, alignment=3)
cc4 = icore.text.Text(cc4, bSub, alignment=7) ; cc4 = icore.text.FrameNum(cc4, alignment=3)
dd1 = icore.std.CropRel(clipb,left=0*wClip//4,top=3*hClip//4,right=3*wClip//4,bottom=0*hClip//4)
dd2 = icore.std.CropRel(clipa,left=1*wClip//4,top=3*hClip//4,right=2*wClip//4,bottom=0*hClip//4)
dd3 = icore.std.CropRel(clipb,left=2*wClip//4,top=3*hClip//4,right=1*wClip//4,bottom=0*hClip//4)
dd4 = icore.std.CropRel(clipa,left=3*wClip//4,top=3*hClip//4,right=0*wClip//4,bottom=0*hClip//4)
dd1 = icore.text.Text(dd1, bSub, alignment=7) ; dd1 = icore.text.FrameNum(dd1, alignment=3)
dd2 = icore.text.Text(dd2, aSub, alignment=7) ; dd2 = icore.text.FrameNum(dd2, alignment=3)
dd3 = icore.text.Text(dd3, bSub, alignment=7) ; dd3 = icore.text.FrameNum(dd3, alignment=3)
dd4 = icore.text.Text(dd4, aSub, alignment=7) ; dd4 = icore.text.FrameNum(dd4, alignment=3)
rr = icore.std.StackVertical( [ icore.std.StackHorizontal([aa1, aa2, aa3, aa4]),
icore.std.StackHorizontal([bb1, bb2, bb3, bb4]),
icore.std.StackHorizontal([cc1, cc2, cc3, cc4]),
icore.std.StackHorizontal([dd1, dd2, dd3, dd4]) ])
return rr

Myrsloik
25th August 2016, 13:39
Hint: sub.Subtitle()

jackoneill
25th August 2016, 14:03
You can use sub.Subtitle (http://www.vapoursynth.com/doc/plugins/subtext.html).

Or this:

import vapoursynth as vs
c = vs.get_core()

def altText(src, msg):
# Print the message on a blank clip with the same format as the input clip.
text = c.std.BlankClip(src)
text = c.text.Text(text, msg)

# Construct a suitable alpha channel for blending.
# Enlarge the text a bit.
mask = c.std.Maximum(text)
# text.Text prints limited range white text (235) on limited range black background (16).
# Make them 255 and 0, so the black box doesn't show at all.
mask = c.std.Binarize(mask)
# Soften the edges of the text a bit.
mask = c.std.Inflate(mask)

# Blend the text into the input clip.
ret = c.std.MaskedMerge(src, text, mask, first_plane=True)

return ret

clip = c.ffms2.Source("video.mov")

clip = altText(clip, "The quick brown fox\njumps over the lazy dog.")

clip.set_output()

hydra3333
25th August 2016, 15:13
Thank you !
def altText(srcclip=None, msg='', alignment=7):
# by jackoneill 2016.08.25 http://forum.doom9.org/showthread.php?p=1778537#post1778537
# used by xBox2 etc to replace icore.text.Text
icore = vs.get_core()
# Print the msg text on a blank clip with the same format as the input src clip.
textclip = icore.std.BlankClip(srcclip)
textclip = icore.text.Text(textclip, msg, alignment=alignment)
# Construct a suitable alpha channel for blending.
# Enlarge the text a bit.
maskclip = icore.std.Maximum(textclip)
# text.Text prints in limited range white text (235) on limited range black background (16).
# Make them 255 and 0, so the black box doesn't show at all.
maskclip = icore.std.Binarize(mask)
# Soften the edges of the text a bit.
maskclip = icore.std.Inflate(maskclip)
# Blend the text into the input clip.
retclip = icore.std.MaskedMerge(srcclip, textclip, maskclip, first_plane=True)
return retclip