Log in

View Full Version : Animated overlay with transparency


Alex-Kid
7th July 2008, 07:36
Hi everybody.

I've always visited this forum as a knowledge source in every video job i've done. Now it's time to make a question because I still haven't found what I'm looking for (yes, i like U2 ;)).

I started a week ago editing some baby fútbol (smallest field with five players) material I've filmed. Every goal scored must have an animated overlay (similar to euro 2008) showing name of the player and time of scoring everytime a goal has occured. The overlay is a sequence of PNG images with transparency enabled (with fade in and out)and the text is shown through subtitles (fading out together with overlay). The script I'm using is as follows:

testcard = avisource("petazetas_vs_mamaestapresa.avi").ConvertToRGB32()
tcard01 = testcard.trim(8587,8757)
subs = ImmaRead("gol%02d.png", start=1, end=45)
logo = Overlay(tcard01, subs, 165, 280, ShowAlpha(subs), 255, "blend")
dissolve(trim(testcard, 0, 8586),logo,trim(testcard,8758,24546),5)
subtitle("JUAN CASTILLO", 230, 287, 8622, 8752, "Arial Narrow Cursiva", 16, $00ffffff, $ff000000, 7)
subtitle("MIN. 51", 248, 307, 8622, 8752, "Arial Narrow Cursiva", 14, $00ffffff, $ff000000, 7)
converttoyv12()

At this time, there's only one issue with dissolve ranges, easy to solve. But there are another issues I think they can be enhanced:

The trim/dissolve filters must be used for showing the overlay from the beginning (if not, it starts from frame 0 of testcard, and the animation gets lost).
Subtitles have not fading out. Anybody, please?
This script shows only one goal. The matches have often 5-8 goals average, so the overlay must be showed many times. Can memory issues occur (overlay called several times)?
Finally, Would be better to make a function for this?

Thanks in advance. Saludos

By ALEX-KID

IanB
7th July 2008, 09:00
testcard = avisource("petazetas_vs_mamaestapresa.avi")

subs = ImmaRead("gol%02d.png", start=1, end=45)

Goal(testcard, subs, 8587, "JUAN CASTILLO", "MIN. 51")
Goal(testcard, subs, 17007, "JOSE FANGIO", "MIN. 101")
...

Function Goal(clip src, clip sub, int start, string text1, string text2) {

ol = 5 # Dissolve duration
fc = FrameCount(sub) # Animation duration
tl = 130 # Text duration

v1 = src.trim(0, -start-ol)
tc = src.trim(start, -fc-ol)
tx = src.trim(start+fc, -tl)
v2 = src.trim(start+fc+tl-ol, 0)

tc = tc.Overlay(sub, 165, 280, ShowAlpha(sub), 1.0, "blend")

tx = tx.subtitle(text1, 230, 287, 0, tl, "Arial Narrow Cursiva", 16, $00ffffff, $ff000000, 7)
tx = tx.subtitle(text2, 248, 307, 0, tl, "Arial Narrow Cursiva", 14, $00ffffff, $ff000000, 7)

return dissolve(v1, tc, tx, v2, ol)
}From your frame numbers I have assumed you want the text to follow the animation, if you want them at the same time it is a simple matter to adjust the Goal function.

Alex-Kid
9th July 2008, 21:06
After a lot of thinking about what the script does, I finally can write reply :)...

I had some issues with sub/subs variable, but were easy to solve. The video was split in four parts, where the second one and third one contain the overlay and the subtitles repectively. Then the video is rejoined through Dissolve filter, but when showing subtitles, the overlay is gone and it's needed as a background for the subtitles. So my attempt is to add another image, make the overlay and add the text. Like this:
testcard = avisource("petazetas_vs_mamaestapresa.avi")

sub = ImmaRead("gol%02d.png", start=1, end=45)
sub0 = ImmaRead("gol45.png")

Goal(testcard, sub, 8587, "JUAN CASTILLO", "MIN. 51")
Goal(testcard, sub, 17007, "JOSE FANGIO", "MIN. 101")
...

Function Goal(clip src, clip sub, int start, string text1, string text2) {

ol = 5 # Dissolve duration
fc = FrameCount(sub) # Animation duration
tl = 130 # Text duration

v1 = src.trim(0, -start-ol)
tc = src.trim(start, -fc-ol)
tx = src.trim(start+fc, -tl)
v2 = src.trim(start+fc+tl-ol, 0)

tc = tc.Overlay(sub, 165, 280, ShowAlpha(sub), 1.0, "blend")

tx = tx.Overlay(sub0, 165, 280, ShowAlpha(sub), 1.0, "blend")
tx = tx.subtitle(text1, 230, 287, 0, tl, "Arial Narrow Cursiva", 16, $00ffffff, $ff000000, 7)
tx = tx.subtitle(text2, 248, 307, 0, tl, "Arial Narrow Cursiva", 14, $00ffffff, $ff000000, 7)

return dissolve(v1, tc, tx, v2, ol)
}

It doesn't seem too elegant (to me). Any improvements are welcome.
But this script only works for the last Goal function specified, I don't know how to make it work for each goal scored.

Help is needed again.

Saludos

By ALEX-KID

Gavino
9th July 2008, 23:13
Ah, so IanB's earlier assumption was mistaken.

From your frame numbers I have assumed you want the text to follow the animation, if you want them at the same time it is a simple matter to adjust the Goal function.

I think the adjustment you need is something like this:

Function Goal(clip src, clip sub, int start, string text1, string text2) {

ol = 5 # Dissolve duration
tl = 130 # Text duration
ts = 30 # Text start relative to animation
fc = tl+ts # Total animation duration

v1 = src.trim(0, -start-ol)
tc = src.trim(start, -fc-ol)
v2 = src.trim(start+fc, 0)

tc = tc.Overlay(sub, 165, 280, ShowAlpha(sub), 1.0, "blend")
tc = tc.subtitle(text1, 230, 287, ts, fc-1, "Arial Narrow Cursiva", 16, $00ffffff, $ff000000, 7)
tc = tc.subtitle(text2, 248, 307, ts, fc-1, "Arial Narrow Cursiva", 14, $00ffffff, $ff000000, 7)

return dissolve(v1, tc, v2, ol)
}

Here I am assuming that the last (45th) frame of your .png sequence is simply repeated as a static background behind the text, which is what your original example suggests.

IanB
9th July 2008, 23:49
Right I misunderstood what you wanted. You want the last frame of the .PNG's repeated thru the text. And oops forgot to remove the "testcard="
Function Goal(clip src, clip sub, int start, string text1, string text2) {

ol = 5 # Dissolve duration
fc = FrameCount(sub) # Animation duration
tl = 130 # Text duration

v1 = src.trim(0, -start-ol)
tc = src.trim(start, -fc-tl-ol)
v2 = src.trim(start+fc+tl, 0)

tc = tc.Overlay(sub, 165, 280, ShowAlpha(sub), 1.0, "blend")

t1 = tc.trim(0, -fc-ol)
t2 = tc.trim(fc, 0)

t2 = t2.subtitle(text1, 230, 287, 0, tl, "Arial Narrow Cursiva", 16, $00ffffff, $ff000000, 7)
t2 = t2.subtitle(text2, 248, 307, 0, tl, "Arial Narrow Cursiva", 14, $00ffffff, $ff000000, 7)

return dissolve(v1, t1, t2, v2, ol)
}

subs = ImmaRead("gol%02d.png", start=1, end=45)

avisource("petazetas_vs_mamaestapresa.avi")

Goal(subs, 8587, "JUAN CASTILLO", "MIN. 51")
Goal(subs, 17007, "JOSE FANGIO", "MIN. 101")
...

Alex-Kid
10th July 2008, 00:17
NIIICE!!

Thank you IanB. And thank you too Gavino for trying. I knew avisynth could do it, so long life avisynth! :)

Saludos

By ALEX-KID