Log in

View Full Version : Animated image transition - more efficiently?


Reino
17th February 2011, 22:47
When it comes to available Avisynth filters I'm not that resourceful, so I was wondering if anyone can tell me if the following script can be done more efficiently, because rendering this script alone uses ± 90% of my cpu.

http://img707.imageshack.us/img707/33/rewp.th.png (http://img707.imageshack.us/img707/33/rewp.png/) http://img268.imageshack.us/img268/5224/rewmask.th.png (http://img268.imageshack.us/img268/5224/rewmask.png/)

BlankClip(200,640,480,"RGB32",25,color=$FFFFFF)

rew = ImageReader("D:\test\rew.png", fps=25)
rewMask = ImageReader("D:\test\rew_mask.png", fps=25)

a=rewMask.Loop(28).Animate(0,28,"Levels", 0,1.0,255,0,0, 0,1.0,255,0,224)
b=rewMask.Loop(20).Animate(0,20,"Levels", 0,1.0,255,0,64, 0,1.0,255,0,224)
c=rewMask.Loop(20).Animate(0,20,"Levels", 0,1.0,255,0,224, 0,1.0,255,0,64)
d=rewMask.Loop(28).Animate(0,28,"Levels", 0,1.0,255,0,224, 0,1.0,255,0,0)

JDL_ReplaceRange(last,Overlay(last, rew,mode="multiply",mask=a),12,39)
JDL_ReplaceRange(last,Overlay(last.Trim(40,0), rew,mode="multiply",mask=c),40,59)
JDL_ReplaceRange(last,Overlay(last.Trim(60,0), rew,mode="multiply",mask=b),60,79)
JDL_ReplaceRange(last,Overlay(last.Trim(80,0), rew,mode="multiply",mask=c),80,99)
JDL_ReplaceRange(last,Overlay(last.Trim(100,0), rew,mode="multiply",mask=b),100,119)
JDL_ReplaceRange(last,Overlay(last.Trim(120,0), rew,mode="multiply",mask=c),120,139)
JDL_ReplaceRange(last,Overlay(last.Trim(140,0), rew,mode="multiply",mask=b),140,159)
JDL_ReplaceRange(last,Overlay(last.Trim(160,0), rew,mode="multiply",mask=d),160,187)

Gavino
18th February 2011, 01:48
You can replace the multiple overlays with a single one by making the mask cover the whole length of the clip.
BlankClip(200,640,480,"RGB32",25,color=$FFFFFF)

rew = ImageReader("D:\test\rew.png", fps=25)
rewMask = ImageReader("D:\test\rew_mask.png", fps=25, end=0)

a=rewMask.Loop(40).Animate(12,39,"Levels", 0,1.0,255,0,0, 0,1.0,255,0,224)
b=rewMask.Loop(20).Animate(0,19,"Levels", 0,1.0,255,0,64, 0,1.0,255,0,224)
c=rewMask.Loop(20).Animate(0,19,"Levels", 0,1.0,255,0,224, 0,1.0,255,0,64)
d=rewMask.Loop(40).Animate(0,27,"Levels", 0,1.0,255,0,224, 0,1.0,255,0,0)
m = a+c+b+c+b+c+b+d

Overlay(last,rew,mode="multiply",mask=m)

Overlay() is quite slow and memory hungry, so you might like to try using Layer() instead when using RGB.

Reino
18th February 2011, 21:10
I deliberately chose Loop(20).Animate(0,20) so I wouldn't end up with 2 consecutive frames with the same output_high value (either 64, or 224).
I immediately changed to Layer() and your suggestion seemed to work just fine (± 30% less cpu-utilization), untill I ran into the following problem:
BlankClip(1100,640,480,"RGB32",25,color=$FFFFFF)

rewMask = ImageReader("D:\temp\rew.png", end=0, fps=25).Invert().ConvertToRGB32()

a=rewMask.Loop(940).Animate(912,940,"Levels", 0,1.0,255,0,0, 0,1.0,255,0,224)
b=rewMask.Loop(20).Animate(0,20,"Levels", 0,1.0,255,0,64, 0,1.0,255,0,224)
c=rewMask.Loop(20).Animate(0,20,"Levels", 0,1.0,255,0,224, 0,1.0,255,0,64)
d=rewMask.Loop(29).Animate(0,28,"Levels", 0,1.0,255,0,224, 0,1.0,255,0,0)
m = a+c+b+c+b+c+b+d

rew = ImageReader("D:\temp\rew.png", fps=25).ConvertToRGB32().Mask(m)

Layer(last, rew)The moment 1000 frames have passed the animation stops and you end up with frame #1000 looping forever.
Overlay(last,rew,mode="multiply",mask=m) does work flawlessly however (without assigning .Mask(m) to 'rew' of course).
Somehow 1000 frames is a limit for "something"...
Do you have any idea?

Gavino
18th February 2011, 21:36
I deliberately chose Loop(20).Animate(0,20) so I wouldn't end up with 2 consecutive frames with the same output_high value (either 64, or 224).
OK - I assumed this was an oversight on your part, but your explanation makes perfect sense.
Somehow 1000 frames is a limit for "something"...
It's the default length returned by ImageReader(*), so 'rew' has only 1000 frames. The last frame (and its mask) are then repeated to fill out the 1100 frames of the background blank clip.

It works OK with Overlay because there 'rew' and 'm' are kept as separate clips of length 1000 and 1089 - the last frame of 'rew' is still repeated but the mask carries on fading to the 1089th frame (and is then repeated to the 1100th).

You need to make 'rew' at least the same length as the mask:
rew = ImageReader("D:\temp\rew.png", fps=25, end=1088).ConvertToRGB32().Mask(m)

(*)Edit - Actually, it's 1001 frames, not 1000, but the explanation is the same.

Reino
18th February 2011, 22:35
Of course! I feel so silly now...
Thanks a lot, Gavino!