View Full Version : Adaptive Text Size with Animation
zerowalker
16th July 2014, 22:47
Okay the Topic makes it sound more fancy than it is.
Basically, what i want to do is make a function that will make a text, which will most likely be the same all the time. And have that text adapt to the clip size, (Not resizing the resolution, but scaling so to speak).
And said text will have an Animation, which is fairly simple.
It's supposed to be small and Fadein within a 2 sec period and Zoom into full scale at the same time.
(How you get what i mean there).
Any ideas on how to do this?
EDIT:
The subtitle filter inbuilt is quite limited.
Is there a way to use subtitles, and make those subtitles within the script (or temp file)?
(Vobsub for example).
This would remove that limitation.
raffriff42
17th July 2014, 00:08
It's supposed to be small and 100% transparent at start, then at in a 2 sec period it will Zoom into full scale and at the same time become visible.return Animate( 0, Round(2.0*FrameRate), "sub_anim_1",
\ "Hello World", 1.0/32, 0.0,
\ "Hello World", 1.5, 1.0)
## 2.0*FrameRate => 2 sec
## 1.0/32 => start text height is 1/32x picture height
## 1.5 => end text height is 1.5x picture height (really really big)
## 0.0 => starting opacity
## 1.0 => ending opacity
#######################################
function sub_anim_1(clip C, string msg, float size, float opacity)
{
return C.Subtitle(msg, align=2,
\ text_color=to_rgb32i(255, 255, 0, Round(opacity*256.0)), /* yellow */
\ halo_color=to_rgb32i( 0, 0, 0, Round(opacity*256.0)), /* black */
\ size=Float(C.Height)*size)
}
#######################################
## given R, G, B, A, return an Avisynth color
## (note, a=255 means fully opaque here)
##
function to_rgb32i(int r, int g, int b, int a) {
r = Min(Max(0, r), 255)
g = Min(Max(0, g), 255)
b = Min(Max(0, b), 255)
a = 255 - Min(Max(0, a), 255)
return (a*$1000000) + (r*$10000) + (g*$100) + b
}
...Needs work (to keep text centered on zoom), left as an exercise.
zerowalker
17th July 2014, 00:16
Splendid, will play around with this, trying to get it to work within my current function, but the "return animate" seem to mess things up a bit.
The centered text thing is probably not That hard:)
raffriff42
17th July 2014, 00:44
"return Animate" was a kind of shorthand, not for your final script.
Also, in your script, you should use a string variable for your subtitle text, since strings can't be changed inside the Animate function. Something like this... XXXSource(...)
...
msg="Hello World"
Animate( 0, Round(2.0*FrameRate), "sub_anim_1",
\ msg, 1.0/32, 0.0,
\ msg, 1.5, 1.0)
...
return Last
zerowalker
17th July 2014, 00:46
Yeah kinda got it to work, not to good at this Function stuff.
A bit stuck at changing Text color, as you got your "rounding colors for transparency" function, so i don't know how to set what colors i want.
raffriff42
17th July 2014, 01:03
One way to get the numbers is to open any Paint editor, pick a color, and read the R, G, B values.
Example: yellow = 255, 255, 0; green = 0, 255, 0; black = 0, 0, 0.
RGB is on a 0-255 scale, but transparency is on a 0-1 scale. Because I couldn't make up my mind which is "better."
zerowalker
17th July 2014, 01:07
Ah, okay that explains it, i was stuck with the hex codes.
Now the only limitation is the actual filter itself. Seems like i am stuck with Bold, and can't decide the size of the halo etc.
The animation works perfect though, thanks:)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.