View Full Version : Create an opaque box
TCmullet
29th August 2018, 16:32
Can anyone suggest an easy way to create an opaque box of a color anywhere on the screen? Ideally anywhere, but in particular, I need to place a box in one corner of the screen. I'll be overlaying text on top of it.
Isn't there somewhere where users have created functions and shared them with the world? (A repository for Avisynth scripts.) I can't find such.
johnmeyer
29th August 2018, 17:04
Some code I had lying around that should get you started:
bord1=64
baseclip=AVISource("E:\Documents\Dnload\UNPACK\bandstand.avi")
blank_white= Blankclip(baseclip, width=bord1,height=bord1, color=$FFFFFF)
final= overlay(baseclip,blank_white, x=40,y=300)
return final
TCmullet
29th August 2018, 18:06
Thanks, John. Could you please help me a bit more? I've incorporated the logic into my own small function, a function that shows a sports scoreboard (rudimentary). I have working the subtitle, but wanted to add a black background. Am now merely trying to get a black box to show, but it doesn't. Here's my whole code:
function Scores(clip myclip, int "score1", int "score2", \
int "fstart", int "fend", \
string "team1", string "team2", string "gamelabel", \
int "frow", int "fcol")
{
blank_black=Blankclip(myclip, width=100,height=100, color=$000000)
overlay(myclip,blank_black,x=0,y=0,mode="darken")
scoreboard = gamelabel + ": " + team1 + " " + string(score1) + ", " + \
team2 + " " + string(score2)
Subtitle(myclip, scoreboard, x=frow, y=fcol, \
font="Arial", size=30, lsp=0, spc=0, font_width=0, \
first_frame=fstart, last_frame=fend)
}
Any idea of why my 100 x 100 black box does not appear at all? The Scores function has been working and still does, but I get no black box anywhere. (Initially I'm simply trying to get the box on the screen, then lay the text over whatever is there. I'll worry about computing the dimensions etc. after I get the box visible.)
TCmullet
29th August 2018, 18:45
The above code had serious flaws. I've improved by creating this, and still no black box appears:
function paintbox(clip clp, int "fstart", int "fend")
{
a=trim(clp,0,fstart-1)
b=trim(clp,fstart,fend)
c=trim(clp,fend+1,0)
blank_black=Blankclip(b, width=100,height=100, color=$000000)
overlay(b,blank_black,x=0,y=0,mode="darken")
b=last
return a++b++c
}
function Scores(clip myclip, int "score1", int "score2", \
int "fstart", int "fend", \
string "team1", string "team2", string "gamelabel", \
int "frow", int "fcol")
{
scoreboard = gamelabel + ": " + team1 + " " + string(score1) + ", " + \
team2 + " " + string(score2)
paintbox(myclip, fstart, fend)
Subtitle(myclip, scoreboard, x=frow, y=fcol, \
font="Arial", size=30, lsp=0, spc=0, font_width=0, \
first_frame=fstart, last_frame=fend)
}
My function calls further down the script look like:
Scores(3,3,2992,3681,"Texas","Oregon","Set 2",0,0)
Scores(4,3,3681,4678,"Texas","Oregon","Set 2",0,0)
Scores(4,4,4678,5441,"Texas","Oregon","Set 2",0,0)
I'm expecting that whenever my subtitle appears, which is in upper left corner, it will now have a black 100x100 box under it. The box blots out the video image, then the text blots out part of both. But I see no evidence of the box.
wonkey_monkey
29th August 2018, 19:17
paintbox(myclip, fstart, fend)
Subtitle(myclip, scoreboard, x=frow, y=fcol, \
font="Arial", size=30, lsp=0, spc=0, font_width=0, \
first_frame=fstart, last_frame=fend)
You're not assigning the result of paintbox to anything. It ends up in implicit last, but you call subtitle with myclip, which is the original clip.
Do either:
boxed_clip=paintbox(myclip, fstart, fend)
subtitle(boxed_clip, scoreboard...
or
paintbox(myclip, fstart, fend)
subtitle(scoreboard...
Removing the clip from the call to subtitle makes it use the implicit last.
TCmullet
29th August 2018, 19:37
I did the latter (removing clip from call to subtitle), and it worked. But when I remove the clip from the call to paintbox, I get an error. Why does paintbox need the clip but subtitle doesn't?
wonkey_monkey
29th August 2018, 20:09
At the point in the script where paintbox is called, there isn't any implicit "last" clip (which is the current "default" clip, also accessible with the keyword "last"). You could set one and then call paintbox like this:
myclip
paintbox(fstart, fend)
Avisynth knows that paintbox wants a clip as its first parameter, so if you don't give it one, it will use last (if there is a clip there, that is).
TCmullet
30th August 2018, 05:29
Thanks to both you guys! David, ah yes, I OFTEN get bit by "script does not end with clip".
I'll try to post my finished and refined "sports scoreboard" here when I finish it.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.