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 > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 25th August 2016, 13:40   #1  |  Link
hydra3333
Registered User
 
Join Date: Oct 2009
Location: crow-land
Posts: 532
alternative to, or better use of, core.text.Text ?

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
Code:
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
Attached Files
File Type: txt zzz.txt (18.9 KB, 2 views)
hydra3333 is offline   Reply With Quote
Old 25th August 2016, 14:39   #2  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Ikea Chair
Posts: 2,031
Hint: sub.Subtitle()
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is online now   Reply With Quote
Old 25th August 2016, 15:03   #3  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 725
You can use sub.Subtitle.

Or this:
Code:
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()
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 25th August 2016, 16:13   #4  |  Link
hydra3333
Registered User
 
Join Date: Oct 2009
Location: crow-land
Posts: 532
Thank you !
Code:
def altText(srcclip=None, msg='', alignment=7): 
    # by jackoneill 2016.08.25 http://forum.doom9.org/showthread.ph...37#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
hydra3333 is offline   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 10:04.


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